[benchmark/cpu] set ymax to prevent the graph go to the legend

pull/13654/head
Jin Zhang 2022-03-07 20:24:07 +00:00
parent 7bd8639fbc
commit 179e3952a4
3 changed files with 23 additions and 9 deletions

View File

@ -74,7 +74,7 @@ func readInCSV(csvPath string, apps map[string]runs) error {
values := []float64{}
// 8-13 contain the run results
// 8-16 contain the run results
for i := 8; i <= 16; i++ {
v, err := strconv.ParseFloat(d[i], 64)
if err != nil {

View File

@ -57,12 +57,13 @@ func createCPUChart(chartPath string, values []plotter.Values, names []string) e
p := plot.New()
p.Title.Text = "CPU utilization to go from 0 to successful Kubernetes deployment"
p.Y.Label.Text = "CPU utilization"
setYMax(p, values)
w := vg.Points(20)
barsA, err := plotter.NewBarChart(values[0], w)
if err != nil {
panic(err)
return err
}
barsA.LineStyle.Width = vg.Length(0)
barsA.Color = plotutil.Color(0)
@ -70,7 +71,7 @@ func createCPUChart(chartPath string, values []plotter.Values, names []string) e
barsB, err := plotter.NewBarChart(values[1], w)
if err != nil {
panic(err)
return err
}
barsB.LineStyle.Width = vg.Length(0)
barsB.Color = plotutil.Color(1)
@ -78,7 +79,7 @@ func createCPUChart(chartPath string, values []plotter.Values, names []string) e
barsC, err := plotter.NewBarChart(values[2], w)
if err != nil {
panic(err)
return err
}
barsC.LineStyle.Width = vg.Length(0)
barsC.Color = plotutil.Color(2)
@ -100,3 +101,16 @@ func createCPUChart(chartPath string, values []plotter.Values, names []string) e
return nil
}
func setYMax(p *plot.Plot, values []plotter.Values) {
ymax := 0.0
for _, value := range values {
for _, v := range value {
if v > ymax {
ymax = v
}
}
}
p.Y.Max = ymax + 5
}

View File

@ -66,7 +66,7 @@ func main() {
apps := make(map[string]runs)
if err := readInCSV(*csvPath, apps); err != nil {
log.Fatal(err)
log.Fatalf("fail to readin cvs file with err %s", err)
}
runningTime, cpuMdPlot, cpuChartPlot, totals, names := values(apps)
@ -76,7 +76,7 @@ func main() {
// chart for running time
if err := createChart(*imagePath+"-time.png", runningTime, totals, names); err != nil {
log.Fatal(err)
log.Fatalf("fail to create running time chart with err %s", err)
}
// markdown table for cpu utilization
@ -84,7 +84,7 @@ func main() {
// chart for cpu utilization
if err := createCPUChart(*imagePath+"-cpu.png", cpuChartPlot, names); err != nil {
log.Fatal(err)
log.Fatalf("fail to create CPU chart with err %s", err)
}
// generate page and save
@ -96,11 +96,11 @@ func main() {
f, err := os.Create(*pagePath)
if err != nil {
log.Fatal(err)
log.Fatalf("fail to create file under path %s, with err %s", *pagePath, err)
}
if err = tmpl.Execute(f, data); err != nil {
log.Fatal(err)
log.Fatalf("fail to populate the page with err %s", err)
}
f.Close()