mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add metricsviz function to process data from an on-disk lg file.
This is part of a series of changes to add metric charts in performance benchmarks. PiperOrigin-RevId: 633098749
This commit is contained in:
committed by
gVisor bot
parent
cc665d1dcb
commit
8860dd2b55
@@ -21,6 +21,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/adler32"
|
||||
"os"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -607,3 +608,36 @@ func FromNamedContainerLogs(ctx context.Context, testLike testing.TB, container
|
||||
testLike.Fatalf("Failed to publish HTML: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// FromProfilingMetricsLogFile parses a profiling metrics log file
|
||||
// (as created by --profiling-metrics-log) and reports metrics data within.
|
||||
func FromProfilingMetricsLogFile(ctx context.Context, testLike testing.TB, logFile string) {
|
||||
contents, err := os.ReadFile(logFile)
|
||||
if err != nil {
|
||||
testLike.Fatalf("Failed to read log file: %v", err)
|
||||
}
|
||||
data, err := Parse(string(contents), false)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrNoMetricData) {
|
||||
return // No metric data in the logs, so stay quiet.
|
||||
}
|
||||
testLike.Fatalf("Failed to parse metrics data: %v", err)
|
||||
}
|
||||
htmlOptions := HTMLOptions{
|
||||
Title: testLike.Name(),
|
||||
When: data.startTime,
|
||||
}
|
||||
html, err := data.ToHTML(htmlOptions)
|
||||
if err != nil {
|
||||
testLike.Fatalf("Failed to generate HTML: %v", err)
|
||||
}
|
||||
if strings.HasSuffix(logFile, ".log") {
|
||||
// Best-effort conversion to HTML next to the .log file in the directory,
|
||||
// if permissions allow that. Ignore errors, what matters more is the
|
||||
// publishing step later on.
|
||||
_ = os.WriteFile(strings.TrimSuffix(logFile, ".log")+".html", []byte(html), 0644)
|
||||
}
|
||||
if err := publishHTMLFn(ctx, testLike, htmlOptions, html); err != nil {
|
||||
testLike.Fatalf("Failed to publish HTML: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user