Commit 307cc458 authored by mlippautz's avatar mlippautz Committed by Commit bot

[tools] Incrementally keep track of GC NVP output

We not keep track of the histogram as we process values and do not wait until
printing the histogram. Furthermore processing the histogram is not O(n) for n
values.

BUG=

Review URL: https://codereview.chromium.org/1364733002

Cr-Commit-Position: refs/heads/master@{#30891}
parent 17f59878
...@@ -6,39 +6,57 @@ ...@@ -6,39 +6,57 @@
"""This script is used to analyze GCTracer's NVP output.""" """This script is used to analyze GCTracer's NVP output."""
from argparse import ArgumentParser from argparse import ArgumentParser
from copy import deepcopy
from gc_nvp_common import split_nvp from gc_nvp_common import split_nvp
from sys import stdin from sys import stdin
class Histogram: class Histogram:
def __init__(self, values, granularity): def __init__(self, granularity, fill_empty):
self.values = list(values) # copy over values
self.granularity = granularity self.granularity = granularity
self.histogram = {}
self.fill_empty = fill_empty
def add(self, key):
index = int(key / self.granularity)
if index not in self.histogram:
self.histogram[index] = 0
self.histogram[index] += 1
def __str__(self): def __str__(self):
ret = [] ret = []
values = list(self.values) # copy over values keys = self.histogram.keys()
min_value = 0 keys.sort()
while len(values) > 0: last = -self.granularity
max_value = min_value + self.granularity for key in keys:
sub = [x for x in self.values if x >= min_value and x < max_value] min_value = key * self.granularity
max_value = min_value + self.granularity
if self.fill_empty:
while (last + self.granularity) != min_value:
last += self.granularity
ret.append(" [{0},{1}[: {2}".format(
str(last), str(last + self.granularity), 0))
ret.append(" [{0},{1}[: {2}".format( ret.append(" [{0},{1}[: {2}".format(
str(min_value), str(max_value),len(sub))) str(min_value), str(max_value), self.histogram[key]))
min_value += self.granularity last = min_value
values = [x for x in values if x not in sub]
return "\n".join(ret) return "\n".join(ret)
class Category: class Category:
def __init__(self, key, histogram, granularity): def __init__(self, key, histogram):
self.key = key self.key = key
self.values = [] self.values = []
self.histogram = histogram self.histogram = histogram
self.granularity = granularity
def process_entry(self, entry): def process_entry(self, entry):
if self.key in entry: if self.key in entry:
self.values.append(float(entry[self.key])) self.values.append(float(entry[self.key]))
if self.histogram:
self.histogram.add(float(entry[self.key]))
def __str__(self): def __str__(self):
ret = [self.key] ret = [self.key]
...@@ -48,7 +66,7 @@ class Category: ...@@ -48,7 +66,7 @@ class Category:
ret.append(" max: {0}".format(max(self.values))) ret.append(" max: {0}".format(max(self.values)))
ret.append(" avg: {0}".format(sum(self.values) / len(self.values))) ret.append(" avg: {0}".format(sum(self.values) / len(self.values)))
if self.histogram: if self.histogram:
ret.append(str(Histogram(self.values, self.granularity))) ret.append(str(self.histogram))
return "\n".join(ret) return "\n".join(ret)
...@@ -59,6 +77,9 @@ def main(): ...@@ -59,6 +77,9 @@ def main():
parser.add_argument('--histogram-granularity', metavar='GRANULARITY', parser.add_argument('--histogram-granularity', metavar='GRANULARITY',
type=int, nargs='?', default=5, type=int, nargs='?', default=5,
help='histogram granularity (default: 5)') help='histogram granularity (default: 5)')
parser.add_argument('--no-histogram-print-empty', dest='histogram_print_empty',
action='store_false',
help='print empty histogram buckets')
feature_parser = parser.add_mutually_exclusive_group(required=False) feature_parser = parser.add_mutually_exclusive_group(required=False)
feature_parser.add_argument('--histogram', dest='histogram', feature_parser.add_argument('--histogram', dest='histogram',
action='store_true', action='store_true',
...@@ -67,9 +88,14 @@ def main(): ...@@ -67,9 +88,14 @@ def main():
action='store_false', action='store_false',
help='do not print histogram') help='do not print histogram')
parser.set_defaults(histogram=True) parser.set_defaults(histogram=True)
parser.set_defaults(histogram_print_empty=True)
args = parser.parse_args() args = parser.parse_args()
categories = [ Category(key, args.histogram, args.histogram_granularity) histogram = None
if args.histogram:
histogram = Histogram(args.histogram_granularity, args.histogram_print_empty)
categories = [ Category(key, deepcopy(histogram))
for key in args.keys ] for key in args.keys ]
while True: while True:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment