-
Notifications
You must be signed in to change notification settings - Fork 5
Add CPU profile capture #499
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
Open
loganintech
wants to merge
6
commits into
main
Choose a base branch
from
logan/add-cpu-profile-capture
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
6 commits
Select commit
Hold shift + click to select a range
e816c32
Add CPU profile capture cli args.
loganintech 17981bd
This generates _a_ profile not sure it generates a _good_ profile.
loganintech 4376171
Profile the client too
loganintech 7a45bc0
Minimal logging
loganintech efe0f22
Linting
loganintech 3d33313
Smh
loganintech 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package connector | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" | ||
|
|
||
| connectorwrapperV1 "github.com/conductorone/baton-sdk/pb/c1/connector_wrapper/v1" | ||
| "github.com/conductorone/baton-sdk/pkg/profiling" | ||
| ) | ||
|
|
||
| // profileService implements the ProfileService gRPC service. | ||
| type profileService struct { | ||
| connectorwrapperV1.UnimplementedProfileServiceServer | ||
| profiler *profiling.Profiler | ||
| } | ||
|
|
||
| // FlushProfiles writes pending profile data to disk. | ||
| func (ps *profileService) FlushProfiles(ctx context.Context, req *connectorwrapperV1.FlushProfilesRequest) (*connectorwrapperV1.FlushProfilesResponse, error) { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Info("FlushProfiles RPC called, stopping profiling and writing profiles") | ||
|
|
||
| if ps.profiler == nil { | ||
| return &connectorwrapperV1.FlushProfilesResponse{ | ||
| Success: true, | ||
| }, nil | ||
| } | ||
|
|
||
| // Stop CPU profiling to flush data | ||
| if err := ps.profiler.Stop(ctx); err != nil { | ||
| //nolint:nilerr // This should be nil, we're returning the error to the client | ||
| return &connectorwrapperV1.FlushProfilesResponse{ | ||
| Success: false, | ||
| Error: err.Error(), | ||
| }, nil | ||
| } | ||
|
|
||
| // Write memory profile | ||
| if err := ps.profiler.WriteMemProfile(ctx); err != nil { | ||
| //nolint:nilerr // This should be nil, we're returning the error to the client | ||
| return &connectorwrapperV1.FlushProfilesResponse{ | ||
| Success: false, | ||
| Error: err.Error(), | ||
| }, nil | ||
| } | ||
|
|
||
| return &connectorwrapperV1.FlushProfilesResponse{ | ||
| Success: true, | ||
| }, nil | ||
| } |
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.
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.
Update for compatibility with the profile_service.go gRPC error fix.
Once
profile_service.gois fixed to return proper gRPC errors (as suggested in the previous review), this method will break. When the service returns an error viastatus.Errorf,respwill be nil and lines 385-387 will cause a panic or become unreachable.Apply this diff to handle errors correctly:
func (cw *wrapper) FlushProfiles(ctx context.Context) error { cw.mtx.RLock() conn := cw.conn cw.mtx.RUnlock() if conn == nil { return fmt.Errorf("no active connection") } client := connectorwrapperV1.NewProfileServiceClient(conn) - resp, err := client.FlushProfiles(ctx, &connectorwrapperV1.FlushProfilesRequest{}) - if err != nil { - return err - } - - if !resp.Success { - return fmt.Errorf("profile flush failed: %s", resp.Error) - } - - return nil + _, err := client.FlushProfiles(ctx, &connectorwrapperV1.FlushProfilesRequest{}) + return err }This simplifies the method to rely on the gRPC error convention where errors are returned via the error return value, not via response fields.
🤖 Prompt for AI Agents