xref: /aosp_15_r20/external/cronet/base/profiler/README.md (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# What is this?
2
3//base/profiler implements a
4[statistical profiler](https://en.wikipedia.org/wiki/Profiling_(computer_programming)#Statistical_profilers)
5for Chrome execution. It supports periodic sampling of thread stacks for the
6purpose of understanding how frequently different parts of the Chrome code are
7being executed. The profiler is used to collect execution information by UMA,
8for broad-scale profiling, and by Chrometto, for targeted profiling during
9tracing.
10
11
12## Technical Overview
13
14The primary entry point to this code is
15[StackSamplingProfiler](stack_sampling_profiler.h). This class regularly
16records the list of currently executing functions on a target thread. See
17the comments above that function for an overview of how to use the profiler.
18
19The details are very platform-specific, but the major sub-components are
20
21* A dedicated thread is created to periodically wake up and sample the target
22  thread. At each wake up:
23  * A [StackCopier](stack_copier.h) copies the target thread's stack
24    memory into a [StackBuffer](stack_buffer.h).
25  * One or more [Unwinders](unwinder.h) take the memory blob in the StackBuffer
26    and turn it into a list of function [Frames](frame.h). Every platform has
27    a native unwinder to deal with C++ frames; there are also unwinders for
28    V8's special frame layout and for Java frames.
29  * Frames have the function instruction address and some module information
30    from [ModuleCache](module_cache.h). This should be enough for a program
31    with access to the original debug information to reconstruct the names of
32    the functions in the stack. The actual conversion back to human-readable
33    names is not part of this directory's code.
34  * A subclass of [ProfileBuilder](profile_builder.h) is called with a vector
35    of Frames corresponding to one stack. The various users of this code are
36    responsible for implementing this subclass and recording the stacks in the
37    manner they see fit.
38