Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node benchmarking utility #6198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions cmd/catchpointdump/bench.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package main

import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/ledger"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
tools "github.com/algorand/go-algorand/tools/network"
)

var reportJsonPath string

Check failure on line 36 in cmd/catchpointdump/bench.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 var-naming: var reportJsonPath should be reportJSONPath (revive) Raw Output: cmd/catchpointdump/bench.go:36:5: var-naming: var reportJsonPath should be reportJSONPath (revive) var reportJsonPath string ^

func init() {
benchCmd.Flags().StringVarP(&networkName, "net", "n", "", "Specify the network name ( i.e. mainnet.algorand.network )")
benchCmd.Flags().IntVarP(&round, "round", "r", 0, "Specify the round number ( i.e. 7700000 )")
benchCmd.Flags().StringVarP(&relayAddress, "relay", "p", "", "Relay address to use ( i.e. r-ru.algorand-mainnet.network:4160 )")
benchCmd.Flags().StringVarP(&catchpointFile, "tar", "t", "", "Specify the catchpoint file (either .tar or .tar.gz) to process")
benchCmd.Flags().StringVarP(&reportJsonPath, "report", "j", "", "Specify the file to save the Json formatted report to")

Check warning on line 43 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L38-L43

Added lines #L38 - L43 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
benchCmd.Flags().StringVarP(&reportJsonPath, "report", "j", "", "Specify the file to save the Json formatted report to")
benchCmd.Flags().StringVarP(&reportJsonPath, "report", "j", "", "Specify the file to save the JSON formatted report to")

}

var benchCmd = &cobra.Command{
Use: "bench",
Short: "Benchmark a catchpoint restore",
Long: "Benchmark a catchpoint restore",
Args: validateNoPosArgsFn,
RunE: func(cmd *cobra.Command, args []string) (err error) {

Check warning on line 51 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L51

Added line #L51 was not covered by tests

// Either source the file locally or require a network name to download
if catchpointFile == "" && networkName == "" {
return fmt.Errorf("provide either catchpoint file or network name")

Check warning on line 55 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L54-L55

Added lines #L54 - L55 were not covered by tests
}
loadOnly = true
benchmark := makeBenchmarkReport()

Check warning on line 58 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L57-L58

Added lines #L57 - L58 were not covered by tests

if catchpointFile == "" {
if round == 0 {
return fmt.Errorf("round not set")

Check warning on line 62 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L60-L62

Added lines #L60 - L62 were not covered by tests
}
stage := benchmark.startStage("network")
catchpointFile, err = downloadCatchpointFromAnyRelay(networkName, round, relayAddress)
if err != nil {
return fmt.Errorf("failed to download catchpoint : %v", err)

Check warning on line 67 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L64-L67

Added lines #L64 - L67 were not covered by tests
}
stage.completeStage()

Check warning on line 69 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L69

Added line #L69 was not covered by tests
}
stats, err := os.Stat(catchpointFile)
if err != nil {
return fmt.Errorf("unable to stat '%s' : %v", catchpointFile, err)

Check warning on line 73 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L71-L73

Added lines #L71 - L73 were not covered by tests
}

catchpointSize := stats.Size()
if catchpointSize == 0 {
return fmt.Errorf("empty file '%s' : %v", catchpointFile, err)

Check warning on line 78 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L76-L78

Added lines #L76 - L78 were not covered by tests
}

genesisInitState := ledgercore.InitState{
Block: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{
UpgradeState: bookkeeping.UpgradeState{
CurrentProtocol: protocol.ConsensusCurrentVersion,
},
}},

Check warning on line 86 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L81-L86

Added lines #L81 - L86 were not covered by tests
}
cfg := config.GetDefaultLocal()
l, err := ledger.OpenLedger(logging.Base(), "./ledger", false, genesisInitState, cfg)
if err != nil {
return fmt.Errorf("unable to open ledger : %v", err)

Check warning on line 91 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L88-L91

Added lines #L88 - L91 were not covered by tests
}

defer os.Remove("./ledger.block.sqlite")
defer os.Remove("./ledger.block.sqlite-shm")
defer os.Remove("./ledger.block.sqlite-wal")
defer os.Remove("./ledger.tracker.sqlite")
defer os.Remove("./ledger.tracker.sqlite-shm")
defer os.Remove("./ledger.tracker.sqlite-wal")
defer l.Close()

Check warning on line 100 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L94-L100

Added lines #L94 - L100 were not covered by tests

catchupAccessor := ledger.MakeCatchpointCatchupAccessor(l, logging.Base())
err = catchupAccessor.ResetStagingBalances(context.Background(), true)
if err != nil {
return fmt.Errorf("unable to initialize catchup database : %v", err)

Check warning on line 105 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L102-L105

Added lines #L102 - L105 were not covered by tests
}

reader, err := os.Open(catchpointFile)
if err != nil {
return fmt.Errorf("unable to read '%s' : %v", catchpointFile, err)

Check warning on line 110 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L108-L110

Added lines #L108 - L110 were not covered by tests
}
defer reader.Close()

Check warning on line 112 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L112

Added line #L112 was not covered by tests

printDigests = false
stage := benchmark.startStage("database")

Check warning on line 115 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L114-L115

Added lines #L114 - L115 were not covered by tests

_, err = loadCatchpointIntoDatabase(context.Background(), catchupAccessor, reader, catchpointSize)
if err != nil {
return fmt.Errorf("unable to load catchpoint file into in-memory database : %v", err)

Check warning on line 119 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L117-L119

Added lines #L117 - L119 were not covered by tests
}
stage.completeStage()

Check warning on line 121 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L121

Added line #L121 was not covered by tests

stage = benchmark.startStage("digest")

Check warning on line 123 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L123

Added line #L123 was not covered by tests

err = buildMerkleTrie(context.Background(), catchupAccessor)
if err != nil {
return fmt.Errorf("unable to build Merkle tree : %v", err)

Check warning on line 127 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L125-L127

Added lines #L125 - L127 were not covered by tests
}
stage.completeStage()

Check warning on line 129 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L129

Added line #L129 was not covered by tests

benchmark.printReport()
if reportJsonPath != "" {
if err := benchmark.saveReport(reportJsonPath); err != nil {
fmt.Printf("error writing report to %s: %v\n", reportJsonPath, err)

Check warning on line 134 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L131-L134

Added lines #L131 - L134 were not covered by tests
}
}

return err

Check warning on line 138 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L138

Added line #L138 was not covered by tests
},
}

