1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-15 23:54:16 +02:00

Add bench dir

This commit is contained in:
Felix Geisendörfer
2021-02-03 11:16:38 +01:00
parent e1341fbf16
commit 50fb7ed6be
9 changed files with 1119 additions and 0 deletions

65
bench/csv.go Normal file
View File

@ -0,0 +1,65 @@
package main
import (
"fmt"
"time"
)
type Record struct {
Workload string
Ops int
Goroutines int
Depth int
Blockprofilerate int
Run int
Duration time.Duration
}
type Column struct {
Name string
MarshalValue func(*Record) (string, error)
}
var Columns = []Column{
{"workload", func(r *Record) (string, error) {
return fmt.Sprintf("%s", r.Workload), nil
}},
{"ops", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Ops), nil
}},
{"goroutines", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Goroutines), nil
}},
{"depth", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Depth), nil
}},
{"blockprofilerate", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Blockprofilerate), nil
}},
{"run", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Run), nil
}},
{"ms", func(r *Record) (string, error) {
return fmt.Sprintf("%f", r.Duration.Seconds()*1000), nil
}},
}
func (r *Record) MarshalRecord() ([]string, error) {
record := make([]string, len(Columns))
for i, col := range Columns {
val, err := col.MarshalValue(r)
if err != nil {
return nil, err
}
record[i] = val
}
return record, nil
}
func Headers() []string {
headers := make([]string, len(Columns))
for i, col := range Columns {
headers[i] = col.Name
}
return headers
}