Skip to content

Instantly share code, notes, and snippets.

@markbenvenuto
Created February 14, 2019 22:29
Show Gist options
  • Save markbenvenuto/db88da972fbbd517ce729fe9fedc39ea to your computer and use it in GitHub Desktop.
Save markbenvenuto/db88da972fbbd517ce729fe9fedc39ea to your computer and use it in GitHub Desktop.
task log to chromium trace
# task_to_trace.py
import sys
import re
from dateutil.parser import *
with open(sys.argv[1]) as fh:
lines = fh.readlines()
begin = {}
start = None
print "["
for line in lines:
if line.find("[executor") == -1:
continue
curr = line.strip()
if curr.find("Running") >= 0:
m = re.search("\[.*:.*:job(.*)\] (.*) Running (.*)\.\.\.", curr)
if m:
job = m.group(1)
time = m.group(2)
test = m.group(3)
# print curr
ts = parse(time)
if start:
delta = (ts - start).total_seconds() * 1000 * 1000
else:
delta = 0
start = ts
print '{"name": "%s", "cat": "foo", "ph": "B", "ts": %s, "pid": 1, "tid": %s },' % \
(test, delta, job)
elif curr.find(" ran in ") >= 0:
m = re.search("\[.*\] \[.*:.*:job(.*)\] (.*) (.*) ran in.*", curr)
if m:
job = m.group(1)
time = m.group(2)
test = m.group(3)
# print curr
ts = parse(time)
delta = ts - start
print '{ "ph": "E", "ts": %s, "pid": 1, "tid": %s },' % \
(delta.total_seconds() * 1000 * 1000, job)
print '{"name": "OutOfMemory", "ph": "i", "ts": %s, "pid": 2343, "tid": 2347, "s": "g"}' % (delta.total_seconds() * 1000 * 1000 + 1)
print "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment