Skip to content

Commit 6d2b84b

Browse files
Leo Weesegitbook-bot
authored andcommitted
GITBOOK-457: change request with no subject merged in GitBook
1 parent 49b4fa2 commit 6d2b84b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

lightning-network-tools/lnd/debugging_lnd.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Subsystems:
7373

7474
`lnd` has a built-in feature which allows you to capture profiling data at runtime using [pprof](https://golang.org/pkg/runtime/pprof/), a profiler for Go. The profiler has negligible performance overhead during normal operations (unless you have explicitly enabled CPU profiling).
7575

76-
To enable this ability, start `lnd` with the `--profile` option using a free port.
76+
To enable this ability, start `lnd` with the `--profile` option using a free port or add `profile=9736` to your `lnd.conf`.
7777

7878
```
7979
⛰ lnd --profile=9736
@@ -85,3 +85,37 @@ Now, with `lnd` running, you can use the pprof endpoint on port 9736 to collect
8585
⛰ curl http://localhost:9736/debug/pprof/goroutine?debug=1
8686
...
8787
```
88+
89+
#### CPU Profile
90+
91+
A CPU profile can be used to analyze LND's CPU usage. You can specify the time duration as a query parameter.
92+
93+
```
94+
⛰ curl http://localhost:9736/debug/pprof/profile?seconds=10 > cpu.prof
95+
```
96+
97+
#### **Goroutine profile**
98+
99+
The goroutine profile is very useful when analyzing deadlocks and lock contention.
100+
101+
```
102+
⛰ curl http://localhost:9736/debug/pprof/goroutine?debug=2 > goroutine.prof
103+
```
104+
105+
#### **Heap profile**
106+
107+
The heap profile is useful to analyze memory allocations.
108+
109+
```
110+
⛰ curl http://localhost:9736/debug/pprof/heap > heap.prof
111+
```
112+
113+
#### **Visualizing the profile dumps**
114+
115+
It can be hard to make sense of the profile dumps by just looking at them. The Golang ecosystem provides tools to analyze those profile dumps either via the terminal or by visualizing them. One of the tools is `go tool pprof`.
116+
117+
Assuming the profile was fetched via `curl` as in the examples above a nice svg visualization can be generated for the cpu profile like this:
118+
119+
```
120+
⛰ go tool pprof -svg cpu.prof > cpu.svg
121+
```

0 commit comments

Comments
 (0)