blob: 0193604b82d9e7c86056c902d7bae7f164598450 [file] [log] [blame]
Shinichiro Hamajib69bf8a2015-06-10 14:52:06 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090015package main
16
17import (
18 "fmt"
19 "sort"
20 "time"
21)
22
23type statsData struct {
24 Name string
25 Count int
26 Longest time.Duration
27 Total time.Duration
28}
29
30var stats = map[string]statsData{}
31
32func addStats(name string, v Value, t time.Time) {
Fumitoshi Ukai586b02a2015-05-08 00:23:10 +090033 if !katiEvalStatsFlag {
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090034 return
35 }
Fumitoshi Ukai358c68a2015-06-08 13:12:55 +090036 d := time.Since(t)
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090037 key := fmt.Sprintf("%s:%s", name, v.String())
38 s := stats[key]
39 if d > s.Longest {
40 s.Longest = d
41 }
42 s.Total += d
43 s.Count++
44 stats[key] = s
45}
46
47func dumpStats() {
Fumitoshi Ukai586b02a2015-05-08 00:23:10 +090048 if !katiEvalStatsFlag {
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090049 return
50 }
51 var sv byTotalTime
52 for k, v := range stats {
53 v.Name = k
54 sv = append(sv, v)
55 }
56 sort.Sort(sv)
Fumitoshi Ukai47f401f2015-04-30 17:29:50 +090057 fmt.Println("count,longest(ns),total(ns),longest,total,name")
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090058 for _, s := range sv {
Fumitoshi Ukai47f401f2015-04-30 17:29:50 +090059 fmt.Printf("%d,%d,%d,%v,%v,%s\n", s.Count, s.Longest, s.Total, s.Longest, s.Total, s.Name)
Fumitoshi Ukai6ac7f692015-04-15 17:13:51 +090060 }
61}
62
63type byTotalTime []statsData
64
65func (b byTotalTime) Len() int { return len(b) }
66func (b byTotalTime) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
67func (b byTotalTime) Less(i, j int) bool {
68 return b[i].Total > b[j].Total
69}