Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metricsviz function to process data from an on-disk lg file. #10356

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/metricsviz/metricsviz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"hash/adler32"
"os"
"regexp"
"slices"
"sort"
Expand Down Expand Up @@ -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)
}
}