-
Notifications
You must be signed in to change notification settings - Fork 34
WIP: tracing #41
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
Draft
flowchartsman
wants to merge
5
commits into
jackc:master
Choose a base branch
from
flowchartsman:tracing
base: master
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.
Draft
WIP: tracing #41
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
759dc73
WIP: tracing
flowchartsman 395c859
remove dead code around context.Value
flowchartsman f26e800
doc: fix ReleaseEnd name
flowchartsman 535c347
chore: remove unused ReleaseTracer iface
flowchartsman bccc38f
reorg: declare waitTime in main function body
flowchartsman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package puddle | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
| ) | ||
|
|
||
| // Tracer traces pool actions. | ||
| type Tracer interface { | ||
| // AcquireStart is called at the beginning of Acquire calls. The return | ||
| // context is used for the rest of the call and will be passed to AcquireEnd | ||
| AcquireStart(ctx context.Context, data AcquireStartData) context.Context | ||
| AcquireEnd(ctx context.Context, data AcquireEndData) | ||
| // ReleaseStart is called at the beginning of Release calls. The return | ||
| // context is used for the rest of the call and will be passed to ReleaseEnd | ||
| ReleaseStart(ctx context.Context, data ReleaseStartData) context.Context | ||
| ReleaseEnd(ctx context.Context, data ReleaseEndData) | ||
| } | ||
|
|
||
| type AcquireStartData struct { | ||
| StartNano int64 | ||
| } | ||
|
|
||
| type AcquireEndData struct { | ||
| WaitDuration time.Duration | ||
| AcquireDuration time.Duration | ||
| InitDuration time.Duration | ||
| ResourceStats ResourceTraceStats | ||
| Err error | ||
| } | ||
|
|
||
| type ReleaseStartData struct { | ||
| HeldDuration time.Duration | ||
| } | ||
|
|
||
| type ReleaseEndData struct { | ||
| BlockDuration time.Duration | ||
| Err error | ||
| } | ||
flowchartsman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| type tracerSpan struct { | ||
| t Tracer | ||
| start int64 | ||
| } | ||
|
|
||
| func (t tracerSpan) acquireEndErr(ctx context.Context, err error) { | ||
| if t.t == nil { | ||
| return | ||
| } | ||
| t.t.AcquireEnd(ctx, AcquireEndData{ | ||
| AcquireDuration: time.Duration(nanotime() - t.start), | ||
| Err: err, | ||
| }) | ||
| } | ||
|
|
||
| func (t tracerSpan) acquireEnd(ctx context.Context, waitTime time.Duration, stats statFn, isNew bool) { | ||
| if t.t == nil { | ||
| return | ||
| } | ||
| var initDuration time.Duration | ||
| resourceStats := stats() | ||
| if isNew { | ||
| initDuration = time.Since(resourceStats.CreationTime) | ||
| } | ||
| t.t.AcquireEnd(ctx, AcquireEndData{ | ||
| WaitDuration: waitTime, | ||
| AcquireDuration: time.Duration(nanotime() - t.start), | ||
| InitDuration: initDuration, | ||
| ResourceStats: resourceStats, | ||
| }) | ||
| } | ||
|
|
||
| type statFn func() ResourceTraceStats | ||
|
|
||
| // BaseTracer implements [Tracer] methods as no-ops. | ||
| // | ||
| // It is intended to be composed with types that only need to implement a subset | ||
| // of Tracer methods. | ||
| // | ||
| // Example usage: | ||
| // | ||
| // // MyTracer only hooks AcquireEnd | ||
| // type MyTracer struct { | ||
| // pool.BaseTracer | ||
| // } | ||
| // | ||
| // func AcquireEnd(ctx context.Context, d AcquireEndData) { | ||
| // /* do something with d */ | ||
| // } | ||
| type BaseTracer struct{} | ||
|
|
||
| func (BaseTracer) AcquireStart(ctx context.Context, _ AcquireStartData) context.Context { | ||
| return ctx | ||
| } | ||
| func (BaseTracer) AcquireEnd(context.Context, AcquireEndData) {} | ||
| func (BaseTracer) ReleaseStart(ctx context.Context, _ ReleaseStartData) context.Context { | ||
| return ctx | ||
| } | ||
| func (BaseTracer) ReleaseEnd(context.Context, ReleaseEndData) {} | ||
|
|
||
| var _ Tracer = BaseTracer{} | ||
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.