Updating test to report memory

This commit is contained in:
James Luck 2023-07-25 17:34:11 +10:00
parent 63512a4db9
commit f162f54689

View file

@ -15,12 +15,12 @@ package promql
import ( import (
"context" "context"
"fmt"
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/go-kit/log/level" "github.com/go-kit/log/level"
"github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"os" "os"
"runtime"
"testing" "testing"
"time" "time"
) )
@ -51,6 +51,8 @@ func benchmarkQuery(query string, b *testing.B) {
// Create engine for querying // Create engine for querying
otel.Tracer("name").Start(context.Background(), "Run") otel.Tracer("name").Start(context.Background(), "Run")
for n := 0; n < b.N; n++ {
eng := NewEngine(EngineOpts{ eng := NewEngine(EngineOpts{
Logger: l, Logger: l,
Reg: nil, Reg: nil,
@ -59,8 +61,6 @@ func benchmarkQuery(query string, b *testing.B) {
EnablePerStepStats: true, EnablePerStepStats: true,
}) })
noErr(err) noErr(err)
for n := 0; n < b.N; n++ {
q, err := eng.NewInstantQuery(context.Background(), db, &PrometheusQueryOpts{}, query, time.UnixMilli(1688922000001)) q, err := eng.NewInstantQuery(context.Background(), db, &PrometheusQueryOpts{}, query, time.UnixMilli(1688922000001))
noErr(err) noErr(err)
q.Stats().Samples.EnablePerStepStats = true q.Stats().Samples.EnablePerStepStats = true
@ -69,11 +69,16 @@ func benchmarkQuery(query string, b *testing.B) {
b.StopTimer() b.StopTimer()
if n == 0 { if n == 0 {
fmt.Printf("Peak samples: %v, Total samples: %v", q.Stats().Samples.PeakSamples, q.Stats().Samples.TotalSamples) b.ReportMetric(float64(q.Stats().Samples.PeakSamples), "peak_samples")
fmt.Println() b.ReportMetric(float64(q.Stats().Samples.TotalSamples), "total_samples")
} }
} }
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
memstats.Sys
b.ReportMetric(float64(memstats.Sys), "sys_memory")
// Clean up any last resources when done. // Clean up any last resources when done.
err = db.Close() err = db.Close()
noErr(err) noErr(err)