^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) from __future__ import print_function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) data = {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) times = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) threads = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) cpus = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) def get_key(time, event, cpu, thread):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) return "%d-%s-%d-%d" % (time, event, cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) def store_key(time, cpu, thread):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) if (time not in times):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) times.append(time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) if (cpu not in cpus):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) cpus.append(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (thread not in threads):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) threads.append(thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) def store(time, event, cpu, thread, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #print("event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # (event, cpu, thread, time, val, ena, run))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) store_key(time, cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) key = get_key(time, event, cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) data[key] = [ val, ena, run]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) def get(time, event, cpu, thread):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) key = get_key(time, event, cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return data[key][0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) def stat__cycles_k(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) store(time, "cycles", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) def stat__instructions_k(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) store(time, "instructions", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) def stat__cycles_u(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) store(time, "cycles", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) def stat__instructions_u(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) store(time, "instructions", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) def stat__cycles(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) store(time, "cycles", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) def stat__instructions(cpu, thread, time, val, ena, run):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) store(time, "instructions", cpu, thread, val, ena, run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) def stat__interval(time):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) for cpu in cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) for thread in threads:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) cyc = get(time, "cycles", cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ins = get(time, "instructions", cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) cpi = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if ins != 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) cpi = cyc/float(ins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) def trace_end():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) # XXX trace_end callback could be used as an alternative place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) # to compute same values as in the script above:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) # for time in times:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) # for cpu in cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) # for thread in threads:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) # cyc = get(time, "cycles", cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) # ins = get(time, "instructions", cpu, thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) # if ins != 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) # cpi = cyc/float(ins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) # print("time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi))