No Description
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.

timeScrape.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "os"
  7. "strings"
  8. "time"
  9. )
  10. type test struct {
  11. name string
  12. t time.Time
  13. }
  14. type result struct {
  15. totalTime time.Duration
  16. count int
  17. }
  18. func createReport(f string, m map[string]*result) {
  19. tests := []test{}
  20. file, err := os.Open(f)
  21. if err != nil {
  22. log.Printf("failed to open file: %s", err)
  23. return
  24. }
  25. defer file.Close()
  26. scanner := bufio.NewScanner(file)
  27. for scanner.Scan() {
  28. s := strings.Split(scanner.Text(), " ")
  29. ts := strings.Replace(
  30. strings.Replace(
  31. s[0],
  32. "[",
  33. "",
  34. -1,
  35. ),
  36. "]",
  37. "",
  38. -1,
  39. )
  40. t, err := time.Parse("15:04:05", ts)
  41. if err != nil {
  42. log.Fatal(err)
  43. }
  44. qn := strings.Split(s[2], "::")
  45. tests = append(tests, test{qn[len(qn)-1], t})
  46. }
  47. if err := scanner.Err(); err != nil {
  48. log.Printf("failed to scan cleanly: %s", err)
  49. return
  50. }
  51. for i, te := range tests {
  52. if i == 0 {
  53. continue
  54. }
  55. realTime := te.t.Sub(tests[i-1].t)
  56. e, ok := m[te.name]
  57. if !ok {
  58. m[te.name] = &result{
  59. totalTime: realTime,
  60. count: 1,
  61. }
  62. } else {
  63. e.totalTime = e.totalTime + realTime
  64. e.count = e.count + 1
  65. }
  66. }
  67. }
  68. func main() {
  69. m := make(map[string]*result)
  70. if len(os.Args) < 2 {
  71. log.Fatal("must provide file")
  72. }
  73. for _, a := range os.Args[1:] {
  74. createReport(a, m)
  75. }
  76. for k, v := range m {
  77. fmt.Printf("%s %s\n", k, (v.totalTime / time.Duration(v.count)))
  78. }
  79. }