Skip to main content

A lightweight trace analysis framework.

Project description

Trazer

Test Doctest Coverage PyPI version Documentation Status

A lightweight trace analysis framework (trace analyzer) for execution and network traces, focusing on event chain analysis.

Getting Started

Prerequisites

  • Python >= 3.8

Installation

pip install trazer

Usage

Create Trace and Add Events

>>> from trazer import Trace, TraceEventDurationBegin, TraceEventDurationEnd
>>> trace = Trace()
>>> trace.add_event(TraceEventDurationBegin('my_event', 1.0, pid=0, tid=0))  # my_event begins at 1.0 s
>>> trace.add_event(TraceEventDurationEnd('my_event', 2.0, pid=0, tid=0))  # my_event ends at 2.0 s

Export Trace to Chrome Tracing JSON

>>> from io import StringIO
>>> s = StringIO()
>>> trace.to_tef_json(file_like=s)  # Exported timestamps are in milliseconds by default
>>> print(s.getvalue())
{
    "traceEvents": [
        {
            "name": "my_event",
            "ts": 1000.0,
            "pid": 0,
            "tid": 0,
            "args": {},
            "ph": "B"
        },
        {
            "name": "my_event",
            "ts": 2000.0,
            "pid": 0,
            "tid": 0,
            "args": {},
            "ph": "E"
        }
    ],
    "displayTimeUnit": "ms"
}

The exported .json file can be opened in the trace visualization tools chrome://tracing in Chrome and Perfetto.

Match Event Chains

Different related events in a trace can be merged and represented as an event chain at a higher hierarchical level.

An event chain is described using an event pattern, where the following symbols have special interpretation:

  • + following an event name: the event begins.
  • - following an event name: the event ends.
  • *: arbitrary events, excluding repetitions.
>>> from trazer import Trace, TraceEventDurationBegin, TraceEventDurationEnd
>>> trace = Trace()

# Add an event sequence: event1 begins, event2 begins, event2 ends, event1 ends
>>> trace.add_events([
... TraceEventDurationBegin('event1', 1),
... TraceEventDurationBegin('event2', 2),
... TraceEventDurationEnd('event2', 3),
... TraceEventDurationEnd('event1', 4)
... ])

>>> print(trace)
[1 ms]: event1 (B)
[2 ms]: event2 (B)
[3 ms]: event2 (E)
[4 ms]: event1 (E)

>>> from trazer import TraceAnalyzer
>>> trace_analyzer = TraceAnalyzer(trace)

# We want to find the event chains matching the sequence:
# event1 begins -> event2 begins -> event2 ends -> event1 ends
>>> trace_analyzer.match('event1+event2+event2-event1-', 'event_chain')
[[1 - 4 ms]: event_chain (4 events)]

# Or use an alternative pattern employing wildcards.
# We want to find the event chains that begins with event1 and ends with event1.
>>> trace_analyzer = TraceAnalyzer(trace)
>>> trace_analyzer.match('event1+*-event1-', 'event_chain')
[[1 - 4 ms]: event_chain (4 events)]

Export Trace with Event Chains

The event chains can be visualized together with the original trace in the same view. For visualization in chrome://tracing or Perfetto, a dedicated process ID needs to be assigned to the event chains, such that they will be displayed separately from the original trace.

trace_analyzer.to_tef_json(5555)  # Process ID = 5555

Contributing

  1. Install development dependencies
pip install -r requirements-dev.txt
  1. Install runtime dependencies
pip install -r requirements.txt
  1. Setup pre-commit hook (formatting with black and linting with flake8)
pre-commit install
  1. Make sure all tests are passed by running pytest

Project details


Download files

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

Source Distribution

trazer-0.2.1.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

trazer-0.2.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file trazer-0.2.1.tar.gz.

File metadata

  • Download URL: trazer-0.2.1.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7

File hashes

Hashes for trazer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8304e2fc67a370167014a25219888761ec5219e8d06ea9632326d9b141a1a9b6
MD5 fa2d4bb0a0d1f68fb9fc83b3c671ea35
BLAKE2b-256 a10340aba0a438af1e203ebf70f13e7a239890aa016e16ae0fa8eeddc321a430

See more details on using hashes here.

File details

Details for the file trazer-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: trazer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7

File hashes

Hashes for trazer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ab126a8439293b9d4392040233118fa5a26ec2f17270d7b198c9444dbfacd0f
MD5 2623b7ad011bd1544a4eba3d709bfa57
BLAKE2b-256 e0798b7429ab749e2d1ff6b09f33aa9ee729335bd7c09cc0cdfaabd884a7af5c

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