@@ -14,6 +14,7 @@ import (
1414 "os"
1515 "path/filepath"
1616 "regexp"
17+ "strconv"
1718 "strings"
1819 "time"
1920
@@ -436,6 +437,11 @@ func exportSysbenchResults(
436437 }
437438 labelString := roachtestutil .GetOpenmetricsLabelString (t , c , labels )
438439 openmetricsMap := make (map [string ][]openmetricsValues )
440+
441+ // Counters for aggregated metrics
442+ var totalQpsSum , readQpsSum , writeQpsSum , otherQpsSum float64
443+ var sampleCount int64
444+
439445 tick := func (fields []string , qpsByType []string ) error {
440446 snapshotTick := sysbenchMetrics {
441447 Time : start .Unix (),
@@ -450,6 +456,18 @@ func exportSysbenchResults(
450456 Reconnects : fields [14 ],
451457 }
452458
459+ // Add to aggregation counters
460+ qpsVal , _ := strconv .ParseFloat (fields [5 ], 64 )
461+ readQpsVal , _ := strconv .ParseFloat (qpsByType [0 ], 64 )
462+ writeQpsVal , _ := strconv .ParseFloat (qpsByType [1 ], 64 )
463+ otherQpsVal , _ := strconv .ParseFloat (qpsByType [2 ], 64 )
464+
465+ totalQpsSum += qpsVal
466+ readQpsSum += readQpsVal
467+ writeQpsSum += writeQpsVal
468+ otherQpsSum += otherQpsVal
469+ sampleCount ++
470+
453471 if t .ExportOpenmetrics () {
454472 addCurrentSnapshotToOpenmetrics (snapshotTick , openmetricsMap )
455473 } else {
@@ -508,7 +526,71 @@ func exportSysbenchResults(
508526 if t .ExportOpenmetrics () {
509527 metricBytes = getOpenmetricsBytes (openmetricsMap , labelString )
510528 }
511- return os .WriteFile (fmt .Sprintf ("%s/%s" , perfDir , roachtestutil .GetBenchmarkMetricsFileName (t )), metricBytes , 0666 )
529+
530+ // Write the standard metrics file
531+ if err := os .WriteFile (fmt .Sprintf ("%s/%s" , perfDir , roachtestutil .GetBenchmarkMetricsFileName (t )), metricBytes , 0666 ); err != nil {
532+ return err
533+ }
534+
535+ // If using OpenMetrics, also calculate and write aggregated metrics
536+ if t .ExportOpenmetrics () && sampleCount > 0 {
537+ floatSampleCount := float64 (sampleCount )
538+ avgTotalQps := totalQpsSum / floatSampleCount
539+ avgReadQps := readQpsSum / floatSampleCount
540+ avgWriteQps := writeQpsSum / floatSampleCount
541+ avgOtherQps := otherQpsSum / floatSampleCount
542+
543+ // Create aggregated metrics exactly matching roachperf's expected format
544+ aggregatedMetrics := roachtestutil.AggregatedPerfMetrics {
545+ {
546+ Name : "total_qps" ,
547+ Value : roachtestutil .MetricPoint (avgTotalQps ),
548+ Unit : "ops/s" ,
549+ IsHigherBetter : true ,
550+ },
551+ {
552+ Name : "read_qps" ,
553+ Value : roachtestutil .MetricPoint (avgReadQps ),
554+ Unit : "ops/s" ,
555+ IsHigherBetter : true ,
556+ },
557+ {
558+ Name : "write_qps" ,
559+ Value : roachtestutil .MetricPoint (avgWriteQps ),
560+ Unit : "ops/s" ,
561+ IsHigherBetter : true ,
562+ },
563+ {
564+ Name : "other_qps" ,
565+ Value : roachtestutil .MetricPoint (avgOtherQps ),
566+ Unit : "ops/s" ,
567+ IsHigherBetter : true ,
568+ },
569+ }
570+
571+ aggregatedBuf := & bytes.Buffer {}
572+
573+ // Convert aggregated metrics to OpenMetrics format
574+ if err := roachtestutil .GetAggregatedMetricBytes (
575+ aggregatedMetrics ,
576+ []* roachtestutil.Label {{Name : "test" , Value : t .Name ()}},
577+ timeutil .Now (),
578+ aggregatedBuf ,
579+ ); err != nil {
580+ return errors .Wrap (err , "failed to format aggregated metrics" )
581+ }
582+
583+ // Write aggregated metrics
584+ aggregatedFileName := "aggregated_" + roachtestutil .GetBenchmarkMetricsFileName (t )
585+ aggregatedPath := filepath .Join (perfDir , aggregatedFileName )
586+ if err := os .WriteFile (aggregatedPath , aggregatedBuf .Bytes (), 0644 ); err != nil {
587+ return errors .Wrap (err , "failed to write aggregated metrics" )
588+ }
589+
590+ t .L ().Printf ("Wrote aggregated metrics to %s" , aggregatedPath )
591+ }
592+
593+ return nil
512594}
513595
514596// Add sysbenchMetrics to the openmetricsMap
0 commit comments