From 286c38bd1ae34870c40986e8ddebfd65d6e5049e Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 13 Jun 2024 20:30:13 +0200 Subject: pkg/stats: split out pkg/stats/sample This will reduce the number of dependencies needed for the main syzkaller tools. --- tools/syz-testbed/stats.go | 26 +++++++++++++------------- tools/syz-testbed/table.go | 8 ++++---- tools/syz-testbed/table_test.go | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'tools') diff --git a/tools/syz-testbed/stats.go b/tools/syz-testbed/stats.go index 8c20d495e..108c25ed1 100644 --- a/tools/syz-testbed/stats.go +++ b/tools/syz-testbed/stats.go @@ -12,7 +12,7 @@ import ( "time" "github.com/google/syzkaller/pkg/osutil" - "github.com/google/syzkaller/pkg/stats" + "github.com/google/syzkaller/pkg/stats/sample" ) type BugInfo struct { @@ -103,12 +103,12 @@ func readBenches(benchFile string) ([]StatRecord, error) { // The input are stat snapshots of different instances taken at the same time. // This function groups those data points per stat types (e.g. exec total, crashes, etc.). -func groupSamples(records []StatRecord) map[string]*stats.Sample { - ret := make(map[string]*stats.Sample) +func groupSamples(records []StatRecord) map[string]*sample.Sample { + ret := make(map[string]*sample.Sample) for _, record := range records { for key, value := range record { if ret[key] == nil { - ret[key] = &stats.Sample{} + ret[key] = &sample.Sample{} } ret[key].Xs = append(ret[key].Xs, float64(value)) } @@ -243,7 +243,7 @@ func (group RunResultGroup) minResultLength() int { return ret } -func (group RunResultGroup) groupNthRecord(i int) map[string]*stats.Sample { +func (group RunResultGroup) groupNthRecord(i int) map[string]*sample.Sample { records := []StatRecord{} for _, result := range group.SyzManagerResults() { records = append(records, result.StatRecords[i]) @@ -251,7 +251,7 @@ func (group RunResultGroup) groupNthRecord(i int) map[string]*stats.Sample { return groupSamples(records) } -func (group RunResultGroup) groupLastRecord() map[string]*stats.Sample { +func (group RunResultGroup) groupLastRecord() map[string]*sample.Sample { records := []StatRecord{} for _, result := range group.SyzManagerResults() { n := len(result.StatRecords) @@ -304,7 +304,7 @@ func (view StatView) AlignedStatsTable(field string) (*Table, error) { continue } // Unwind the samples so that they are aligned on the field value. - var samples map[string]*stats.Sample + var samples map[string]*sample.Sample for i := minLen - 1; i >= 0; i-- { candidate := group.groupNthRecord(i) // TODO: consider data interpolation. @@ -390,16 +390,16 @@ func (view StatView) GenerateReproDurationTable() (*Table, error) { table.AddColumn(group.Name) } for _, group := range view.Groups { - samples := make(map[string]*stats.Sample) + samples := make(map[string]*sample.Sample) for _, result := range group.SyzReproResults() { title := result.Input.Title - var sample *stats.Sample - sample, ok := samples[title] + var sampleObj *sample.Sample + sampleObj, ok := samples[title] if !ok { - sample = &stats.Sample{} - samples[title] = sample + sampleObj = &sample.Sample{} + samples[title] = sampleObj } - sample.Xs = append(sample.Xs, result.Duration.Seconds()) + sampleObj.Xs = append(sampleObj.Xs, result.Duration.Seconds()) } for title, sample := range samples { diff --git a/tools/syz-testbed/table.go b/tools/syz-testbed/table.go index ee3ffd0e7..fae3e2279 100644 --- a/tools/syz-testbed/table.go +++ b/tools/syz-testbed/table.go @@ -10,7 +10,7 @@ import ( "os" "sort" - "github.com/google/syzkaller/pkg/stats" + "github.com/google/syzkaller/pkg/stats/sample" ) type Cell = interface{} @@ -25,7 +25,7 @@ type Table struct { type ValueCell struct { Value float64 - Sample *stats.Sample + Sample *sample.Sample PercentChange *float64 PValue *float64 } @@ -39,7 +39,7 @@ type BoolCell struct { Value bool } -func NewValueCell(sample *stats.Sample) *ValueCell { +func NewValueCell(sample *sample.Sample) *ValueCell { return &ValueCell{Value: sample.Median(), Sample: sample} } @@ -183,7 +183,7 @@ func (t *Table) SetRelativeValues(baseColumn string) error { } cellSample := valueCell.Sample.RemoveOutliers() - pval, err := stats.UTest(baseSample, cellSample) + pval, err := sample.UTest(baseSample, cellSample) if err == nil { // Sometimes it fails because there are too few samples. valueCell.PValue = new(float64) diff --git a/tools/syz-testbed/table_test.go b/tools/syz-testbed/table_test.go index fb07e7804..313802819 100644 --- a/tools/syz-testbed/table_test.go +++ b/tools/syz-testbed/table_test.go @@ -6,16 +6,16 @@ package main import ( "testing" - "github.com/google/syzkaller/pkg/stats" + "github.com/google/syzkaller/pkg/stats/sample" "github.com/stretchr/testify/assert" ) func TestRelativeValues(t *testing.T) { table := NewTable("", "A", "B") - table.Set("row1", "A", NewValueCell(&stats.Sample{Xs: []float64{2, 2}})) - table.Set("row1", "B", NewValueCell(&stats.Sample{Xs: []float64{3, 3}})) + table.Set("row1", "A", NewValueCell(&sample.Sample{Xs: []float64{2, 2}})) + table.Set("row1", "B", NewValueCell(&sample.Sample{Xs: []float64{3, 3}})) // Don't set row2/A. - table.Set("row2", "B", NewValueCell(&stats.Sample{Xs: []float64{1, 1}})) + table.Set("row2", "B", NewValueCell(&sample.Sample{Xs: []float64{1, 1}})) err := table.SetRelativeValues("A") assert.NoError(t, err) -- cgit mrf-deployment