You've already forked go-profiler-notes
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:
65
bench/csv.go
Normal file
65
bench/csv.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user