-
Notifications
You must be signed in to change notification settings - Fork 5.1k
docs: added developer docs for pprof/tcmalloc testing #4194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing this up. FYI, this already works with static linking and enabling the heap profiler via env variables. Static linking forcing is here: https://github.com/envoyproxy/envoy/blob/master/source/common/profiler/profiler.cc#L21
Then you just run Envoy with the appropriate environment variables: https://gperftools.github.io/gperftools/heapprofile.html (e.g., HEAPPROFILE).
What you show here is how to get it working against the dynamic linked tcmalloc which seems fine but would it be better to document how it works out of the box? Up to you.
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
bazel/PPROF.md
Outdated
|
||
Just compile Envoy as normal: | ||
|
||
$ bazel build //source/exe:envoy-static --copt='-ltcmalloc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copt isn't needed. We compile against tcmalloc by default.
Signed-off-by: James Buckland <jbuckland@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Just a few minor nits
bazel/PPROF.md
Outdated
|
||
### Compiling a statically-linked Envoy | ||
|
||
Just compile Envoy as normal: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: phrasing - I would prefer something like: Build the static binary using bazel:
bazel/PPROF.md
Outdated
|
||
### Running a statically-linked Envoy with `pprof` | ||
|
||
And run the binary with a `HEAPPROFILE` env var, like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove And
.
Also, can you add a brief explanation of what the HEAPPROFILE
environment variable does (It's explained below, so just saying it will be explained in section X would work too)?
bazel/PPROF.md
Outdated
|
||
### Adding `tcmalloc_dep` to Envoy | ||
|
||
To add a `HeapProfiler` breakpoint yourself, add `tcmalloc` as a dependency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe add a one sentence explanation (or link) explaining what a heap profiler break point does? Or, you could add a section (or link) at the top that explains the ways you can use the heap profiler.
Also, do heap profiler break points only work/apply in the dynamic linking setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the statically linked Envoy profiles everything by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks always for docs!
bazel/PPROF.md
Outdated
} | ||
``` | ||
|
||
Once these changes have been implemented against head, it might make sense to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of "head" here seems a little weird. For example, I bet lots of people would want to use this to test a branch where they are developing a PR, not actually "head". Instead, maybe something like "Once these changes have been made in your working directory"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, you're right. This was a holdover from when I was enabling profiling against both upstream/master and my branch.
bazel/PPROF.md
Outdated
|
||
### Compiling a dynamically-linked Envoy with `pprof` | ||
|
||
The binary must be explicitly built with `tcmalloc` like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to write -ltcmalloc
for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, are you sure this is needed even for the dynamic case?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch -- the inclusion of tcmalloc_dep = 1
is sufficient.
bazel/PPROF.md
Outdated
|
||
### Running a dynamically-linked Envoy with `pprof` | ||
|
||
You can then run the binary without any env vars: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just say "Run the binary without any env vars:"
bazel/PPROF.md
Outdated
|
||
$ timeout <num_seconds> bazel-bin/source/exe/envoy <options> | ||
|
||
During a run, the binary should print something like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To stdout? stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To stdout by default.
bazel/PPROF.md
Outdated
|
||
*NB:* There is no reason this needs to be titled `main_common_base`: whatever | ||
flag you supply `HeapProfilerStart` / `HeapProfilerDump` will become the | ||
filename. Multiple ranges could be tested at the same time with this method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "range" refer to here? The time interval between HeapProfilerStart
and HeapProfilerDump
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be more explicit about profiling a section of code, not a range of time. I'll fix.
bazel/PPROF.md
Outdated
|
||
# Analyzing with `pprof` | ||
|
||
[pprof](https://github.com/google/pprof) can then read these heap files in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: drop "then"
Signed-off-by: James Buckland <jbuckland@google.com>
* origin/master: (34 commits) fuzz: fixes oss-fuzz: 9895 (envoyproxy#4189) docs: added developer docs for pprof/tcmalloc testing (envoyproxy#4194) fix sometimes returns response body to HEAD requests (envoyproxy#3985) admin: fix config dump order (envoyproxy#4197) thrift: allow translation between downstream and upstream protocols (envoyproxy#4136) Use local_info.node() instead of bootstrap.node() whenever possible (envoyproxy#4120) upstream: allow extension protocol options to be used with http filters (envoyproxy#4165) [thrift_proxy] Replace local HeaderMap with Http::HeaderMap[Impl] (envoyproxy#4169) docs: improve gRPC-JSON filter doc (envoyproxy#4184) stats: refactoring MetricImpl without strings (envoyproxy#4190) fuzz: coverage profile generation instructions. (envoyproxy#4193) upstream: rebuild cluster when health check config is changed (envoyproxy#4075) build: use clang-6.0. (envoyproxy#4168) thrift_proxy: introduce header transport (envoyproxy#4082) tcp: allow connection pool callers to store protocol state (envoyproxy#4131) configs: match latest API changes (envoyproxy#4185) Fix wrong mock function name. (envoyproxy#4187) Bump yaml-cpp so it builds with Visual Studio 15.8 (envoyproxy#4182) Converting envoy configs to V2 (envoyproxy#2957) Add timestamp to HealthCheckEvent definition (envoyproxy#4119) ... Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: James Buckland jbuckland@google.com
Description: Follow-up to #4190, explaining how
pprof
/tcmalloc
can be used for memory consumption performance testing.Risk Level: None
Testing: None
Docs Changes: Added a developer-facing documentation under
bazel/PPROF.md
.Release Notes: N/A