Last active
March 28, 2017 13:15
-
-
Save jettero/a810368e81dc64a4d566720410b84121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__virtualname__ = 'profile' | |
tabulate = None | |
# tabulate is this: | |
# https://github.com/gregbanks/python-tabulate/blob/master/tabulate.py | |
# I usually just copy it into my _modules and/or _output directories along side | |
# items like this | |
def __virtual__(): | |
try: | |
global tabulate | |
from tabulate import tabulate | |
return True | |
except: | |
return False | |
def _find_durations(data, name_max=60): | |
ret = [] | |
for host in data: | |
for sid in data[host]: | |
dat = data[host][sid] | |
ts = sid.split('_|-') | |
mod = ts[0] | |
fun = ts[-1] | |
name = dat.get('name', dat.get('__id__')) | |
dur = float(data[host][sid].get('duration',-1)) | |
if name is None: | |
name = '<>' | |
if len(name) > name_max: | |
name = name[0:name_max-3] + '...' | |
ret.append( [dur, name, '{0}.{1}'.format(mod,fun)] ) | |
return [ x[1:] + x[0:1] for x in sorted(ret) ] | |
def output(data): | |
rows = _find_durations(data) | |
return tabulate(rows, headers=['name', 'mod.fun', 'duration (ms)'], tablefmt='postgres' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment