From d401b9d77980e7469e1c6eaa282f33df0fcfb3df Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 21 Aug 2025 19:00:20 +0200 Subject: pkg/manager: add Rank column with tooltips to the main page --- pkg/report/impact_score.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ pkg/report/title_stat.go | 6 +++--- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'pkg/report') diff --git a/pkg/report/impact_score.go b/pkg/report/impact_score.go index 63adb652a..8139644d2 100644 --- a/pkg/report/impact_score.go +++ b/pkg/report/impact_score.go @@ -4,6 +4,8 @@ package report import ( + "sort" + "github.com/google/syzkaller/pkg/report/crash" ) @@ -62,3 +64,45 @@ func TitlesToImpact(title string, otherTitles ...string) int { } return maxImpact } + +type TitleFreqRank struct { + Title string + Count int + Total int + Rank int +} + +func ExplainTitleStat(ts *titleStat) []*TitleFreqRank { + titleCount := map[string]int{} + var totalCount int + ts.visit(func(count int, titles ...string) { + uniq := map[string]bool{} + for _, title := range titles { + uniq[title] = true + } + for title := range uniq { + titleCount[title] += count + } + totalCount += count + }) + var res []*TitleFreqRank + for title, count := range titleCount { + res = append(res, &TitleFreqRank{ + Title: title, + Count: count, + Total: totalCount, + Rank: TitlesToImpact(title), + }) + } + sort.Slice(res, func(l, r int) bool { + if res[l].Rank != res[r].Rank { + return res[l].Rank > res[r].Rank + } + lTitle, rTitle := res[l].Title, res[r].Title + if titleCount[lTitle] != titleCount[rTitle] { + return titleCount[lTitle] > titleCount[rTitle] + } + return lTitle < rTitle + }) + return res +} diff --git a/pkg/report/title_stat.go b/pkg/report/title_stat.go index 92d8079d5..5b3cd3fb7 100644 --- a/pkg/report/title_stat.go +++ b/pkg/report/title_stat.go @@ -16,9 +16,9 @@ func AddTitleStat(file string, reps []*Report) error { for _, rep := range reps { titles = append(titles, rep.Title) } - stat, err := readStatFile(file) + stat, err := ReadStatFile(file) if err != nil { - return fmt.Errorf("readStatFile: %w", err) + return fmt.Errorf("report.ReadStatFile: %w", err) } stat.add(titles) if err := writeStatFile(file, stat); err != nil { @@ -27,7 +27,7 @@ func AddTitleStat(file string, reps []*Report) error { return nil } -func readStatFile(file string) (*titleStat, error) { +func ReadStatFile(file string) (*titleStat, error) { stat := &titleStat{} if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) { return stat, nil -- cgit mrf-deployment