Skip to content

Commit 3fa2ec7

Browse files
cdeckerrustyrussell
authored andcommitted
test: Add a run-trace test and document tracing overhead
1 parent 7ce0942 commit 3fa2ec7

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

common/test/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,10 @@ common/test/run-version: \
105105
wire/towire.o
106106

107107

108+
common/test/run-trace: \
109+
common/amount.o \
110+
common/memleak.o \
111+
common/trace.o \
112+
wire/fromwire.o \
113+
wire/towire.o
108114
check-units: $(COMMON_TEST_PROGRAMS:%=unittest/%)

common/test/run-trace.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "config.h"
2+
#include <common/setup.h>
3+
#include <common/trace.h>
4+
5+
/* This is mostly a benchmark to see how much overhead the tracing
6+
* introduces. */
7+
8+
int main(int argx, char *argv[])
9+
{
10+
/* Just some context objects to hang spans off of. */
11+
int a, b, c, d;
12+
13+
common_setup(argv[0]);
14+
15+
/* Create a bunch of nested spans to emit. */
16+
for(int i=0; i<25000; i++) {
17+
trace_span_start("a", &a);
18+
trace_span_start("b", &b);
19+
20+
trace_span_start("c", &c);
21+
trace_span_end(&c);
22+
23+
trace_span_end(&b);
24+
25+
trace_span_start("d", &d);
26+
trace_span_end(&d);
27+
28+
trace_span_end(&a);
29+
}
30+
trace_cleanup();
31+
common_shutdown();
32+
}

doc/developers-guide/tracing-cln-performance.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,36 @@ Attaching 1 probe...
8181
8282
8383
Notice that due to a [limitation](https://github.com/iovisor/bpftrace/issues/305) in `bpftrace` you'll at most get the first 200 bytes of the payload. If you write your own exporter you'll be able to specify the size of the buffer that is being used, and can extract the entire span.
84+
85+
## Tracing Overhead
86+
87+
While we try to make tracing as lightweight as possible it isn't
88+
free. To quantify how much time is spent actually maintaining the
89+
tracing context we built a small test in `common/test/run-trace` which
90+
creates a sequence of 25'000 traces, with a total of 1'000'000 spans,
91+
without any additional operations.
92+
93+
The following run with [hyperfine][hf] shows the runtime for that test
94+
without an exporter attached:
95+
96+
97+
```bash
98+
99+
$ hyperfine common/test/run-trace
100+
Benchmark 1: common/test/run-trace
101+
Time (mean ± σ): 368.4 ms ± 4.8 ms [User: 142.7 ms, System: 225.1 ms]
102+
Range (min … max): 358.3 ms … 377.2 ms 10 runs
103+
```
104+
105+
While the following is the same run, but with an exporter attached:
106+
107+
```bash
108+
$ ❯ hyperfine common/test/run-trace
109+
Benchmark 1: common/test/run-trace
110+
Time (mean ± σ): 561.5 ms ± 14.1 ms [User: 164.5 ms, System: 396.5 ms]
111+
Range (min … max): 546.5 ms … 598.9 ms 10 runs
112+
```
113+
114+
So depending on whether an exporter is attached, creating and emitting
115+
span without and with an exporter takes around 370ns and 560ns
116+
respectively.

0 commit comments

Comments
 (0)