Skip to content

Python event tracing using the Trace Event Format supported by Chromium browsers

License

Notifications You must be signed in to change notification settings

jamie-everlaw/trace_events

 
 

Repository files navigation

Trace Events

Python event tracing using the Trace Event Format which is supported by Chromium browsers and other tools

Installing

Install and update using pip

Usage

Add tracing to sections of your code and execute to generate a json trace file

import time
from trace_events import Profiler, profile, timeit

@profile
def foo():
    # ... do some work

@profile(category='suspected-slow')
def bar():
    time.sleep(1)

def baz(value):
    with timeit('baz::foo'):
        foo()

    with timeit('baz::bar', value=value):
        bar()

if __name__ == '__main__':
    baz(10)

    Profiler.global_profiler().save_trace('trace.json')

Traces are saved atexit to a default trace.json file, or can be configured with a call to init_trace

import trace_events

trace_events.init_trace(
    trace_file_dir='./my-traces',
    trace_file_name='my-trace.json',
    # save_at_exit = True
    # overwrite_trace_files=False,
    # logger=logging.getLogger("trace_events")
)

Open up a Chromium browser to chrome://tracing and load the file to view the trace

Example image

More examples in the examples folder

About

Python event tracing using the Trace Event Format supported by Chromium browsers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%