# Path: test/util.py
# def busy_wait(duration):
#     end_time = time.time() + duration
# 
#     while time.time() < end_time:
#         do_nothing()
# 
# Path: test/low_level/util.py



import contextvars
import time
import pytest
from ..util import busy_wait
from .util import parametrize_setstatprofile
        setstatprofile(None)


profiler_context_var = contextvars.ContextVar("profiler_context_var", default=None)


@parametrize_setstatprofile
def test_context_tracking(setstatprofile):
    profile_calls = []

    def profile_callback(frame, event, arg):
        nonlocal profile_calls
        profile_calls.append((frame, event, arg))

    profiler_1 = object()
    profiler_2 = object()

    context_1 = contextvars.copy_context()
    context_2 = contextvars.copy_context()

    context_1.run(profiler_context_var.set, profiler_1)
    context_2.run(profiler_context_var.set, profiler_2)

    setstatprofile(
        profile_callback,
        1e10,  # set large interval so we only get context_change events
        profiler_context_var,
    )

    context_1.run(busy_wait, 0.001)

# Path: test/util.py
# def busy_wait(duration):
#     end_time = time.time() + duration
# 
#     while time.time() < end_time:
#         do_nothing()
# 
# Path: test/low_level/util.py



# Path: test/low_level/test_context.py
import contextvars
import time
import pytest
from ..util import busy_wait
from .util import parametrize_setstatprofile

        setstatprofile(None)


profiler_context_var = contextvars.ContextVar("profiler_context_var", default=None)


@parametrize_setstatprofile
def test_context_tracking(setstatprofile):
    profile_calls = []

    def profile_callback(frame, event, arg):
        nonlocal profile_calls
        profile_calls.append((frame, event, arg))

    profiler_1 = object()
    profiler_2 = object()

    context_1 = contextvars.copy_context()
    context_2 = contextvars.copy_context()

    context_1.run(profiler_context_var.set, profiler_1)
    context_2.run(profiler_context_var.set, profiler_2)

    setstatprofile(
        profile_callback,
        1e10,  # set large interval so we only get context_change events
        profiler_context_var,
    )

    context_1.run(busy_wait, 0.001)

    context_2.run(busy_wait, 0.001)