Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 
0003 from __future__ import print_function
0004 
0005 data    = {}
0006 times   = []
0007 threads = []
0008 cpus    = []
0009 
0010 def get_key(time, event, cpu, thread):
0011     return "%d-%s-%d-%d" % (time, event, cpu, thread)
0012 
0013 def store_key(time, cpu, thread):
0014     if (time not in times):
0015         times.append(time)
0016 
0017     if (cpu not in cpus):
0018         cpus.append(cpu)
0019 
0020     if (thread not in threads):
0021         threads.append(thread)
0022 
0023 def store(time, event, cpu, thread, val, ena, run):
0024     #print("event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" %
0025     #      (event, cpu, thread, time, val, ena, run))
0026 
0027     store_key(time, cpu, thread)
0028     key = get_key(time, event, cpu, thread)
0029     data[key] = [ val, ena, run]
0030 
0031 def get(time, event, cpu, thread):
0032     key = get_key(time, event, cpu, thread)
0033     return data[key][0]
0034 
0035 def stat__cycles_k(cpu, thread, time, val, ena, run):
0036     store(time, "cycles", cpu, thread, val, ena, run);
0037 
0038 def stat__instructions_k(cpu, thread, time, val, ena, run):
0039     store(time, "instructions", cpu, thread, val, ena, run);
0040 
0041 def stat__cycles_u(cpu, thread, time, val, ena, run):
0042     store(time, "cycles", cpu, thread, val, ena, run);
0043 
0044 def stat__instructions_u(cpu, thread, time, val, ena, run):
0045     store(time, "instructions", cpu, thread, val, ena, run);
0046 
0047 def stat__cycles(cpu, thread, time, val, ena, run):
0048     store(time, "cycles", cpu, thread, val, ena, run);
0049 
0050 def stat__instructions(cpu, thread, time, val, ena, run):
0051     store(time, "instructions", cpu, thread, val, ena, run);
0052 
0053 def stat__interval(time):
0054     for cpu in cpus:
0055         for thread in threads:
0056             cyc = get(time, "cycles", cpu, thread)
0057             ins = get(time, "instructions", cpu, thread)
0058             cpi = 0
0059 
0060             if ins != 0:
0061                 cpi = cyc/float(ins)
0062 
0063             print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins))
0064 
0065 def trace_end():
0066     pass
0067 # XXX trace_end callback could be used as an alternative place
0068 #     to compute same values as in the script above:
0069 #
0070 #    for time in times:
0071 #        for cpu in cpus:
0072 #            for thread in threads:
0073 #                cyc = get(time, "cycles", cpu, thread)
0074 #                ins = get(time, "instructions", cpu, thread)
0075 #
0076 #                if ins != 0:
0077 #                    cpi = cyc/float(ins)
0078 #
0079 #                print("time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi))