Parse output of perf script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: python this.py <(perf script -i perf.data -F comm,tid,time,ip,sym,cpu,event) | |
import fileinput | |
proc_sample_total = 0 | |
cpu_inc = {} | |
cpu_ext = {} | |
comm = '<your-process-name>'[:15].lower() | |
interested = True | |
expect_header = True | |
top_of_frame = False | |
for input_line in fileinput.input(): | |
line = input_line.strip() | |
if len(line) == 0: | |
interested = True | |
expect_header = True | |
continue | |
if expect_header: | |
interested = line.lower().startswith(comm) | |
if interested: | |
proc_sample_total += 1 | |
expect_header = False | |
top_of_frame = True | |
continue | |
if interested: | |
segments = line.split() | |
if segments[1] == '[unknown]': | |
top_of_frame = False | |
continue | |
signature = '_'.join(segments[1:]) | |
cpu_inc.setdefault(signature, 0) | |
cpu_inc[signature] += 1 | |
if top_of_frame: | |
cpu_ext.setdefault(signature, 0) | |
cpu_ext[signature] += 1 | |
top_of_frame = False | |
def stats(x): | |
items = sorted(x.items(), key=lambda x: x[1], reverse=True) | |
for item in items: | |
print(' - {}: {:.3f}'.format(item[0], 100.0 * item[1] / proc_sample_total)) | |
print('') | |
print('Inclusion %:') | |
stats(cpu_inc) | |
print('Exclusion %:') | |
stats(cpu_ext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment