From c6f5cf50fb5a0fccfce5d56bc9ab270cab050da6 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 9 Jul 2026 14:06:41 +0300 Subject: [PATCH] manual: Fix decorators in the Python listing and typo --- manual/latex2md.sh | 2 + manual/tracy.md | 102 +++++++++++++++++++++++---------------------- manual/tracy.tex | 4 +- 3 files changed, 56 insertions(+), 52 deletions(-) diff --git a/manual/latex2md.sh b/manual/latex2md.sh index 940a850a..9f687c2e 100644 --- a/manual/latex2md.sh +++ b/manual/latex2md.sh @@ -19,6 +19,8 @@ sed -i -e 's@\\textsigma@σ@g' _tmp.tex sed -i -e 's|@\\circled{a}@|(a)|g' -e 's|@\\circled{b}@|(b)|g' -e 's|@\\circled{c}@|(c)|g' _tmp.tex sed -i -e 's|\\circled{a}|(a)|g' -e 's|\\circled{b}|(b)|g' -e 's|\\circled{c}|(c)|g' _tmp.tex sed -i -e 's|@\\ldots@|…|g' _tmp.tex +# pandoc doens't recognize this lstlisting option and emits it verbatim +sed -i -e 's|,\?escapeinside={}{}||g' _tmp.tex sed -i -e 's@\\nameref{quicklook}@A quick look at Tracy Profiler@g' _tmp.tex sed -i -e 's@\\nameref{firststeps}@First steps@g' _tmp.tex diff --git a/manual/tracy.md b/manual/tracy.md index cc60091a..9125fd62 100644 --- a/manual/tracy.md +++ b/manual/tracy.md @@ -2205,82 +2205,84 @@ An especially powerful feature is the ability to profile Python code and any oth An example of how to use the Tracy-Client bindings is shown below: - #!/usr/bin/env python3 - # -*- coding: utf-8 -*- +``` {.python language="Python"} +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- - from time import sleep +from time import sleep - import numpy as np +import numpy as np - import tracy_client as tracy +import tracy_client as tracy - @tracy.ScopedFrameDecorator("framed") - @tracy.ScopedZoneDecorator(name="work", color=tracy.ColorType.Red4) - def work(): - sleep(0.05) +@tracy.ScopedFrameDecorator("framed") +@tracy.ScopedZoneDecorator(name="work", color=tracy.ColorType.Red4) +def work(): + sleep(0.05) - def main(): - assert tracy.program_name("MyApp") - assert tracy.app_info("this is a python app") +def main(): + assert tracy.program_name("MyApp") + assert tracy.app_info("this is a python app") - tracy.thread_name("python") # main thread so bit useless + tracy.thread_name("python") # main thread so bit useless - plot_id = tracy.plot_config("plot", tracy.PlotFormatType.Number) - assert plot_id is not None + plot_id = tracy.plot_config("plot", tracy.PlotFormatType.Number) + assert plot_id is not None - mem_id = None + mem_id = None - index = 0 - while True: - with tracy.ScopedZone(name="test", color=tracy.ColorType.Coral) as zone: - index += 1 + index = 0 + while True: + with tracy.ScopedZone(name="test", color=tracy.ColorType.Coral) as zone: + index += 1 - tracy.frame_mark() + tracy.frame_mark() - inner = tracy.ScopedZone(depth=5, color=tracy.ColorType.Coral) - inner.color(index % 5) - inner.name(str(index)) - inner.enter() + inner = tracy.ScopedZone(depth=5, color=tracy.ColorType.Coral) + inner.color(index % 5) + inner.name(str(index)) + inner.enter() - if index % 2: - tracy.alloc(44, index) + if index % 2: + tracy.alloc(44, index) + else: + tracy.free(44) + + if not index % 2: + if mem_id is None: + mem_id = tracy.alloc(1337000000, index, name="named", depth=4) + assert mem_id is not None else: - tracy.free(44) + tracy.alloc(1337000000, index, id=mem_id, depth=4) + else: + tracy.free(1337000000, mem_id, 4) - if not index % 2: - if mem_id is None: - mem_id = tracy.alloc(1337000000, index, name="named", depth=4) - assert mem_id is not None - else: - tracy.alloc(1337000000, index, id=mem_id, depth=4) - else: - tracy.free(1337000000, mem_id, 4) + with tracy.ScopedFrame("custom"): - with tracy.ScopedFrame("custom"): + image = np.full([400, 400, 4], index, dtype=np.uint8) + assert tracy.frame_image(image.tobytes(), 400, 400) - image = np.full([400, 400, 4], index, dtype=np.uint8) - assert tracy.frame_image(image.tobytes(), 400, 400) + inner.exit() - inner.exit() + zone.text(index) - zone.text(index) + assert tracy.message(f"we are at index {index}") + assert tracy.message(f"we are at index {index}", tracy.ColorType.Coral) - assert tracy.message(f"we are at index {index}") - assert tracy.message(f"we are at index {index}", tracy.ColorType.Coral) + assert tracy.plot(plot_id, index) - assert tracy.plot(plot_id, index) + work() - work() - - sleep(0.1) + sleep(0.1) - if __name__ == "__main__": - main() +if __name__ == "__main__": + main() +``` -Please not the use of ids as way to cope with the need for unique pointers for certain features of the Tracy profiler, see section [3.1.2](#uniquepointers). +Please note the use of ids as way to cope with the need for unique pointers for certain features of the Tracy profiler, see section [3.1.2](#uniquepointers). ### Building the Python package diff --git a/manual/tracy.tex b/manual/tracy.tex index 50efb920..6f265bd8 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -2482,7 +2482,7 @@ An especially powerful feature is the ability to profile Python code and any oth An example of how to use the Tracy-Client bindings is shown below: -\begin{lstlisting} +\begin{lstlisting}[language=Python,escapeinside={}{}] #!/usr/bin/env python3 # -*- coding: utf-8 -*- @@ -2559,7 +2559,7 @@ if __name__ == "__main__": main() \end{lstlisting} -Please not the use of ids as way to cope with the need for unique pointers for certain features of the Tracy profiler, see section~\ref{uniquepointers}. +Please note the use of ids as way to cope with the need for unique pointers for certain features of the Tracy profiler, see section~\ref{uniquepointers}. \subsubsection{Building the Python package}