Skip to content

Commit

Permalink
get metrics only since we started the execution
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Feb 1, 2024
1 parent e987937 commit 6626e83
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
3 changes: 2 additions & 1 deletion go/cmd/gen/metrics/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package metrics

import (
"log"
"time"

"github.com/spf13/cobra"
"github.com/vitessio/arewefastyet/go/exec"
Expand Down Expand Up @@ -68,7 +69,7 @@ func GenExecMetricsCmd() *cobra.Command {
continue
}

executionMetrics, err := metrics.GetExecutionMetrics(*clientMetrics, uuid, 0)
executionMetrics, err := metrics.GetExecutionMetrics(*clientMetrics, uuid, 0, time.Now())
if err != nil {
return err
}
Expand Down
41 changes: 33 additions & 8 deletions go/exec/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,31 @@ package metrics
import (
"fmt"
"strings"
"time"

"github.com/vitessio/arewefastyet/go/storage"
"github.com/vitessio/arewefastyet/go/storage/influxdb"
awftmath "github.com/vitessio/arewefastyet/go/tools/math"
)

const (
cpuSecondsPerComponent = `from(bucket:"%s")
|> range(start: %s, stop: %s)
cpuSecondsPerComponentStart = `from(bucket:"%s")
|> range(start: 0, stop: -%.0fs)
|> filter(fn:(r) => r._measurement == "process_cpu_seconds_total" and r.exec_uuid == "%s" and r.component == "%s")
|> max()`

memAllocBytesPerComponent = `from(bucket:"%s")
|> range(start: %s, stop: %s)
cpuSecondsPerComponentEnd = `from(bucket:"%s")
|> range(start: 0, stop: now())
|> filter(fn:(r) => r._measurement == "process_cpu_seconds_total" and r.exec_uuid == "%s" and r.component == "%s")
|> max()`

memAllocBytesPerComponentStart = `from(bucket:"%s")
|> range(start: 0, stop: -%.0fs)
|> filter(fn:(r) => r._measurement == "go_memstats_alloc_bytes_total" and r.exec_uuid == "%s" and r.component == "%s")
|> max()`

memAllocBytesPerComponentEnd = `from(bucket:"%s")
|> range(start: 0, stop: now())
|> filter(fn:(r) => r._measurement == "go_memstats_alloc_bytes_total" and r.exec_uuid == "%s" and r.component == "%s")
|> max()`
)
Expand Down Expand Up @@ -74,21 +85,35 @@ type (

// GetExecutionMetrics fetches and computes a single execution's metrics.
// Metrics are fetched using the given influxdb.Client and execUUID.
func GetExecutionMetrics(client influxdb.Client, execUUID string, queries int) (ExecutionMetrics, error) {
func GetExecutionMetrics(client influxdb.Client, execUUID string, queries int, startTime time.Time) (ExecutionMetrics, error) {
execMetrics := NewExecMetrics()

var err error
for _, component := range components {
execMetrics.ComponentsCPUTime[component], err = getSumFloatValueForQuery(client, fmt.Sprintf(cpuSecondsPerComponent, client.Config.Database, "0", "now()", execUUID, component))
// CPU time
endValue, err := getSumFloatValueForQuery(client, fmt.Sprintf(cpuSecondsPerComponentEnd, client.Config.Database, execUUID, component))
if err != nil {
return ExecutionMetrics{}, err
}

startValue, err := getSumFloatValueForQuery(client, fmt.Sprintf(cpuSecondsPerComponentStart, client.Config.Database, time.Since(startTime).Seconds(), execUUID, component))
if err != nil {
return ExecutionMetrics{}, err
}
execMetrics.ComponentsCPUTime[component] = endValue - startValue
execMetrics.TotalComponentsCPUTime += execMetrics.ComponentsCPUTime[component]

execMetrics.ComponentsMemStatsAllocBytes[component], err = getSumFloatValueForQuery(client, fmt.Sprintf(memAllocBytesPerComponent, client.Config.Database, "0", "now()", execUUID, component))
// Memory
endValue, err = getSumFloatValueForQuery(client, fmt.Sprintf(memAllocBytesPerComponentEnd, client.Config.Database, execUUID, component))
if err != nil {
return ExecutionMetrics{}, err
}

startValue, err = getSumFloatValueForQuery(client, fmt.Sprintf(memAllocBytesPerComponentStart, client.Config.Database, time.Since(startTime).Seconds(), execUUID, component))
if err != nil {
return ExecutionMetrics{}, err
}

execMetrics.ComponentsMemStatsAllocBytes[component] = endValue - startValue
execMetrics.TotalComponentsMemStatsAllocBytes += execMetrics.ComponentsMemStatsAllocBytes[component]
}

Expand Down
17 changes: 12 additions & 5 deletions go/tools/macrobench/macrobench.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"os/exec"
"strings"
"time"

"github.com/vitessio/arewefastyet/go/exec/metrics"
"github.com/vitessio/arewefastyet/go/storage/influxdb"
Expand Down Expand Up @@ -122,9 +123,15 @@ func Run(mabcfg Config) error {

// Execution
var resStr []byte
var runStartTime time.Time
for _, step := range newSteps {
args := buildSysbenchArgString(mabcfg.M, step.Name)
args = append(args, mabcfg.WorkloadPath, step.SysbenchName)

if step.Name == stepRun {
runStartTime = time.Now()
}

command := exec.Command(mabcfg.SysbenchExec, args...)
command.Dir = mabcfg.WorkingDirectory
out, err := command.Output()
Expand All @@ -136,19 +143,19 @@ func Run(mabcfg Config) error {
}
}

err = handleResults(mabcfg, resStr, sqlClient, metricsClient, macrobenchID)
err = handleResults(mabcfg, resStr, sqlClient, metricsClient, macrobenchID, runStartTime)
if err != nil {
return err
}
return nil
}

func handleResults(mabcfg Config, resStr []byte, sqlClient *psdb.Client, metricsClient *influxdb.Client, macrobenchID int) error {
func handleResults(mabcfg Config, resStr []byte, sqlClient *psdb.Client, metricsClient *influxdb.Client, macrobenchID int, startTime time.Time) error {
sysbenchResults, err := handleSysBenchResults(resStr, sqlClient, macrobenchID)
if err != nil {
return err
}
err = handleMetricsResults(metricsClient, sqlClient, mabcfg.execUUID, sysbenchResults.Queries)
err = handleMetricsResults(metricsClient, sqlClient, mabcfg.execUUID, sysbenchResults.Queries, startTime)
if err != nil {
return err
}
Expand Down Expand Up @@ -187,8 +194,8 @@ func handleVTGateResults(ports []string, sqlClient *psdb.Client, execUUID string
return insertVTGateQueryMapToMySQL(sqlClient, execUUID, plans, macrobenchID)
}

func handleMetricsResults(client *influxdb.Client, sqlClient *psdb.Client, execUUID string, queries int) error {
execMetrics, err := metrics.GetExecutionMetrics(*client, execUUID, queries)
func handleMetricsResults(client *influxdb.Client, sqlClient *psdb.Client, execUUID string, queries int, startTime time.Time) error {
execMetrics, err := metrics.GetExecutionMetrics(*client, execUUID, queries, startTime)
if err != nil {
return err
}
Expand Down

0 comments on commit 6626e83

Please sign in to comment.