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