Skip to content

Commit

Permalink
Amend protobench for renamed CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot committed Aug 19, 2024
1 parent 2c5f92b commit 36ecf78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
6 changes: 3 additions & 3 deletions tools/protobench/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
The idea is to record the wire messages of the profiling agent and see how well they compress using different
compressors and what the CPU impact is.

To record the wire messages, you need to run the profiling agent with the `-bench-proto-dir` flag.
To record the wire messages, you need to run the profiling agent with the `-reporter-save-outputs-to` flag.
This will write the wire messages into the given directory. The directory will be created if it does not exist.

You can then use the `protobench` tool to compress the wire messages and see how well they compress and how much
CPU time it takes to compress them.

To run the profiling agent, first have a receiving endpoint, e.g. `devfiler` listening on localhost:11000.
Then run the profiling agent with the `-bench-proto-dir` flag:
Then run the profiling agent with the `-reporter-save-outputs-to` flag:
```shell
sudo ./opentelemetry-ebpf-profiler -bench-proto-dir=/tmp/protobuf -collection-agent=127.0.0.1:11000 -disable-tls
sudo ./opentelemetry-ebpf-profiler -reporter-save-outputs-to=/tmp/protobuf -collection-agent=127.0.0.1:11000 -disable-tls
```
The wire messages are written to `protobuf/`, one file per message.

Expand Down
21 changes: 9 additions & 12 deletions tools/protobench/cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ import (
)

const (
defaultArgBenchProtoDir = ""
defaultArgOutputFile = ""
defaultArgInputDir = ""
defaultArgOutputFile = ""
)

// Help strings for command line arguments
var (
benchProtoDirHelp = "Directory to store raw protobuf wire messages."
outputFileHelp = "Output file to store the benchmark results (*.csv or *.png)."
inputDirHelp = "Directory to read and compress files from."
outputFileHelp = "Output file to store the benchmark results (*.csv or *.png)."
)

type arguments struct {
benchProtoDir string
outputFile string
inputDir string
outputFile string

fs *flag.FlagSet
}

func (args *arguments) SanityCheck() error {
if args.benchProtoDir == "" {
if args.inputDir == "" {
return errors.New("no protobuf message directory specified")
}

Expand All @@ -57,11 +57,8 @@ func parseArgs() (*arguments, error) {

fs := flag.NewFlagSet("protobench", flag.ExitOnError)

fs.StringVar(&args.benchProtoDir, "bench-proto-dir", defaultArgBenchProtoDir,
benchProtoDirHelp)

fs.StringVar(&args.outputFile, "output-file", defaultArgOutputFile,
outputFileHelp)
fs.StringVar(&args.inputDir, "input-dir", defaultArgInputDir, inputDirHelp)
fs.StringVar(&args.outputFile, "output-file", defaultArgOutputFile, outputFileHelp)

fs.Usage = func() {
fs.PrintDefaults()
Expand Down
12 changes: 6 additions & 6 deletions tools/protobench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func mainWithError() error {
return err
}

summary, err := benchmark(args.benchProtoDir)
summary, err := benchmark(args.inputDir)
if err != nil {
return fmt.Errorf("benchmark failed: %v", err)
}
Expand All @@ -54,11 +54,11 @@ func mainWithError() error {
return nil
}

func benchmark(benchProtoDir string) (*benchSummary, error) {
func benchmark(inputDir string) (*benchSummary, error) {
// scan directory for files
files, err := os.ReadDir(benchProtoDir)
files, err := os.ReadDir(inputDir)
if err != nil {
return nil, fmt.Errorf("failed to read directory %s: %v", benchProtoDir, err)
return nil, fmt.Errorf("failed to read directory %s: %v", inputDir, err)
}

summary := &benchSummary{
Expand All @@ -73,14 +73,14 @@ func benchmark(benchProtoDir string) (*benchSummary, error) {
var buf = bytes.NewBuffer(make([]byte, 0, maxSize))

// Warm-up
_, _ = compressFiles(noneCompressor{name: "none"}, files, benchProtoDir, buf)
_, _ = compressFiles(noneCompressor{name: "none"}, files, inputDir, buf)

baseUsage := int64(0)
for _, c := range compressors {
var compressed int64

cpuUsage := getCPUUsage(func() {
compressed, err = compressFiles(c, files, benchProtoDir, buf)
compressed, err = compressFiles(c, files, inputDir, buf)
})

if err != nil {
Expand Down

0 comments on commit 36ecf78

Please sign in to comment.