Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trace_events-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file trace_events-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trace_events-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for trace_events-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c31a5a6579745f5ee57c7167de9051ffa8fd1b7d90edf215c0c9f6664cb043b
MD5 8e8f275f4398d0d271e90b769af51064
BLAKE2b-256 e136283716214b74b4a6461b2570a741be4d87851c3631b7cd4b05285c2975aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page