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

Side by Side Diff: tools/eval_gc_nvp.py

Issue 1348763006: [tools] Add script to analyze GC tracing output (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """This script is used to analyze GCTracer's NVP output."""
8
9 from argparse import ArgumentParser
10 from gc_nvp_common import split_nvp
11 from sys import stdin
12
13 class Histogram:
14 def __init__(self, values, granularity):
15 self.values = list(values) # copy over values
16 self.granularity = granularity
17
18 def __str__(self):
19 ret = []
20 values = list(self.values) # copy over values
21 min_value = 0
22 while len(values) > 0:
23 max_value = min_value + self.granularity
24 sub = [x for x in self.values if x >= min_value and x < max_value]
25 ret.append(" [{0},{1}[: {2}".format(
26 str(min_value), str(max_value),len(sub)))
27 min_value += self.granularity
28 values = [x for x in values if x not in sub]
29 return "\n".join(ret)
30
31
32 class Category:
33 def __init__(self, key, histogram, granularity):
34 self.key = key
35 self.values = []
36 self.histogram = histogram
37 self.granularity = granularity
38
39 def process_entry(self, entry):
40 if self.key in entry:
41 self.values.append(float(entry[self.key]))
42
43 def __str__(self):
44 ret = [self.key]
45 ret.append(" len: {0}".format(len(self.values)))
46 if len(self.values) > 0:
47 ret.append(" min: {0}".format(min(self.values)))
48 ret.append(" max: {0}".format(max(self.values)))
49 ret.append(" avg: {0}".format(sum(self.values) / len(self.values)))
50 if self.histogram:
51 ret.append(str(Histogram(self.values, self.granularity)))
52 return "\n".join(ret)
53
54
55 def main():
56 parser = ArgumentParser(description="Process GCTracer's NVP output")
57 parser.add_argument('keys', metavar='KEY', type=str, nargs='+',
58 help='the keys (names) to process')
59 parser.add_argument('--histogram-granularity', metavar='GRANULARITY',
60 type=int, nargs='?', default=5,
61 help='histogram granularity (default: 5)')
62 feature_parser = parser.add_mutually_exclusive_group(required=False)
63 feature_parser.add_argument('--histogram', dest='histogram',
64 action='store_true',
65 help='print histogram')
66 feature_parser.add_argument('--no-histogram', dest='histogram',
67 action='store_false',
68 help='do not print histogram')
69 parser.set_defaults(histogram=True)
70 args = parser.parse_args()
71
72 categories = [ Category(key, args.histogram, args.histogram_granularity)
73 for key in args.keys ]
74
75 while True:
76 line = stdin.readline()
77 if not line:
78 break
79 obj = split_nvp(line)
80 for category in categories:
81 category.process_entry(obj)
82
83 for category in categories:
84 print(category)
85
86
87 if __name__ == '__main__':
88 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698