...

Text file src/edge-infra.dev/hack/scripts/bench.sh

Documentation: edge-infra.dev/hack/scripts

     1#!/usr/bin/env bash
     2
     3set -e
     4
     5test_target=$1
     6if [[ -z "${test_target}" ]]; then
     7    echo "error: must provide a single go_test target as an argument, e.g. //path/to/my/test:my_test"
     8    exit
     9fi
    10
    11bazel query "kind(test, ${test_target})"
    12
    13name=$(echo "${test_target}" | cut -d':' -f2)
    14echo "${name}"
    15
    16bazel run "${test_target}" -- -test.run="Benchmark.*" -test.bench=. -test.cpuprofile="${name}.cpuprofile.out" -test.blockprofile="${name}.blockprofile.out" -test.benchtime=1x
    17
    18# Choose which profile to open
    19# Available profiles are listed in https://go.dev/doc/diagnostics
    20# Also see: go help testflag
    21
    22# profile=cpuprofile
    23profile=blockprofile
    24
    25bin=$(bazel info bazel-bin)
    26package=$(bazel query "${test_target}" --output package)
    27prof_file="${bin}/${package}/${name}_/${name}.runfiles/edge_infra/${package}/${name}.${profile}.out"
    28echo "opening pprof file ${prof_file}"
    29bazel run @io_bazel_rules_go//go -- tool pprof -http :8080 "${prof_file}"

View as plain text