pprof context provider for OpenCtx
OpenCtx provider that annotates Go functions with their associated CPU time and memory allocations based on the CPU/memory profiles.
As profiling reports are usually not stored in a centralized remote location (like, e.g. docs or logs) and only exist on your machine, this provider only supports local VSCode client. It also does not provide annotations for test files.
When enabled, pprof provider will:
- Search the workspace to find a profiling report and, optionally, a Go binary that produced it.
- Get
pprof -top
nodes for the current package. - Create an annotation for each function/method in the current file denoting its resourse consumption.
- Pass a detailed
pprof -list
breakdown toannotation.item.ai
to be consumed by Cody.
Add the following to your settings.json
:
"openctx.providers": {
// ...other providers...
"https://npmjs.com/package/@bevzzz/provider-pprof": true
},
Pprof provider has reasonable defaults, so no additional configuration in necessary if you follow the standard naming conventions for pprof reports and Go binaries, e.g. that a cpu profile report has .pprof
extension.
Most of the time, however, you'll want to adjust the config to suit your preferences.
The default configuration looks like this:
{
"reportGlob": "**/*.pprof",
"binaryGlob": undefined, // By default, looks for a binary whose name matches the name of its parent directory
"rootDirectoryMarkers": ["go.mod", ".git"],
"top": { // Options to control `pprof -top` output
"excludeInline": true, // Add `-noinlines`
"nodeCount": undefined, // Add `-nodecount=x`, not set by default
"sort": "cum" // Set `-cum` or `-flat`
}
}
pprof
can collect stack traces for a number of different profiles:
goroutine - stack traces of all current goroutines
heap - a sampling of memory allocations of live objects
allocs - a sampling of all past memory allocations
threadcreate - stack traces that led to the creation of new OS threads
block - stack traces that led to blocking on synchronization primitives
mutex - stack traces of holders of contended mutexes
This provider only supports heap
and CPU profile1.
Footnotes
-
The CPU profile is not available as
runtime/pprof.Profile
and has a special API. ↩