"""One profiled request of a tool server (Qwen-Image 2.1's picture requests: qwen_profiled.py attaches it to the unchanged launchers/qwen_server.py from outside), with the [profiling] switches of spellcast3d-config.ini named as AURA-V5's training config names them. profiler = RequestProfiler.begin(config.profiling(), "qwen", info) # on the request's own thread profiler.mark("prompt"); profiler.mark("drawing 1/1", steps=20); profiler.step(1, 20); ... profiler.note("seconds", 120.4) profiler.finish("ok") # never raises The switches (enable ONE at a time, as in AURA): use_python_profiler PyInstrument on the request's thread (profiling_harness.start/stop_python_profiler): profile_raw.json + performance_summary.txt - the launcher's own Python around the ctypes call into stable-diffusion.cpp. use_torch_profiler torch.profiler with CPU + CUDA activities, record_shapes, no schedule, no Python stacks (all of Qwen-Image's work is stable-diffusion.cpp's C++: with_stack only added wrapper and event-loop rows at the top of AURA's summary, and ~40% to the trace): the whole request (begin..finish). CUPTI records stable-diffusion.cpp's kernels although PyTorch launches none -> trace.json + trace_summary.txt (AURA's process_torch_trace_json, then cuda_trace_report's phase and kernel-class tables). diagnostic_enable_sync_hunter the CUDA runtime's blocking calls and the GPU's idle gaps (cuda_trace_report's sync_report; torch's sync debug mode sees nothing here, see sync_hunter.py) -> sync_report.txt, from torch's trace when use_torch_profiler runs too, else from a lean CUPTI recording of its own (no shapes, no stacks) kept as sync_trace.json. python + torch both on: torch is skipped with a warning (AURA's rule, one at a time: there PyInstrument and with_stack's Python tracer conflict; here PyInstrument's sampling would also slow the request the trace times). sync runs beside either: its lean recording has no Python tracer. The request's parts are record_function annotations on its thread (they appear as user_annotation events, and as gpu_user_annotation around the kernels they launched - only when the CPU activity is recorded):