Skip to content
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

feat: Add HTTP API for cpu profiling #1694

Merged
merged 15 commits into from Jun 7, 2023
Merged

Conversation

evenyag
Copy link
Contributor

@evenyag evenyag commented Jun 1, 2023

I hereby agree to the terms of the GreptimeDB CLA

What's changed and what's your intention?

This PR adds an HTTP API for CPU profiling. It also refactors the mem prof handler to make chaining handlers to the router easier.

Sample at 99 Hertz, for 5 seconds, output report in protobuf format.

curl -s '0:4000/v1/prof/cpu' > /tmp/pprof.out

Sample at 99 Hertz, for 60 seconds, output report in flamegraph format.

curl -s '0:4000/v1/prof/cpu?seconds=60&output=flamegraph' > /tmp/pprof.svg

Sample at 49 Hertz, for 10 seconds, output report in text format.

curl -s '0:4000/v1/prof/cpu?seconds=10&frequency=49&output=text' > /tmp/pprof.txt

This feature is disabled by default. To enable it, we need to build the binary with pprof feature

cargo build --features=pprof

Because the pprof API needs to sample for a specific duration, we must apply the timeout layer before it.

Note that this might panic on Apple silicon chips (M1/M2)

This PR also closes the test region in TestBase which should fix the test case test_flush_and_reopen.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

src/servers/src/http.rs Outdated Show resolved Hide resolved
@evenyag evenyag force-pushed the feat/pprof branch 3 times, most recently from 751c3ba to 3f74d4f Compare June 2, 2023 10:01
@evenyag
Copy link
Contributor Author

evenyag commented Jun 2, 2023

The default timeout layer can abort the perf API

2023-06-02T13:15:24.719305Z ERROR tower_http::trace::on_failure: response failed classification=Error: request timed out latency=30000 ms

@evenyag evenyag marked this pull request as ready for review June 5, 2023 04:01
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #1694 (24b1778) into develop (8cda163) will decrease coverage by 0.36%.
The diff coverage is 21.21%.

@@             Coverage Diff             @@
##           develop    #1694      +/-   ##
===========================================
- Coverage    86.58%   86.23%   -0.36%     
===========================================
  Files          575      578       +3     
  Lines        93294    93360      +66     
===========================================
- Hits         80782    80509     -273     
- Misses       12512    12851     +339     

src/common/pprof/Cargo.toml Outdated Show resolved Hide resolved
src/common/pprof/src/lib.rs Outdated Show resolved Hide resolved
src/servers/src/http/pprof.rs Show resolved Hide resolved
src/servers/src/http/pprof.rs Show resolved Hide resolved
@v0y4g3r v0y4g3r self-requested a review June 6, 2023 11:36
Copy link
Contributor

@v0y4g3r v0y4g3r left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelScofield MichaelScofield added Documentation Improvements or additions to documentation Doc update required This change requires document update on https://github.com/GreptimeTeam/docs labels Jun 7, 2023
@v0y4g3r v0y4g3r merged commit 5b8e54e into GreptimeTeam:develop Jun 7, 2023
15 checks passed
paomian pushed a commit to paomian/greptimedb that referenced this pull request Oct 19, 2023
* chore: print source error in mem-prof

* feat(common-pprof): add pprof crate

* feat(servers): Add pprof handler to router

refactor the mem_prof handler to avoid checking feature while
registering router

* feat(servers): pprof handler support different output type

* docs(common-pprof): Add readme

* feat(common-pprof): Build guard using code in pprof-rs's example

* feat(common-pprof): use prost

* feat: don't add timeout to perf api

* feat: add feature pprof

* feat: update readme

* test: fix tests

* feat: close region in TestBase

* feat(pprof): addres comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc update required This change requires document update on https://github.com/GreptimeTeam/docs Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants