diff options
| author | Franck Cuny <franck@fcuny.net> | 2022-06-19 15:11:59 -0700 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2022-06-19 15:17:50 -0700 |
| commit | c4c1b7af140c1dd99c7b0520178eea02edd63e2b (patch) | |
| tree | ad5a5a0244b921d09cfedbd72be758a0c5f9e867 /tools/seqstat/seqstat.go | |
| parent | feat(tools/numap): add a tool to report NUMA topology of a host (diff) | |
| download | infra-c4c1b7af140c1dd99c7b0520178eea02edd63e2b.tar.gz | |
feat(tools/seqstat): add a tool to report stats about a sequence
For example:
```
% echo 1 20 12 32 19 2 | ./seqstat -S
▁▅▃█▅▁
min: 1.000000
max: 32.000000
avg: 14.333333
p50: 19.000000
p90: 32.000000
p99: 32.000000
p999: 32.000000
ordered sequence: [1 2 12 19 20 32]
```
Change-Id: I9303bd7d0e964948143e77c868de8777cd7a9951
Reviewed-on: https://cl.fcuny.net/c/world/+/454
Tested-by: CI
Reviewed-by: Franck Cuny <franck@fcuny.net>
Diffstat (limited to 'tools/seqstat/seqstat.go')
| -rw-r--r-- | tools/seqstat/seqstat.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/seqstat/seqstat.go b/tools/seqstat/seqstat.go new file mode 100644 index 0000000..8709fa4 --- /dev/null +++ b/tools/seqstat/seqstat.go @@ -0,0 +1,63 @@ +package main + +import ( + "bufio" + "flag" + "fmt" + "os" + "strconv" + "strings" +) + +var ( + stats = flag.Bool("S", false, "Display statistics about the sequence.") +) + +func main() { + flag.Parse() + + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "usage: [-S] <INPUT>") + flag.PrintDefaults() + } + + elements := argsToElements(flag.Args()) + + if len(elements) < 1 { + scanner := bufio.NewScanner(os.Stdin) + var e []string + for scanner.Scan() { + e = append(e, strings.Split(scanner.Text(), " ")...) + } + elements = argsToElements(e) + } + + seq := newSequence(elements) + + fmt.Println(string(seq.histogram())) + + if *stats { + fmt.Printf("min: %f\n", seq.min) + fmt.Printf("max: %f\n", seq.max) + fmt.Printf("avg: %f\n", seq.avg()) + fmt.Printf("p50: %f\n", seq.p50()) + fmt.Printf("p90: %f\n", seq.p90()) + fmt.Printf("p99: %f\n", seq.p99()) + fmt.Printf("p999: %f\n", seq.p999()) + fmt.Printf("ordered sequence: %v\n", seq.elementsSorted) + } +} + +// converts the input to float64 +func argsToElements(args []string) []float64 { + elements := make([]float64, len(args)) + + for i, input := range args { + num, err := strconv.ParseFloat(input, 64) + if err != nil { + panic(err) + } + elements[i] = num + } + return elements +} |
