You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`uftrace <https://github.com/namhyung/uftrace/wiki/Tutorial#getting-started>`_ is a great tool to generate rich profile data
96
+
that you can use to focus and drill down into the timeline of your application.
97
+
We will use it to generate Chromium trace JSON.
98
+
In contrast to ``perf``, this approach statically instruments every function, so it should be more precise and thorough than the sampling-based approaches like ``perf``.
99
+
In contrast to using ``-ftime-trace``, functions don't need to opt-in to be profiled using ``llvm::TimeTraceScope``.
100
+
All functions are profiled due to automatic static instrumentation.
101
+
102
+
There is only one prerequisite to use this tool.
103
+
You need to build the binary you are about to instrument using ``-pg`` or ``-finstrument-functions``.
104
+
This will make it run substantially slower but allows rich instrumentation.
105
+
It will also consume many gigabites of storage for a single trace unless filter flags are used during recording.
106
+
107
+
.. code-block:: bash
108
+
:caption: Recording with ``uftrace``, then dumping the result as a Chrome trace JSON.
109
+
110
+
uftrace record clang -cc1 -analyze -verify clang/test/Analysis/string.c \
In this picture, you can see the functions below the Static Analyzer's entry point, which takes at least 300 nanoseconds to run, visualized by Chrome's ``about:tracing`` page
117
+
You can also see how deep function calls we may have due to AST visitors.
118
+
119
+
Using different filters can reduce the number of functions to record.
120
+
For the common options, refer to the ``uftrace`` `documentation <https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md#common-options>`_.
121
+
122
+
Similar filters can be applied for dumping too. That way you can reuse the same (detailed)
123
+
recording to selectively focus on some special part using a refinement of the filter flags.
124
+
Remember, the trace JSON needs to fit into Chrome's ``about:tracing`` or `speedscope <https://speedscope.app>`_,
125
+
thus it needs to be of a limited size.
126
+
If you do not apply filters on recording, you will collect a large trace and every dump operation
127
+
would need to sieve through the much larger recording which may be annoying if done repeatedly.
128
+
129
+
If the trace JSON is still too large to load, have a look at the dump as plain text and look for frequent entries that refer to non-interesting parts.
130
+
Once you have some of those, add them as ``--hide`` flags to the ``uftrace dump`` call.
131
+
To see what functions appear frequently in the trace, use this command:
0 commit comments