Skip to content

Commit 98a5297

Browse files
committed
feat: add instrumentation to extract round times
1 parent 0853dbd commit 98a5297

File tree

1 file changed

+0
-79
lines changed

1 file changed

+0
-79
lines changed

testing/testing/benchmark.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ package testing
66

77
import (
88
"context"
9-
"crypto/rand"
10-
"encoding/hex"
11-
"encoding/json"
129
"flag"
1310
"fmt"
1411
"io"
1512
"math"
1613
"os"
17-
"path/filepath"
1814
"runtime"
1915
"slices"
2016
"strconv"
@@ -469,8 +465,6 @@ func (b *B) loopSlowPath() bool {
469465
if b.loop.n < uint64(b.benchTime.n) {
470466
b.loop.n = uint64(b.benchTime.n)
471467
b.loop.i++
472-
b.ResetTimer()
473-
b.StartTimer()
474468
return true
475469
}
476470
b.StopTimer()
@@ -793,79 +787,6 @@ func (s *benchState) processBench(b *B) {
793787
continue
794788
}
795789
results := r.String()
796-
797-
// ############################################################################################
798-
// START CODSPEED
799-
type RawResults struct {
800-
BenchmarkName string `json:"benchmark_name"`
801-
Pid int `json:"pid"`
802-
CodspeedTimePerRoundNs []time.Duration `json:"codspeed_time_per_round_ns"`
803-
CodspeedItersPerRound []int64 `json:"codspeed_iters_per_round"`
804-
}
805-
806-
// Build custom bench name with :: separator
807-
var nameParts []string
808-
current := &b.common
809-
for current.parent != nil {
810-
// Extract the sub-benchmark part by removing parent prefix
811-
parentName := current.parent.name
812-
if strings.HasPrefix(current.name, parentName+"/") {
813-
subName := strings.TrimPrefix(current.name, parentName+"/")
814-
nameParts = append([]string{subName}, nameParts...)
815-
} else {
816-
nameParts = append([]string{current.name}, nameParts...)
817-
}
818-
819-
if current.parent.name == "Main" {
820-
break
821-
}
822-
current = current.parent
823-
}
824-
customBenchName := strings.Join(nameParts, "::")
825-
826-
rawResults := RawResults{
827-
BenchmarkName: customBenchName,
828-
Pid: os.Getpid(),
829-
CodspeedTimePerRoundNs: r.CodspeedTimePerRoundNs,
830-
CodspeedItersPerRound: r.CodspeedItersPerRound,
831-
}
832-
833-
codspeedProfileFolder := os.Getenv("CODSPEED_PROFILE_FOLDER")
834-
if codspeedProfileFolder == "" {
835-
panic("CODSPEED_PROFILE_FOLDER environment variable is not set")
836-
}
837-
if err := os.MkdirAll(filepath.Join(codspeedProfileFolder, "raw_results"), 0755); err != nil {
838-
fmt.Fprintf(os.Stderr, "failed to create raw results directory: %v\n", err)
839-
continue
840-
}
841-
// Generate random filename to avoid any overwrites
842-
randomBytes := make([]byte, 16)
843-
if _, err := rand.Read(randomBytes); err != nil {
844-
fmt.Fprintf(os.Stderr, "failed to generate random filename: %v\n", err)
845-
continue
846-
}
847-
rawResultsFile := filepath.Join(codspeedProfileFolder, "raw_results", fmt.Sprintf("%s.json", hex.EncodeToString(randomBytes)))
848-
file, err := os.Create(rawResultsFile)
849-
if err != nil {
850-
fmt.Fprintf(os.Stderr, "failed to create raw results file: %v\n", err)
851-
continue
852-
}
853-
output, err := json.MarshalIndent(rawResults, "", " ")
854-
if err != nil {
855-
fmt.Fprintf(os.Stderr, "failed to marshal raw results: %v\n", err)
856-
file.Close()
857-
continue
858-
}
859-
// FIXME: Don't overwrite the file if it already exists
860-
if _, err := file.Write(output); err != nil {
861-
fmt.Fprintf(os.Stderr, "failed to write raw results: %v\n", err)
862-
file.Close()
863-
continue
864-
}
865-
defer file.Close()
866-
// END CODSPEED
867-
// ############################################################################################
868-
869790
if b.chatty != nil {
870791
fmt.Fprintf(b.w, "%-*s\t", s.maxLen, benchName)
871792
}

0 commit comments

Comments
 (0)