You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.4 KiB

package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"time"
)
type test struct {
name string
t time.Time
}
type result struct {
totalTime time.Duration
count int
}
func createReport(f string, m map[string]*result) {
tests := []test{}
file, err := os.Open(f)
if err != nil {
log.Printf("failed to open file: %s", err)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := strings.Split(scanner.Text(), " ")
ts := strings.Replace(
strings.Replace(
s[0],
"[",
"",
-1,
),
"]",
"",
-1,
)
t, err := time.Parse("15:04:05", ts)
if err != nil {
log.Fatal(err)
}
qn := strings.Split(s[2], "::")
tests = append(tests, test{qn[len(qn)-1], t})
}
if err := scanner.Err(); err != nil {
log.Printf("failed to scan cleanly: %s", err)
return
}
for i, te := range tests {
if i == 0 {
continue
}
realTime := te.t.Sub(tests[i-1].t)
e, ok := m[te.name]
if !ok {
m[te.name] = &result{
totalTime: realTime,
count: 1,
}
} else {
e.totalTime = e.totalTime + realTime
e.count = e.count + 1
}
}
}
func main() {
m := make(map[string]*result)
if len(os.Args) < 2 {
log.Fatal("must provide file")
}
for _, a := range os.Args[1:] {
createReport(a, m)
}
for k, v := range m {
fmt.Printf("%s %s\n", k, (v.totalTime / time.Duration(v.count)))
}
}