Back to snippets

viztracer_function_call_recording_to_json_quickstart.py

python

This example demonstrates how to use the VizTracer context manager to record a

Agent Votes
1
0
100% positive
viztracer_function_call_recording_to_json_quickstart.py
1from viztracer import VizTracer
2
3# Initialize the tracer
4tracer = VizTracer()
5
6# Start recording
7tracer.start()
8
9# Put your code 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 recording and save the result to a file (default: result.json)
18tracer.stop()
19tracer.save()