Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / tools / profiler / docs / memory.rst
blob347a91f9e7632494ce2cd2860d271746dfb39f21
1 Profiling Memory
2 ================
4 Sampling stacks from native allocations
5 ---------------------------------------
7 The profiler can sample allocations and de-allocations from malloc using the
8 "Native Allocations" feature. This can be enabled by going to `about:profiling` and
9 enabling the "Native Allocations" checkbox. It is only available in Nightly, as it
10 uses a technique of hooking into malloc that could be a little more risky to apply to
11 the broader population of Firefox users.
13 This implementation is located in: `tools/profiler/core/memory_hooks.cpp
14 <https://searchfox.org/mozilla-central/source/tools/profiler/core/memory_hooks.cpp>`_
16 It works by hooking into all of the malloc calls. When the profiler is running, it
17 performs a `Bernoulli trial`_, that will pass for a given probability of per-byte
18 allocated. What this means is that larger allocations have a higher chance of being
19 recorded compared to smaller allocations. Currently, there is no way to configure
20 the per-byte probability. This means that sampled allocation sizes will be closer
21 to the actual allocated bytes.
23 This infrastructure is quite similar to DMD, but with the additional motiviations of
24 making it easy to turn on and use with the profiler. The overhead is quite high,
25 especially on systems with more expensive stack walking, like Linux. Turning off
26 thee "Native Stacks" feature can help lower overhead, but will give less information.
28 For more information on analyzing these profiles, see the `Firefox Profiler docs`_.
30 Memory counters
31 ---------------
33 Similar to the Native Allocations feature, memory counters use the malloc memory hook
34 that is only available in Nightly. When it's available, the memory counters are always
35 turned on. This is a lightweight way to count in a very granular fashion how much
36 memory is being allocated and deallocated during the profiling session.
38 This information is then visualized in the `Firefox Profiler memory track`_.
40 This feature uses the `Profiler Counters`_, which can be used to create other types
41 of cheap counting instrumentation.
43 .. _Bernoulli trial: https://en.wikipedia.org/wiki/Bernoulli_trial
44 .. _Firefox Profiler docs: https://profiler.firefox.com/docs/#/./memory-allocations
45 .. _Firefox Profiler memory track: https://profiler.firefox.com/docs/#/./memory-allocations?id=memory-track
46 .. _Profiler Counters: https://searchfox.org/mozilla-central/source/tools/profiler/public/ProfilerCounts.h