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