func downloadCatchpointFromAnyRelay(network string, round int, relayAddress string) (string, error) {
var addrs []string
if relayAddress != "" {
addrs = []string{relayAddress}
} else {

Check warning on line 146 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L142-L146

Added lines #L142 - L146 were not covered by tests
//append relays
dnsaddrs, err := tools.ReadFromSRV(context.Background(), "algobootstrap", "tcp", networkName, "", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"algobootstrap" probably should not be here since they not obliged to have catchpoints except few most recent ones.

if err != nil || len(dnsaddrs) == 0 {
return "", fmt.Errorf("unable to bootstrap records for '%s' : %v", networkName, err)

Check warning on line 150 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L148-L150

Added lines #L148 - L150 were not covered by tests
}
addrs = append(addrs, dnsaddrs...)

Check warning on line 152 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L152

Added line #L152 was not covered by tests
// append archivers
dnsaddrs, err = tools.ReadFromSRV(context.Background(), "archive", "tcp", networkName, "", false)
if err == nil && len(dnsaddrs) > 0 {
addrs = append(addrs, dnsaddrs...)

Check warning on line 156 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L154-L156

Added lines #L154 - L156 were not covered by tests
}
}

for _, addr := range addrs {
tarName, err := downloadCatchpoint(addr, round)
if err != nil {
reportInfof("failed to download catchpoint from '%s' : %v", addr, err)
continue

Check warning on line 164 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L160-L164

Added lines #L160 - L164 were not covered by tests
}
return tarName, nil

Check warning on line 166 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L166

Added line #L166 was not covered by tests
}
return "", fmt.Errorf("catchpoint for round %d on network %s could not be downloaded from any relay", round, network)

Check warning on line 168 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L168

Added line #L168 was not covered by tests
}

func buildMerkleTrie(ctx context.Context, catchupAccessor ledger.CatchpointCatchupAccessor) (err error) {
err = catchupAccessor.BuildMerkleTrie(ctx, func(uint64, uint64) {})
if err != nil {
return err

Check warning on line 174 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L171-L174

Added lines #L171 - L174 were not covered by tests
}
fmt.Printf("\n Building Merkle Trie, this will take a few minutes...")
var balanceHash, spverHash crypto.Digest
balanceHash, spverHash, _, err = catchupAccessor.GetVerifyData(ctx)
if err != nil {
return err

Check warning on line 180 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L176-L180

Added lines #L176 - L180 were not covered by tests
}
fmt.Printf("done. \naccounts digest=%s, spver digest=%s\n\n", balanceHash, spverHash)
return nil

Check warning on line 183 in cmd/catchpointdump/bench.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench.go#L182-L183

Added lines #L182 - L183 were not covered by tests
}
146 changes: 146 additions & 0 deletions cmd/catchpointdump/bench_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package main

import (
"crypto/sha256"
"encoding/json"
"fmt"
"os"
"runtime"
"syscall"
"time"

"github.com/google/uuid"
. "github.com/klauspost/cpuid/v2"

Check failure on line 13 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 dot-imports: should not use dot imports (revive) Raw Output: cmd/catchpointdump/bench_report.go:13:2: dot-imports: should not use dot imports (revive) . "github.com/klauspost/cpuid/v2" ^
)

type benchStage struct {
stage string
start time.Time
duration time.Duration
cpuTimeNS int64
completed bool
}

type hostInfo struct {
CpuCoreCnt int `json:"cores"`

Check failure on line 25 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 var-naming: struct field CpuCoreCnt should be CPUCoreCnt (revive) Raw Output: cmd/catchpointdump/bench_report.go:25:2: var-naming: struct field CpuCoreCnt should be CPUCoreCnt (revive) CpuCoreCnt int `json:"cores"` ^
CpuLogicalCnt int `json:"log_cores"`

Check failure on line 26 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 var-naming: struct field CpuLogicalCnt should be CPULogicalCnt (revive) Raw Output: cmd/catchpointdump/bench_report.go:26:2: var-naming: struct field CpuLogicalCnt should be CPULogicalCnt (revive) CpuLogicalCnt int `json:"log_cores"` ^
CpuBaseMHz int64 `json:"base_mhz"`

Check failure on line 27 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 var-naming: struct field CpuBaseMHz should be CPUBaseMHz (revive) Raw Output: cmd/catchpointdump/bench_report.go:27:2: var-naming: struct field CpuBaseMHz should be CPUBaseMHz (revive) CpuBaseMHz int64 `json:"base_mhz"` ^
CpuMaxMHz int64 `json:"max_mhz"`
CpuName string `json:"cpu_name"`
CpuVendor string `json:"cpu_vendor"`
MemMB int `json:"mem_mb"`
OS string `json:"os"`
ID uuid.UUID `json:"uuid"`
}

type benchReport struct {
ReportID uuid.UUID `json:"report"`
Stages []*benchStage `json:"stages"`
HostInfo *hostInfo `json:"host"`
// TODO: query cpu cores, bogomips and stuff (windows/mac compatible)
}

func (s *benchStage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Stage string `json:"stage"`
Duration int64 `json:"duration_sec"`
CpuTime int64 `json:"cpu_time_sec"`
}{
Stage: s.stage,
Duration: int64(s.duration.Seconds()),
CpuTime: s.cpuTimeNS / 1000000000,
})

