@@ -465,6 +465,32 @@ func getBenchmarkSourceFile(name string) string {
465465 return "perf-tracking/benchmarks/core/allocation_test.go"
466466}
467467
468+ // exportVersionWithCPU exports a single version's benchmarks to JSON, applying
469+ // cpuFallback when the benchmark file lacks a cpu: line.
470+ func exportVersionWithCPU (inputFile , version , outputFile , cpuFallback string ) error {
471+ versionData , err := parseBenchmarkFile (inputFile , version )
472+ if err != nil {
473+ return fmt .Errorf ("failed to parse benchmark file: %w" , err )
474+ }
475+ if versionData .Metadata .System .CPU == "" && cpuFallback != "" {
476+ versionData .Metadata .System .CPU = cpuFallback
477+ }
478+
479+ jsonData , err := json .MarshalIndent (versionData , "" , " " )
480+ if err != nil {
481+ return fmt .Errorf ("failed to marshal JSON: %w" , err )
482+ }
483+ if err := os .MkdirAll (filepath .Dir (outputFile ), 0755 ); err != nil {
484+ return fmt .Errorf ("failed to create output directory: %w" , err )
485+ }
486+ if err := os .WriteFile (outputFile , jsonData , 0644 ); err != nil {
487+ return fmt .Errorf ("failed to write output file: %w" , err )
488+ }
489+ fmt .Printf (" Output: %s\n " , outputFile )
490+ fmt .Printf (" ✓ Exported %d benchmarks\n \n " , len (versionData .Benchmarks ))
491+ return nil
492+ }
493+
468494// exportVersion exports a single version's benchmarks to JSON
469495func exportVersion (inputFile , version , outputFile string ) error {
470496 fmt .Printf ("Exporting Go %s...\n " , version )
@@ -580,7 +606,8 @@ func getReliability(maxCV float64) string {
580606// This makes every export additive: pre-existing version files are never dropped.
581607// defaultPlatform is used when the platform cannot be auto-detected from the
582608// benchmark files (e.g. files lack OS/arch metadata).
583- func exportAll (resultsDir , outputDir , defaultPlatform string ) error {
609+ // cpuOverride is used as a fallback when benchmark files lack a cpu: line.
610+ func exportAll (resultsDir , outputDir , defaultPlatform , cpuOverride string ) error {
584611 fmt .Println ("=== Exporting All Versions ===" )
585612
586613 entries , err := os .ReadDir (resultsDir )
@@ -683,7 +710,7 @@ func exportAll(resultsDir, outputDir, defaultPlatform string) error {
683710 platformDir := filepath .Join (outputDir , platform )
684711 outputFile := filepath .Join (platformDir , fmt .Sprintf ("go%s.json" , version ))
685712
686- if err := exportVersion (latestFile , version , outputFile ); err != nil {
713+ if err := exportVersionWithCPU (latestFile , version , outputFile , cpuOverride ); err != nil {
687714 fmt .Printf (" Error: %v\n " , err )
688715 continue
689716 }
0 commit comments