-
Notifications
You must be signed in to change notification settings - Fork 3
/
printStatistics.go
88 lines (78 loc) · 2.28 KB
/
printStatistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"os"
"runtime"
"time"
"github.com/dustin/go-humanize"
"github.com/globusdigital/logbench/benchmark"
"github.com/olekukonko/tablewriter"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func printStatistics(
timeTotal time.Duration,
target uint64,
concWriters uint,
memStatChan chan benchmark.MemStats,
loggerOrder []string,
operationsOrder []string,
stats map[string]map[string]benchmark.Statistics,
) {
numPrint := message.NewPrinter(language.English)
memStats := <-memStatChan
var m runtime.MemStats
runtime.ReadMemStats(&m)
totalConcWriters := numPrint.Sprintf("%d", concWriters)
totalGC := numPrint.Sprintf("%d", m.NumGC)
totalMallocs := numPrint.Sprintf("%d", m.Mallocs)
maxHeapObj := numPrint.Sprintf("%d", memStats.MaxHeapObjects)
heapAllocInc := numPrint.Sprintf("%d", memStats.HeapAllocInc)
heapObjInc := numPrint.Sprintf("%d", memStats.HeapObjectsInc)
memStatSamples := numPrint.Sprintf("%d", memStats.StatSamples)
// Print main table
{
tbMain := tablewriter.NewWriter(os.Stdout)
tbMain.SetAlignment(tablewriter.ALIGN_LEFT)
dr := func(k, v string) { tbMain.Append([]string{k, v}) }
dr("target", numPrint.Sprintf("%d", target))
dr("conc. writers", totalConcWriters)
dr("", "")
dr("time total", timeTotal.String())
dr("max heap", humanize.Bytes(memStats.MaxHeapAlloc))
dr("max heap obj", maxHeapObj)
dr("mem samples", memStatSamples)
dr("heap inc", heapAllocInc)
dr("heap obj in", heapObjInc)
dr("heap sys", humanize.Bytes(memStats.MaxHeapSys))
dr("total alloc", humanize.Bytes(m.TotalAlloc))
dr("mallocs", totalMallocs)
dr("num-gc", totalGC)
dr("total pause", time.Duration(m.PauseTotalNs).String())
tbMain.Render()
}
// Print comparisons table
{
tbMain := tablewriter.NewWriter(os.Stdout)
tbMain.SetHeader([]string{
"logger",
"operation",
"time total",
"time avg.",
"written",
})
tbMain.SetAlignment(tablewriter.ALIGN_LEFT)
for _, loggerName := range loggerOrder {
for _, operation := range operationsOrder {
stats := stats[loggerName][operation]
tbMain.Append([]string{
loggerName,
operation,
stats.TotalTime.String(),
(stats.TotalTime / time.Duration(target)).String(),
numPrint.Sprintf("%d", stats.TotalLogsWritten),
})
}
}
tbMain.Render()
}
}