Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit cf3ae79

Browse files
authored
Add documentation for benchmarks and profiling. (#42)
1 parent 4b9efcc commit cf3ae79

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

opencensus/doc/benchmarks.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Benchmarks
2+
3+
## Running
4+
5+
Benchmarks are implemented as binary rules in bazel, and can be either built and
6+
then run from the binary location in `bazel-bin` or run with `bazel run`, e.g.
7+
```shell
8+
bazel run -c opt opencensus/stats:stats_manager_benchmark [-- BENCHMARK_FLAGS]
9+
```
10+
Benchmarks use the [Google benchmark](https://github.com/google/benchmark)
11+
library. This accepts several helpful flags, including
12+
- --benchmark_filter=REGEX: Run only benchmarks whose names match REGEX.
13+
- --benchmark_repetitions=N: Repeat each benchmark and calculate
14+
mean/median/stddev.
15+
- --benchmark_report_aggregates_only={true|false}: In conjunction with
16+
benchmark_repetitions, report only summary statistics and not single-run
17+
timings.
18+
19+
## Profiling
20+
21+
Benchmarks can be profiled using the
22+
[gperftools](https://github.com/gperftools/gperftools) library. On
23+
Debian/Ubuntu, install the `google-perftools` (profile analysis tools) and
24+
`libgoogle-perftools-dev` (profiling library) packages. When running the
25+
benchmark, set `LD_PRELOAD=/usr/lib/libprofiler.so` to enable the profiler and
26+
`CPUPROFILE=PATH` to save a profile, and analyze the profile with
27+
`google-pprof` (which needs a path to the binary for symbolization). For
28+
example,
29+
```shell
30+
bazel build -c opt opencensus/stats:stats_manager_benchmark
31+
LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=/tmp/prof \
32+
./bazel-bin/opencensus/stats/stats_manager_benchmark
33+
google-pprof --web bazel-bin/opencensus/stats/stats_manager_benchmark /tmp/prof
34+
```
35+
pprof supports many analysis types--see its documentation for options.

0 commit comments

Comments
 (0)