Commit a1b20e1d authored by mlippautz's avatar mlippautz Committed by Commit bot

[tools] Add capability of generating log2-based histograms to eval_gc_nvp.py

BUG=

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

Cr-Commit-Position: refs/heads/master@{#30949}
parent 4c64573d
...@@ -10,17 +10,47 @@ ...@@ -10,17 +10,47 @@
from argparse import ArgumentParser from argparse import ArgumentParser
from copy import deepcopy from copy import deepcopy
from gc_nvp_common import split_nvp from gc_nvp_common import split_nvp
from math import log
from sys import stdin from sys import stdin
class Histogram: class LinearBucket:
def __init__(self, granularity, fill_empty): def __init__(self, granularity):
self.granularity = granularity self.granularity = granularity
def value_to_bucket(self, value):
return int(value / self.granularity)
def bucket_to_range(self, bucket):
return (bucket * self.granularity, (bucket + 1) * self.granularity)
class Log2Bucket:
def __init__(self, start):
self.start = int(log(start, 2)) - 1
def value_to_bucket(self, value):
index = int(log(value, 2))
index -= self.start
if index < 0:
index = 0
return index
def bucket_to_range(self, bucket):
if bucket == 0:
return (0, 2 ** (self.start + 1))
bucket += self.start
return (2 ** bucket, 2 ** (bucket + 1))
class Histogram:
def __init__(self, bucket_trait, fill_empty):
self.histogram = {} self.histogram = {}
self.fill_empty = fill_empty self.fill_empty = fill_empty
self.bucket_trait = bucket_trait
def add(self, key): def add(self, key):
index = int(key / self.granularity) index = self.bucket_trait.value_to_bucket(key)
if index not in self.histogram: if index not in self.histogram:
self.histogram[index] = 0 self.histogram[index] = 0
self.histogram[index] += 1 self.histogram[index] += 1
...@@ -29,20 +59,17 @@ class Histogram: ...@@ -29,20 +59,17 @@ class Histogram:
ret = [] ret = []
keys = self.histogram.keys() keys = self.histogram.keys()
keys.sort() keys.sort()
last = -self.granularity last = keys[len(keys) - 1]
for key in keys: for i in range(0, last + 1):
min_value = key * self.granularity (min_value, max_value) = self.bucket_trait.bucket_to_range(i)
max_value = min_value + self.granularity if i == keys[0]:
keys.pop(0)
if self.fill_empty: ret.append(" [{0},{1}[: {2}".format(
while (last + self.granularity) != min_value: str(min_value), str(max_value), self.histogram[i]))
last += self.granularity else:
if self.fill_empty:
ret.append(" [{0},{1}[: {2}".format( ret.append(" [{0},{1}[: {2}".format(
str(last), str(last + self.granularity), 0)) str(min_value), str(max_value), 0))
ret.append(" [{0},{1}[: {2}".format(
str(min_value), str(max_value), self.histogram[key]))
last = min_value
return "\n".join(ret) return "\n".join(ret)
...@@ -73,27 +100,37 @@ class Category: ...@@ -73,27 +100,37 @@ class Category:
def main(): def main():
parser = ArgumentParser(description="Process GCTracer's NVP output") parser = ArgumentParser(description="Process GCTracer's NVP output")
parser.add_argument('keys', metavar='KEY', type=str, nargs='+', parser.add_argument('keys', metavar='KEY', type=str, nargs='+',
help='the keys (names) to process') help='the keys of NVPs to process')
parser.add_argument('--histogram-granularity', metavar='GRANULARITY', parser.add_argument('--histogram-type', metavar='<linear|log2>',
type=int, nargs='?', default=5, type=str, nargs='?', default="linear",
help='histogram granularity (default: 5)') help='histogram type to use (default: linear)')
parser.add_argument('--no-histogram-print-empty', dest='histogram_print_empty', linear_group = parser.add_argument_group('linear histogram specific')
action='store_false', linear_group.add_argument('--linear-histogram-granularity',
help='print empty histogram buckets') metavar='GRANULARITY', type=int, nargs='?',
feature_parser = parser.add_mutually_exclusive_group(required=False) default=5,
feature_parser.add_argument('--histogram', dest='histogram', help='histogram granularity (default: 5)')
action='store_true', log2_group = parser.add_argument_group('log2 histogram specific')
help='print histogram') log2_group.add_argument('--log2-histogram-init-bucket', metavar='START',
feature_parser.add_argument('--no-histogram', dest='histogram', type=int, nargs='?', default=64,
action='store_false', help='initial buck size (default: 64)')
help='do not print histogram') parser.add_argument('--histogram-omit-empty-buckets',
dest='histogram_omit_empty',
action='store_true',
help='omit empty histogram buckets')
parser.add_argument('--no-histogram', dest='histogram',
action='store_false', help='do not print histogram')
parser.set_defaults(histogram=True) parser.set_defaults(histogram=True)
parser.set_defaults(histogram_print_empty=True) parser.set_defaults(histogram_omit_empty=False)
args = parser.parse_args() args = parser.parse_args()
histogram = None histogram = None
if args.histogram: if args.histogram:
histogram = Histogram(args.histogram_granularity, args.histogram_print_empty) bucket_trait = None
if args.histogram_type == "log2":
bucket_trait = Log2Bucket(args.log2_histogram_init_bucket)
else:
bucket_trait = LinearBucket(args.linear_histogram_granularity)
histogram = Histogram(bucket_trait, not args.histogram_omit_empty)
categories = [ Category(key, deepcopy(histogram)) categories = [ Category(key, deepcopy(histogram))
for key in args.keys ] for key in args.keys ]
......
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