mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Updating test to report memory
This commit is contained in:
parent
63512a4db9
commit
f162f54689
|
@ -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,16 +51,16 @@ 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")
|
||||||
eng := NewEngine(EngineOpts{
|
|
||||||
Logger: l,
|
|
||||||
Reg: nil,
|
|
||||||
MaxSamples: 50000000,
|
|
||||||
Timeout: 60 * time.Second,
|
|
||||||
EnablePerStepStats: true,
|
|
||||||
})
|
|
||||||
noErr(err)
|
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
|
eng := NewEngine(EngineOpts{
|
||||||
|
Logger: l,
|
||||||
|
Reg: nil,
|
||||||
|
MaxSamples: 50000000,
|
||||||
|
Timeout: 60 * time.Second,
|
||||||
|
EnablePerStepStats: true,
|
||||||
|
})
|
||||||
|
noErr(err)
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue