Skip to content

Instantly share code, notes, and snippets.

@takaswie
Last active December 25, 2020 00:40
Show Gist options
  • Save takaswie/af2b93b58a1154903d6fbe1a6bee3c69 to your computer and use it in GitHub Desktop.
Save takaswie/af2b93b58a1154903d6fbe1a6bee3c69 to your computer and use it in GitHub Desktop.
parser for 'perf.data.script.211220202054.txt'
#!/usr/bin/env python3
from sys import argv
from re import compile, search
records = []
with open(argv[1], 'r') as f:
record = []
for line in f.readlines():
l = line.strip()
if len(l) == 0:
records.append(record)
record = []
else:
record.append(l)
# Timestamp format: 120.239372
expr = compile('\d+\.\d{6}')
prev = -1
for record in records:
for bt in record[1:]:
if bt.find('snd_pcm_period_elapsed') > 0:
matches = search(expr, record[0])
tstamp = float(matches.group(0))
if prev > 0:
gap = tstamp - prev
if gap < 0.02 or gap > 0.03:
res = 'unexpected'
else:
res = 'expected'
print('{:0.4f} {:0.8f} {}'.format(tstamp, gap, res))
prev = tstamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment