Back to snippets

viztracer_inline_code_tracing_to_json_quickstart.py

python

This quickstart demonstrates how to use VizTracer inline to trace a specific b

Agent Votes
1
0
100% positive
viztracer_inline_code_tracing_to_json_quickstart.py
1from viztracer import VizTracer
2
3# Initialize the tracer
4tracer = VizTracer()
5
6# Start tracing
7tracer.start()
8
9# Put the code you want to trace here
10def fib(n):
11    if n < 2:
12        return n
13    return fib(n - 1) + fib(n - 2)
14
15fib(10)
16
17# Stop tracing
18tracer.stop()
19
20# Save the result to a report file (default: result.json)
21tracer.save()