Skip to content

Commit 28f4f54

Browse files
committed
chore(pprof): write docs
1 parent 519daef commit 28f4f54

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

provider/pprof/README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# [pprof](https://github.com/google/pprof) context provider for OpenCtx
22

3-
This is a context provider for [OpenCtx](https://openctx.org) that annotates functions with the CPU time and memory allocations attributed to them.
3+
[OpenCtx](https://openctx.org) provider that annotates Go functions with their associated CPU time and memory allocations based on the CPU/memory profiles.
4+
5+
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.
6+
7+
When enabled, pprof provider will:
8+
9+
1. Search the workspace to find a profiling report and, optionally, a Go binary that produced it.
10+
1. Get `pprof -top` nodes for the current package.
11+
1. Create an annotation for each function/method in the current file denoting its resourse consumption.
12+
1. Pass a detailed `pprof -list` breakdown to `annotation.item.ai` to be consumed by Cody.
413

514
## Usage
615

7-
Add the following to your settings in any OpenCtx client:
16+
Add the following to your `settings.json`:
817

918
```json
1019
"openctx.providers": {
@@ -13,12 +22,48 @@ Add the following to your settings in any OpenCtx client:
1322
},
1423
```
1524

25+
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.
26+
27+
Most of the time, however, you'll want to adjust the config to suit your preferences.
28+
1629
## Configuration
1730

18-
> TODO
31+
The default configuration looks like this:
32+
33+
```json
34+
{
35+
"reportGlob": "**/*.pprof",
36+
"binaryGlob": undefined, // By default, looks for a binary whose name matches the name of its parent directory
37+
"rootDirectoryMarkers": ["go.mod", ".git"],
38+
"top": { // Options to control `pprof -top` output
39+
"excludeInline": true, // Add `-noinlines`
40+
"nodeCount": undefined, // Add `-nodecount=x`, not set by default
41+
"sort": "cum" // Set `-cum` or `-flat`
42+
}
43+
}
44+
```
45+
46+
## Limitations
47+
48+
`pprof` can collect stack traces for a number of [different profiles](https://pkg.go.dev/runtime/pprof#Profile):
49+
50+
```
51+
goroutine - stack traces of all current goroutines
52+
heap - a sampling of memory allocations of live objects
53+
allocs - a sampling of all past memory allocations
54+
threadcreate - stack traces that led to the creation of new OS threads
55+
block - stack traces that led to blocking on synchronization primitives
56+
mutex - stack traces of holders of contended mutexes
57+
```
58+
59+
This provider only supports `heap` and CPU profile[^1].
1960

2061
## Development
2162

2263
- [Source code](https://sourcegraph.com/github.com/sourcegraph/openctx/-/tree/provider/pprof)
2364
- [Docs](https://openctx.org/docs/providers/pprof)
2465
- License: Apache 2.0
66+
67+
____
68+
69+
[^1]: The CPU profile is not available as a `runtime/pprof.Profile` and has a special API.

0 commit comments

Comments
 (0)