MCPcopy Index your code
hub / github.com/github/github-mcp-server / ProfileFunc

Method ProfileFunc

internal/profiler/profiler.go:73–101  ·  view source on GitHub ↗

ProfileFunc profiles a function execution

(ctx context.Context, operation string, fn func() error)

Source from the content-addressed store, hash-verified

71
72// ProfileFunc profiles a function execution
73func (p *Profiler) ProfileFunc(ctx context.Context, operation string, fn func() error) (*Profile, error) {
74 if !p.enabled {
75 return nil, fn()
76 }
77
78 profile := &Profile{
79 Operation: operation,
80 Timestamp: time.Now(),
81 }
82
83 var memBefore runtime.MemStats
84 runtime.ReadMemStats(&memBefore)
85 profile.MemoryBefore = memBefore.Alloc
86
87 start := time.Now()
88 err := fn()
89 profile.Duration = time.Since(start)
90
91 var memAfter runtime.MemStats
92 runtime.ReadMemStats(&memAfter)
93 profile.MemoryAfter = memAfter.Alloc
94 profile.MemoryDelta = safeMemoryDelta(memAfter.Alloc, memBefore.Alloc)
95
96 if p.logger != nil {
97 p.logger.InfoContext(ctx, "Performance profile", "profile", profile.String())
98 }
99
100 return profile, err
101}
102
103// ProfileFuncWithMetrics profiles a function execution and captures additional metrics
104func (p *Profiler) ProfileFuncWithMetrics(ctx context.Context, operation string, fn func() (int, int64, error)) (*Profile, error) {

Callers 1

ProfileFuncFunction · 0.80

Calls 2

StringMethod · 0.95
safeMemoryDeltaFunction · 0.85

Tested by

no test coverage detected