Debian Codegraph @

benchmarks/cmd/benchreport/main.go

raw
1 // Command benchreport renders the benchmark report of go-json from the results of the machines: the HTML page,
2 // the SVG summary which the README shows, and a copy of every result file, which the page links to.
3 //
4 // go run ./cmd/benchreport -out site results-amd64.json results-arm64.json
5 package main
6
7 import (
8 "flag"
9 "fmt"
10 "os"
11 "path/filepath"
12
13 "benchmark/report"
14 )
15
16 func main() {
17 out := flag.String("out", "site", "the directory to write the site to")
18 attestations := flag.String("attestations", "", "the URL of the attestations of the result files")
19 flag.Parse()
20 if err := run(*out, *attestations, flag.Args()); err != nil {
21 fmt.Fprintln(os.Stderr, err)
22 os.Exit(1)
23 }
24 }
25
26 func run(out, attestations string, files []string) error {
27 if len(files) == 0 {
28 return fmt.Errorf("no result file is given")
29 }
30 if err := os.MkdirAll(out, 0o755); err != nil {
31 return err
32 }
33 site := &report.Site{Attestations: attestations}
34 for _, f := range files {
35 r, err := report.ReadRun(f)
36 if err != nil {
37 return err
38 }
39 data, err := os.ReadFile(f)
40 if err != nil {
41 return err
42 }
43 name := filepath.Base(f)
44 // the file is copied as it is, so that its digest is the one of the attested file
45 if err := os.WriteFile(filepath.Join(out, name), data, 0o644); err != nil {
46 return err
47 }
48 site.Runs = append(site.Runs, r)
49 site.Files = append(site.Files, name)
50 }
51 page, err := site.HTML()
52 if err != nil {
53 return err
54 }
55 if err := os.WriteFile(filepath.Join(out, "index.html"), []byte(page), 0o644); err != nil {
56 return err
57 }
58 return os.WriteFile(filepath.Join(out, "summary.svg"), []byte(site.Summary()), 0o644)
59 }