Check warning on line 52 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L43-L52

Added lines #L43 - L52 were not covered by tests
}

func (bs *benchStage) String() string {

Check failure on line 55 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 receiver-naming: receiver name bs should be consistent with previous receiver name s for benchStage (revive) Raw Output: cmd/catchpointdump/bench_report.go:55:1: receiver-naming: receiver name bs should be consistent with previous receiver name s for benchStage (revive) func (bs *benchStage) String() string { return fmt.Sprintf(">> stage:%s duration_sec:%.1f duration_min:%.1f cpu_sec:%d", bs.stage, bs.duration.Seconds(), bs.duration.Minutes(), bs.cpuTimeNS/1000000000) }
return fmt.Sprintf(">> stage:%s duration_sec:%.1f duration_min:%.1f cpu_sec:%d", bs.stage, bs.duration.Seconds(), bs.duration.Minutes(), bs.cpuTimeNS/1000000000)

Check warning on line 56 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L55-L56

Added lines #L55 - L56 were not covered by tests
}

func maybeGetTotalMemory() uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving to util/util.go

switch runtime.GOOS {
case "linux":

Check warning on line 61 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L59-L61

Added lines #L59 - L61 were not covered by tests
// Use sysinfo on Linux
var si syscall.Sysinfo_t

Check failure on line 63 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

undefined: syscall.Sysinfo_t
err := syscall.Sysinfo(&si)

Check failure on line 64 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

undefined: syscall.Sysinfo
if err != nil {
return 0

Check warning on line 66 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L63-L66

Added lines #L63 - L66 were not covered by tests
}
return si.Totalram
default:
return 0

Check warning on line 70 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L68-L70

Added lines #L68 - L70 were not covered by tests
}
}

