Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HawkTracer converter written in python
import json
import HawkTracer
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source', help='Description of the source; either file name or IP address', required=True)
args = parser.parse_args()
client = HawkTracer.Client()
client.start(args.source)
was_eos = False
data = []
def get_label(event):
if 'name' in event:
return event['name']
if 'label' in event:
return event['label']
return None
while True:
event = client.poll_event()
if event:
label, event = event
label = get_label(event)
if not label:
continue
duration = event['duration'] if 'duration' in event else 0
thread_id = event['thread_id'] if 'thread_id' in event else 99
data.append({"name": label, "ph": "X", "ts": event['timestamp'], "dur": duration, "pid": 0, "tid": thread_id})
else:
if was_eos:
break
was_eos = client.eos()
time.sleep(0.1)
continue
print(json.dumps({"traceEvents": data}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.