[tools] Compute percentiles for GC NVP

R=hpayer@chromium.org
NOTRY=true
BUG=

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

Cr-Commit-Position: refs/heads/master@{#35354}
This commit is contained in:
Michael Lippautz 2016-04-08 14:04:54 +02:00
parent 47cce8d6ed
commit 77f3c5efad
2 changed files with 34 additions and 3 deletions

View File

@ -10,7 +10,7 @@
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 math import ceil,log
from sys import stdin from sys import stdin
@ -74,11 +74,12 @@ class Histogram:
class Category: class Category:
def __init__(self, key, histogram, csv): def __init__(self, key, histogram, csv, percentiles):
self.key = key self.key = key
self.values = [] self.values = []
self.histogram = histogram self.histogram = histogram
self.csv = csv self.csv = csv
self.percentiles = percentiles
def process_entry(self, entry): def process_entry(self, entry):
if self.key in entry: if self.key in entry:
@ -100,6 +101,16 @@ class Category:
def empty(self): def empty(self):
return len(self.values) == 0 return len(self.values) == 0
def _compute_percentiles(self):
ret = []
if len(self.values) == 0:
return ret
sorted_values = sorted(self.values)
for percentile in self.percentiles:
index = int(ceil((len(self.values) - 1) * percentile / 100))
ret.append(" {0}%: {1}".format(percentile, sorted_values[index]))
return ret
def __str__(self): def __str__(self):
if self.csv: if self.csv:
ret = [self.key] ret = [self.key]
@ -118,6 +129,8 @@ class Category:
ret.append(" avg: {0}".format(self.avg())) ret.append(" avg: {0}".format(self.avg()))
if self.histogram: if self.histogram:
ret.append(str(self.histogram)) ret.append(str(self.histogram))
if self.percentiles:
ret.append("\n".join(self._compute_percentiles()))
return "\n".join(ret) return "\n".join(ret)
def __repr__(self): def __repr__(self):
@ -160,6 +173,9 @@ def main():
help="rank keys by metric (default: no)") help="rank keys by metric (default: no)")
parser.add_argument('--csv', dest='csv', parser.add_argument('--csv', dest='csv',
action='store_true', help='provide output as csv') action='store_true', help='provide output as csv')
parser.add_argument('--percentiles', dest='percentiles',
type=str, default="",
help='comma separated list of percentiles')
args = parser.parse_args() args = parser.parse_args()
histogram = None histogram = None
@ -171,7 +187,14 @@ def main():
bucket_trait = LinearBucket(args.linear_histogram_granularity) bucket_trait = LinearBucket(args.linear_histogram_granularity)
histogram = Histogram(bucket_trait, not args.histogram_omit_empty) histogram = Histogram(bucket_trait, not args.histogram_omit_empty)
categories = [ Category(key, deepcopy(histogram), args.csv) percentiles = []
for percentile in args.percentiles.split(','):
try:
percentiles.append(float(percentile))
except ValueError:
pass
categories = [ Category(key, deepcopy(histogram), args.csv, percentiles)
for key in args.keys ] for key in args.keys ]
while True: while True:

View File

@ -17,6 +17,7 @@ print_usage_and_die() {
echo " -c|--csv provide csv output" echo " -c|--csv provide csv output"
echo " -f|--file FILE profile input in a file" echo " -f|--file FILE profile input in a file"
echo " (default: stdin)" echo " (default: stdin)"
echo " -p|--percentiles comma separated percentiles"
exit 1 exit 1
} }
@ -25,6 +26,7 @@ RANK_MODE=max
TOP_LEVEL=no TOP_LEVEL=no
CSV="" CSV=""
LOGFILE=/dev/stdin LOGFILE=/dev/stdin
PERCENTILES=""
while [[ $# -ge 1 ]] while [[ $# -ge 1 ]]
do do
@ -60,6 +62,10 @@ do
LOGFILE=$2 LOGFILE=$2
shift shift
;; ;;
-f|--percentiles)
PERCENTILES="--percentiles=$2"
shift
;;
*) *)
break break
;; ;;
@ -145,6 +151,7 @@ case $OP in
--no-histogram \ --no-histogram \
--rank $RANK_MODE \ --rank $RANK_MODE \
$CSV \ $CSV \
$PERCENTILES \
${INTERESTING_NEW_GEN_KEYS} ${INTERESTING_NEW_GEN_KEYS}
;; ;;
old-gen-rank) old-gen-rank)
@ -153,6 +160,7 @@ case $OP in
--no-histogram \ --no-histogram \
--rank $RANK_MODE \ --rank $RANK_MODE \
$CSV \ $CSV \
$PERCENTILES \
${INTERESTING_OLD_GEN_KEYS} ${INTERESTING_OLD_GEN_KEYS}
;; ;;
*) *)