mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
move main report processing benchmarks in one place
so they can share code and are easier to run in combination. We take advantage of the code sharing by generalising the report rendering benchmarks to read & merge reports from a dir.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"flag"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/weaveworks/scope/render"
|
||||
@@ -12,9 +14,43 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
benchReportFile = flag.String("bench-report-file", "", "report file to use for benchmarking (relative to this package)")
|
||||
benchReportPath = flag.String("bench-report-path", "", "report file, or dir with files, to use for benchmarking (relative to this package)")
|
||||
)
|
||||
|
||||
func readReportFiles(path string) ([]report.Report, error) {
|
||||
reports := []report.Report{}
|
||||
if err := filepath.Walk(path,
|
||||
func(p string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
rpt, err := report.MakeFromFile(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reports = append(reports, rpt)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return reports, nil
|
||||
}
|
||||
|
||||
func BenchmarkReportUnmarshal(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
b.StartTimer()
|
||||
if _, err := readReportFiles(*benchReportPath); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTopologyList(b *testing.B) {
|
||||
benchmarkRender(b, func(report report.Report) {
|
||||
request := &http.Request{
|
||||
@@ -26,11 +62,12 @@ func BenchmarkTopologyList(b *testing.B) {
|
||||
|
||||
func benchmarkRender(b *testing.B, f func(report.Report)) {
|
||||
r := fixture.Report
|
||||
if *benchReportFile != "" {
|
||||
var err error
|
||||
if r, err = report.MakeFromFile(*benchReportFile); err != nil {
|
||||
if *benchReportPath != "" {
|
||||
reports, err := readReportFiles(*benchReportPath)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
r = NewSmartMerger().Merge(reports)
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
benchReportPath = flag.String("bench-report-path", "", "report file, or dir with files, to use for benchmarking (relative to this package)")
|
||||
)
|
||||
|
||||
func BenchmarkReportUnmarshal(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
b.StartTimer()
|
||||
if err := readReportFiles(*benchReportPath); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readReportFiles(path string) error {
|
||||
return filepath.Walk(path,
|
||||
func(p string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if _, err := MakeFromFile(p); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user