Repository navigation
fix(profiler): keep partial results when a PID fails, and explain pprof failures #139
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
760a922
fix(profiler): keep the profiles of PIDs that succeed when another fails
mayankpande88 871e50d
fix(profiler): fail the PID when its flamegraph cannot be rendered
mayankpande88 2bb038e
fix(go): say why a pprof scrape failed
mayankpande88 65be9ae
test(e2e): profile multi-process Python targets and real Go servers
mayankpande88 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,87 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/nudgebee/application-profiler/api" | ||
| "github.com/nudgebee/application-profiler/pkg/util/log" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // ProfilePIDs runs profile once for every PID, concurrently, starting each one | ||
| // delay after the previous so a container with many processes is not hit all | ||
| // at once. Each PID publishes its own result. | ||
| // | ||
| // The PIDs are the leaf processes of the container's process tree, which | ||
| // routinely include ones the tool cannot profile: a shell, a sidecar-style | ||
| // helper, a process that is not the target's runtime, one that exits | ||
| // mid-run. One of those failing must not throw away the profiles the others | ||
| // produced, so the run succeeds as long as at least one PID did, and a notice | ||
| // names the PIDs that were skipped and why. It fails only when every PID | ||
| // failed, with each one's reason. | ||
| func ProfilePIDs(pids []string, delay time.Duration, profile func(pid string) error) error { | ||
| if len(pids) == 0 { | ||
| // Nothing would be published, so succeeding here would end the run | ||
| // without a result. | ||
| return errors.New("no PIDs to profile") | ||
| } | ||
|
|
||
| errs := make([]error, len(pids)) | ||
| var wg sync.WaitGroup | ||
| for i, pid := range pids { | ||
| if i > 0 { | ||
| // wait a bit between jobs for not overloading the system | ||
| time.Sleep(delay) | ||
| } | ||
| wg.Go(func() { errs[i] = profile(pid) }) | ||
| } | ||
| wg.Wait() | ||
|
|
||
| var failed pidErrors | ||
| for i, err := range errs { | ||
| if err != nil { | ||
| failed = append(failed, pidError{pid: pids[i], err: err}) | ||
| } | ||
| } | ||
| switch len(failed) { | ||
| case 0: | ||
| return nil | ||
| case len(pids): | ||
| return failed | ||
| } | ||
|
|
||
| _ = log.EventLn(api.Notice, &api.NoticeData{ | ||
| Time: time.Now(), | ||
| Msg: fmt.Sprintf("Profiled %d of %d PIDs; skipped %s", | ||
| len(pids)-len(failed), len(pids), failed.Error()), | ||
| }) | ||
| return nil | ||
| } | ||
|
|
||
| // pidError is the reason one PID could not be profiled. | ||
| type pidError struct { | ||
| pid string | ||
| err error | ||
| } | ||
|
|
||
| // pidErrors reads "PID <n>: <reason>; PID <m>: <reason>". | ||
| type pidErrors []pidError | ||
|
|
||
| func (e pidErrors) Error() string { | ||
| reasons := make([]string, len(e)) | ||
| for i, f := range e { | ||
| reasons[i] = fmt.Sprintf("PID %s: %s", f.pid, f.err) | ||
| } | ||
| return strings.Join(reasons, "; ") | ||
| } | ||
|
|
||
| func (e pidErrors) Unwrap() []error { | ||
| errs := make([]error, len(e)) | ||
| for i, f := range e { | ||
| errs[i] = f.err | ||
| } | ||
| return errs | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.