Commit 72793ebb authored by Nick Gaskill's avatar Nick Gaskill

Merge branch '352403-memory-profiler-docs' into 'master'

Docs update for memory profiler and performance bar

See merge request gitlab-org/gitlab!80598
parents e84cc181 57c7a0f1
...@@ -65,6 +65,9 @@ From left to right, the performance bar displays: ...@@ -65,6 +65,9 @@ From left to right, the performance bar displays:
can be added by its full URL (authenticated as the current user), or by the value of can be added by its full URL (authenticated as the current user), or by the value of
its `X-Request-Id` header. its `X-Request-Id` header.
- **Download**: a link to download the raw JSON used to generate the Performance Bar reports. - **Download**: a link to download the raw JSON used to generate the Performance Bar reports.
- **Memory Report**: a link that generates a
[memory profiling](../../../development/performance.md#using-memory-profiler)
report of the current URL.
- **Flamegraph** with mode: a link to generate a [flamegraph](../../../development/profiling.md#speedscope-flamegraphs) - **Flamegraph** with mode: a link to generate a [flamegraph](../../../development/profiling.md#speedscope-flamegraphs)
of the current URL with the selected [Stackprof mode](https://github.com/tmm1/stackprof#sampling): of the current URL with the selected [Stackprof mode](https://github.com/tmm1/stackprof#sampling):
- The **Wall** mode samples every *interval* of the time on a clock on a wall. The interval is set to `10100` microseconds. - The **Wall** mode samples every *interval* of the time on a clock on a wall. The interval is set to `10100` microseconds.
......
...@@ -459,11 +459,14 @@ The `mem_*` values represent different aspects of how objects and memory are all ...@@ -459,11 +459,14 @@ The `mem_*` values represent different aspects of how objects and memory are all
We can use `memory_profiler` for profiling. We can use `memory_profiler` for profiling.
The [`memory_profiler`](https://github.com/SamSaffron/memory_profiler) gem is already present in the GitLab `Gemfile`, The [`memory_profiler`](https://github.com/SamSaffron/memory_profiler)
you just need to require it: gem is already present in the GitLab `Gemfile`. It's also available in the [performance bar](../administration/monitoring/performance/performance_bar.md)
for the current URL.
To use the memory profiler directly in your code, use `require` to add it:
```ruby ```ruby
require 'sidekiq/testing' require 'memory_profiler'
report = MemoryProfiler.report do report = MemoryProfiler.report do
# Code you want to profile # Code you want to profile
...@@ -473,10 +476,17 @@ output = File.open('/tmp/profile.txt','w') ...@@ -473,10 +476,17 @@ output = File.open('/tmp/profile.txt','w')
report.pretty_print(output) report.pretty_print(output)
``` ```
The report breaks down 2 key concepts: The report shows the retained and allocated memory grouped by gem, file, location, and class. The
memory profiler also performs a string analysis that shows how often a string is allocated and
retained.
#### Retained versus allocated
- Retained: long lived memory use and object count retained due to the execution of the code block. - Retained memory: long-lived memory use and object count retained due to the execution of the code
- Allocated: all object allocation and memory allocation during code block. block. This has a direct impact on memory and the garbage collector.
- Allocated memory: all object allocation and memory allocation during the code block. This might
have minimal impact on memory, but substantial impact on performance. The more objects you
allocate, the more work is being done and the slower the application is.
As a general rule, **retained** is always smaller than or equal to **allocated**. As a general rule, **retained** is always smaller than or equal to **allocated**.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment