Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: tools/eval_gc_nvp.py

Issue 1846983002: [tools] Beef up GC eval scripts (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/eval_gc_time.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2015 the V8 project authors. All rights reserved. 3 # Copyright 2015 the V8 project authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """This script is used to analyze GCTracer's NVP output.""" 7 """This script is used to analyze GCTracer's NVP output."""
8 8
9 9
10 from argparse import ArgumentParser 10 from argparse import ArgumentParser
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ret.append(" [{0},{1}[: {2}".format( 67 ret.append(" [{0},{1}[: {2}".format(
68 str(min_value), str(max_value), self.histogram[i])) 68 str(min_value), str(max_value), self.histogram[i]))
69 else: 69 else:
70 if self.fill_empty: 70 if self.fill_empty:
71 ret.append(" [{0},{1}[: {2}".format( 71 ret.append(" [{0},{1}[: {2}".format(
72 str(min_value), str(max_value), 0)) 72 str(min_value), str(max_value), 0))
73 return "\n".join(ret) 73 return "\n".join(ret)
74 74
75 75
76 class Category: 76 class Category:
77 def __init__(self, key, histogram): 77 def __init__(self, key, histogram, csv):
78 self.key = key 78 self.key = key
79 self.values = [] 79 self.values = []
80 self.histogram = histogram 80 self.histogram = histogram
81 self.csv = csv
81 82
82 def process_entry(self, entry): 83 def process_entry(self, entry):
83 if self.key in entry: 84 if self.key in entry:
84 self.values.append(float(entry[self.key])) 85 self.values.append(float(entry[self.key]))
85 if self.histogram: 86 if self.histogram:
86 self.histogram.add(float(entry[self.key])) 87 self.histogram.add(float(entry[self.key]))
87 88
88 def min(self): 89 def min(self):
89 return min(self.values) 90 return min(self.values)
90 91
91 def max(self): 92 def max(self):
92 return max(self.values) 93 return max(self.values)
93 94
94 def avg(self): 95 def avg(self):
96 if len(self.values) == 0:
97 return 0.0
95 return sum(self.values) / len(self.values) 98 return sum(self.values) / len(self.values)
96 99
97 def __str__(self): 100 def __str__(self):
98 ret = [self.key] 101 if self.csv:
99 ret.append(" len: {0}".format(len(self.values))) 102 ret = [self.key]
100 if len(self.values) > 0: 103 ret.append(len(self.values))
101 ret.append(" min: {0}".format(min(self.values))) 104 ret.append(self.min())
102 ret.append(" max: {0}".format(max(self.values))) 105 ret.append(self.max())
103 ret.append(" avg: {0}".format(sum(self.values) / len(self.values))) 106 ret.append(self.avg())
104 if self.histogram: 107 ret = [str(x) for x in ret]
105 ret.append(str(self.histogram)) 108 return ",".join(ret)
106 return "\n".join(ret) 109 else:
110 ret = [self.key]
111 ret.append(" len: {0}".format(len(self.values)))
112 if len(self.values) > 0:
113 ret.append(" min: {0}".format(self.min()))
114 ret.append(" max: {0}".format(self.max()))
115 ret.append(" avg: {0}".format(self.avg()))
116 if self.histogram:
117 ret.append(str(self.histogram))
118 return "\n".join(ret)
107 119
108 def __repr__(self): 120 def __repr__(self):
109 return "<Category: {0}>".format(self.key) 121 return "<Category: {0}>".format(self.key)
110 122
111 123
112 def make_key_func(cmp_metric): 124 def make_key_func(cmp_metric):
113 def key_func(a): 125 def key_func(a):
114 return getattr(a, cmp_metric)() 126 return getattr(a, cmp_metric)()
115 return key_func 127 return key_func
116 128
(...skipping 19 matching lines...) Expand all
136 action='store_true', 148 action='store_true',
137 help='omit empty histogram buckets') 149 help='omit empty histogram buckets')
138 parser.add_argument('--no-histogram', dest='histogram', 150 parser.add_argument('--no-histogram', dest='histogram',
139 action='store_false', help='do not print histogram') 151 action='store_false', help='do not print histogram')
140 parser.set_defaults(histogram=True) 152 parser.set_defaults(histogram=True)
141 parser.set_defaults(histogram_omit_empty=False) 153 parser.set_defaults(histogram_omit_empty=False)
142 parser.add_argument('--rank', metavar='<no|min|max|avg>', 154 parser.add_argument('--rank', metavar='<no|min|max|avg>',
143 type=str, nargs='?', 155 type=str, nargs='?',
144 default="no", 156 default="no",
145 help="rank keys by metric (default: no)") 157 help="rank keys by metric (default: no)")
158 parser.add_argument('--csv', dest='csv',
159 action='store_true', help='provide output as csv')
146 args = parser.parse_args() 160 args = parser.parse_args()
147 161
148 histogram = None 162 histogram = None
149 if args.histogram: 163 if args.histogram:
150 bucket_trait = None 164 bucket_trait = None
151 if args.histogram_type == "log2": 165 if args.histogram_type == "log2":
152 bucket_trait = Log2Bucket(args.log2_histogram_init_bucket) 166 bucket_trait = Log2Bucket(args.log2_histogram_init_bucket)
153 else: 167 else:
154 bucket_trait = LinearBucket(args.linear_histogram_granularity) 168 bucket_trait = LinearBucket(args.linear_histogram_granularity)
155 histogram = Histogram(bucket_trait, not args.histogram_omit_empty) 169 histogram = Histogram(bucket_trait, not args.histogram_omit_empty)
156 170
157 categories = [ Category(key, deepcopy(histogram)) 171 categories = [ Category(key, deepcopy(histogram), args.csv)
158 for key in args.keys ] 172 for key in args.keys ]
159 173
160 while True: 174 while True:
161 line = stdin.readline() 175 line = stdin.readline()
162 if not line: 176 if not line:
163 break 177 break
164 obj = split_nvp(line) 178 obj = split_nvp(line)
165 for category in categories: 179 for category in categories:
166 category.process_entry(obj) 180 category.process_entry(obj)
167 181
168 if args.rank != "no": 182 if args.rank != "no":
169 categories = sorted(categories, key=make_key_func(args.rank), reverse=True) 183 categories = sorted(categories, key=make_key_func(args.rank), reverse=True)
170 184
171 for category in categories: 185 for category in categories:
172 print(category) 186 print(category)
173 187
174 188
175 if __name__ == '__main__': 189 if __name__ == '__main__':
176 main() 190 main()
OLDNEW
« no previous file with comments | « no previous file | tools/eval_gc_time.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698