This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
PMM-5492 Add Pprof data to logs.zip #1117
Open
pkadej
wants to merge
19
commits into
main
Choose a base branch
from
PMM-5492-pprof-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e92bca5
PMM-5492 Pprof tool implementation.
pkadej 882f9aa
PMM-5492 Pprof in /logs.zip implementation.
pkadej 366d963
PMM-5492 Added pprof_test.go.
pkadej a3c438d
PMM-5492 Added pprof_test.go.
pkadej 80e5d2d
Merge branch 'main' into PMM-5492-pprof-support
pkadej 683b4db
PMM-5492 Format fix.
pkadej 214a656
PMM-5492 Format fix.
pkadej b8ddc92
PMM-5492 Tests fix.
pkadej ea5c617
PMM-5492 Linter fix.
pkadej 2f36941
PMM-5492 Added configuration support
pkadej f8aa75a
Merge branch 'main' into PMM-5492-pprof-support
pkadej b0e5163
Merge branch 'main' into PMM-5492-pprof-support
pkadej a28413e
PMM-5492 Code review adjustments.
pkadej 28e4406
PMM-5492 Code review adjustments.
pkadej 291869e
PMM-5492 Code review adjustments.
pkadej 22c5b95
Merge branch 'main' into PMM-5492-pprof-support
pkadej 27856c8
PMM-5492 Code review adjustments.
pkadej d988223
Merge branch 'main' into PMM-5492-pprof-support
pkadej 3d5d295
PMM-5492 Test fixes.
pkadej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // pmm-managed | ||
| // Copyright (C) 2017 Percona LLC | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package pprof | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "runtime" | ||
| "runtime/pprof" | ||
| "runtime/trace" | ||
| "time" | ||
| ) | ||
|
|
||
| // Profile responds with the pprof-formatted cpu profile. | ||
| // Profiling lasts for duration specified in seconds. | ||
| func Profile(duration time.Duration) ([]byte, error) { | ||
| var profileBuf bytes.Buffer | ||
| if err := pprof.StartCPUProfile(&profileBuf); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| time.Sleep(duration) | ||
| pprof.StopCPUProfile() | ||
|
|
||
| return profileBuf.Bytes(), nil | ||
| } | ||
|
|
||
| // Trace responds with the execution trace in binary form. | ||
| // Tracing lasts for duration specified in seconds. | ||
| func Trace(duration time.Duration) ([]byte, error) { | ||
| var traceBuf bytes.Buffer | ||
| if err := trace.Start(&traceBuf); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| time.Sleep(duration) | ||
| trace.Stop() | ||
|
|
||
| return traceBuf.Bytes(), nil | ||
| } | ||
|
|
||
| // Heap responds with the pprof-formatted profile named "heap". | ||
| // listing the available profiles. | ||
| // You can specify the gc parameter to run gc before taking the heap sample. | ||
| func Heap(gc bool) ([]byte, error) { | ||
| var heapBuf bytes.Buffer | ||
| debug := 0 | ||
| profile := "heap" | ||
|
|
||
| p := pprof.Lookup(profile) | ||
| if p == nil { | ||
| return nil, fmt.Errorf("profile cannot be found: %s", profile) | ||
| } | ||
|
|
||
| if gc { | ||
| runtime.GC() | ||
| } | ||
|
|
||
| err := p.WriteTo(&heapBuf, debug) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return heapBuf.Bytes(), nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // pmm-managed | ||
| // Copyright (C) 2017 Percona LLC | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package pprof | ||
|
|
||
| import ( | ||
| "time" | ||
| ) | ||
|
|
||
| // Config pprof settings. | ||
| type Config struct { | ||
| ProfileDuration time.Duration `yaml:"profile_duration"` //nolint:tagliatelle | ||
| TraceDuration time.Duration `yaml:"trace_duration"` //nolint:tagliatelle | ||
| } | ||
|
|
||
| // Init pprof config init. | ||
| func (c *Config) Init() { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // pmm-managed | ||
| // Copyright (C) 2017 Percona LLC | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package pprof | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "compress/gzip" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestHeap(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("Heap test", func(t *testing.T) { | ||
| heapBytes, err := Heap(true) | ||
|
|
||
| // read gzip | ||
| reader, err := gzip.NewReader(bytes.NewBuffer(heapBytes)) | ||
| assert.NoError(t, err) | ||
|
|
||
| var resB bytes.Buffer | ||
| _, err = resB.ReadFrom(reader) | ||
| assert.NoError(t, err) | ||
| assert.NotEmpty(t, resB.Bytes()) | ||
| }) | ||
| } | ||
|
|
||
| func TestProfile(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("Profile test", func(t *testing.T) { | ||
| profileBytes, err := Profile(1 * time.Second) | ||
|
|
||
| assert.NoError(t, err) | ||
| assert.NotEmpty(t, profileBytes) | ||
|
|
||
| // read gzip | ||
| reader, err := gzip.NewReader(bytes.NewBuffer(profileBytes)) | ||
| assert.NoError(t, err) | ||
|
|
||
| var resB bytes.Buffer | ||
| _, err = resB.ReadFrom(reader) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.NotEmpty(t, resB.Bytes()) | ||
| }) | ||
| } | ||
|
|
||
| func TestTrace(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("Trace test", func(t *testing.T) { | ||
| traceBytes, err := Trace(1 * time.Second) | ||
|
|
||
| assert.NoError(t, err) | ||
| assert.NotEmpty(t, traceBytes) | ||
| }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess nginx will terminate connections longer than 10 minutes. Can you please check it? If so we should document this limitation or change nginx configuration.