func gatherHostInfo() *hostInfo {
nid := sha256.Sum256(uuid.NodeID())
uuid, _ := uuid.FromBytes(nid[0:16])

Check warning on line 76 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L74-L76

Added lines #L74 - L76 were not covered by tests

ni := &hostInfo{
CpuCoreCnt: CPU.PhysicalCores,
CpuLogicalCnt: CPU.LogicalCores,
CpuName: CPU.BrandName,
CpuVendor: CPU.VendorID.String(),
CpuMaxMHz: CPU.BoostFreq / 1_000_000,
CpuBaseMHz: CPU.Hz / 1_000_000,
MemMB: int(maybeGetTotalMemory()) / 1024 / 1024,
ID: uuid,
OS: runtime.GOOS,

Check warning on line 87 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L78-L87

Added lines #L78 - L87 were not covered by tests
}

return ni

Check warning on line 90 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L90

Added line #L90 was not covered by tests
}

func makeBenchmarkReport() *benchReport {
uuid, _ := uuid.NewV7()
return &benchReport{
Stages: make([]*benchStage, 0),
HostInfo: gatherHostInfo(),
ReportID: uuid,

Check warning on line 98 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L93-L98

Added lines #L93 - L98 were not covered by tests
}
}

func GetCPU() int64 {

Check failure on line 102 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 exported: exported function GetCPU should have comment or be unexported (revive) Raw Output: cmd/catchpointdump/bench_report.go:102:1: exported: exported function GetCPU should have comment or be unexported (revive) func GetCPU() int64 { ^
usage := new(syscall.Rusage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, move to util

syscall.Getrusage(syscall.RUSAGE_SELF, usage)

Check failure on line 104 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 Error return value of `syscall.Getrusage` is not checked (errcheck) Raw Output: cmd/catchpointdump/bench_report.go:104:19: Error return value of `syscall.Getrusage` is not checked (errcheck) syscall.Getrusage(syscall.RUSAGE_SELF, usage) ^

Check failure on line 104 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

undefined: syscall.Getrusage

Check failure on line 104 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

undefined: syscall.RUSAGE_SELF
return usage.Utime.Nano() + usage.Stime.Nano()

Check warning on line 105 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L102-L105

Added lines #L102 - L105 were not covered by tests

Check failure on line 105 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

usage.Utime undefined (type *syscall.Rusage has no field or method Utime)

Check failure on line 105 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / build-windows

usage.Stime undefined (type *syscall.Rusage has no field or method Stime)
}

func (br *benchReport) startStage(stage string) *benchStage {
bs := &benchStage{
stage: stage,
start: time.Now(),
duration: 0,
cpuTimeNS: GetCPU(),
completed: false,

Check warning on line 114 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L108-L114

Added lines #L108 - L114 were not covered by tests
}
br.Stages = append(br.Stages, bs)
return bs

Check warning on line 117 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L116-L117

Added lines #L116 - L117 were not covered by tests
}

func (bs *benchStage) completeStage() {

Check failure on line 120 in cmd/catchpointdump/bench_report.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 receiver-naming: receiver name bs should be consistent with previous receiver name s for benchStage (revive) Raw Output: cmd/catchpointdump/bench_report.go:120:1: receiver-naming: receiver name bs should be consistent with previous receiver name s for benchStage (revive) func (bs *benchStage) completeStage() { bs.duration = time.Since(bs.start) bs.completed = true bs.cpuTimeNS = GetCPU() - bs.cpuTimeNS }
bs.duration = time.Since(bs.start)
bs.completed = true
bs.cpuTimeNS = GetCPU() - bs.cpuTimeNS

Check warning on line 123 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L120-L123

Added lines #L120 - L123 were not covered by tests
}

func (br *benchReport) printReport() {
fmt.Print("\nBenchmark report:\n")
for i := range br.Stages {
fmt.Println(br.Stages[i].String())

Check warning on line 129 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L126-L129

Added lines #L126 - L129 were not covered by tests
}
}

func (br *benchReport) saveReport(filename string) error {
jsonData, err := json.MarshalIndent(br, "", " ")
if err != nil {
return err

Check warning on line 136 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L133-L136

Added lines #L133 - L136 were not covered by tests
}

// Write to file with permissions set to 0644
err = os.WriteFile(filename, jsonData, 0644)
if err != nil {
return err

Check warning on line 142 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L140-L142

Added lines #L140 - L142 were not covered by tests
}

return nil

Check warning on line 145 in cmd/catchpointdump/bench_report.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/bench_report.go#L145

Added line #L145 was not covered by tests
}
1 change: 1 addition & 0 deletions cmd/catchpointdump/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
func init() {
rootCmd.AddCommand(fileCmd)
rootCmd.AddCommand(netCmd)
rootCmd.AddCommand(benchCmd)

Check warning on line 46 in cmd/catchpointdump/commands.go

View check run for this annotation

Codecov / codecov/patch

cmd/catchpointdump/commands.go#L46

Added line #L46 was not covered by tests
rootCmd.AddCommand(databaseCmd)
}

Expand Down
Loading