Skip to content

Conversation

ambuc
Copy link
Contributor

@ambuc ambuc commented Aug 17, 2018

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

ambuc added 2 commits August 17, 2018 12:37
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Copy link
Member

@mattklein123 mattklein123 left a 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.

ambuc added 2 commits August 17, 2018 14:39
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'
Copy link
Member

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>
Copy link
Member

@mrice32 mrice32 left a 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:
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@dnoe dnoe left a 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
Copy link
Contributor

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"?

Copy link
Contributor Author

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:
Copy link
Contributor

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?

Copy link
Contributor

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?)

Copy link
Contributor Author

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:
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To stdout? stderr?

Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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>
@dnoe dnoe merged commit 9058d46 into envoyproxy:master Aug 20, 2018
snowp pushed a commit to snowp/envoy that referenced this pull request Aug 20, 2018
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants