stat-cpi.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. data = {}
  3. times = []
  4. threads = []
  5. cpus = []
  6. def get_key(time, event, cpu, thread):
  7. return "%d-%s-%d-%d" % (time, event, cpu, thread)
  8. def store_key(time, cpu, thread):
  9. if (time not in times):
  10. times.append(time)
  11. if (cpu not in cpus):
  12. cpus.append(cpu)
  13. if (thread not in threads):
  14. threads.append(thread)
  15. def store(time, event, cpu, thread, val, ena, run):
  16. #print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \
  17. # (event, cpu, thread, time, val, ena, run)
  18. store_key(time, cpu, thread)
  19. key = get_key(time, event, cpu, thread)
  20. data[key] = [ val, ena, run]
  21. def get(time, event, cpu, thread):
  22. key = get_key(time, event, cpu, thread)
  23. return data[key][0]
  24. def stat__cycles_k(cpu, thread, time, val, ena, run):
  25. store(time, "cycles", cpu, thread, val, ena, run);
  26. def stat__instructions_k(cpu, thread, time, val, ena, run):
  27. store(time, "instructions", cpu, thread, val, ena, run);
  28. def stat__cycles_u(cpu, thread, time, val, ena, run):
  29. store(time, "cycles", cpu, thread, val, ena, run);
  30. def stat__instructions_u(cpu, thread, time, val, ena, run):
  31. store(time, "instructions", cpu, thread, val, ena, run);
  32. def stat__cycles(cpu, thread, time, val, ena, run):
  33. store(time, "cycles", cpu, thread, val, ena, run);
  34. def stat__instructions(cpu, thread, time, val, ena, run):
  35. store(time, "instructions", cpu, thread, val, ena, run);
  36. def stat__interval(time):
  37. for cpu in cpus:
  38. for thread in threads:
  39. cyc = get(time, "cycles", cpu, thread)
  40. ins = get(time, "instructions", cpu, thread)
  41. cpi = 0
  42. if ins != 0:
  43. cpi = cyc/float(ins)
  44. print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins)
  45. def trace_end():
  46. pass
  47. # XXX trace_end callback could be used as an alternative place
  48. # to compute same values as in the script above:
  49. #
  50. # for time in times:
  51. # for cpu in cpus:
  52. # for thread in threads:
  53. # cyc = get(time, "cycles", cpu, thread)
  54. # ins = get(time, "instructions", cpu, thread)
  55. #
  56. # if ins != 0:
  57. # cpi = cyc/float(ins)
  58. #
  59. # print "time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi)