import random


def _CreateQueryStdout(results):
  """Returns a "ptt dump" stdout for the given dict of results.

  See ibmperf.py for a full listing of sample output.

  Args:
    results: A dict of results as returned by
        ibmperf.HardwarePerformanceCounters.Query.
  """
  stdout = "***** ptt v2.0.8 for x86 ***** pid=1944/0x798 *****\n"
  stdout += "\n"
  pids = results[results.keys()[0]].keys()
  for pid in pids:
    stdout += "  PID  %d is foo\n" % pid
  stdout += "\n"
  stdout += "PTT Facility Per-Thread Information\n"
  stdout += "-----------------------------------\n"
  stdout += "\n"

  stdout += " PID TID Disp Intr"
  for metric in results:
    stdout += " %s" % metric
  stdout += "\n"

  stdout += " --- --- ---- ----"
  for metric in results:
    stdout += " %s" % ("-" * len(metric))
  stdout += "\n"

  for pid in pids:
    tid = random.randint(100, 1000)
    disp = random.randint(1, 10000)
    intr = random.randint(1, 10000)

    metric_values =  ""
    for metric in results:
      metric_values += " %d" % results[metric][pid]

    stdout += " %d %d %d %d%s\n" % (pid, tid, disp, intr, metric_values)

    stdout += "                   "
    stdout += "-".join("%s" % ("-" * len(metric)) for metric in results)
    stdout += "\n"
    stdout += "                   "
    stdout += metric_values
    stdout += "\n\n"

  stdout += "Execution ended: 1 iterations.\n"
  return stdout