Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported 2017-06-29-ssdp tools to python 3 #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions 2017-06-29-ssdp/mmhistogram
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python2
#!/usr/bin/env python

import argparse
import itertools
import math
import statistics
import sys

parser = argparse.ArgumentParser(description='Print log-2 histogram, like systemtap')
Expand Down Expand Up @@ -31,10 +32,10 @@ M.sort(reverse=True)
totalcount = len(M)
minval = M[-1]
maxval = M[0]
avgval = sum(M) / float(len(M))
devval = math.sqrt(sum([(m - avgval)**2 for m in M]) / float(len(M)))
avgval = statistics.mean(M)
devval = statistics.stdev(M)
medval = statistics.median(M)

medval = M[len(M)/2]

KV = []

Expand Down Expand Up @@ -65,35 +66,41 @@ maxcount = float(max(c for _, _, c in KV))
maxbound = KV[-1][0]
boundl = max(len(str(maxbound)), len('value'))

print "%s min:%.2f avg:%.2f med=%.2f max:%.2f dev:%.2f count:%d" % (
print_values = "%s min:%.2f avg:%.2f med=%.2f max:%.2f dev:%.2f count:%d" % (
args.title,
minval,
avgval,
medval,
maxval,
devval,
totalcount,
totalcount
)
print "%s:" % (
print(print_values)

print_title = "%s:" % (
args.title,
)
print "%*s |%*s %s" % (
print(print_title)

print_column = "%*s |%*s %s" % (
boundl+1,
"value",
args.columns,
"-" * args.columns,
"count"
)
print(print_column)

for boundb, bound, c in KV:
if args.percentage:
cp = "%5.2f%%" % ((c / float(totalcount))*100.0,)
else:
cp = "%d" % (c,)
print "%*d |%*s %s" % (
print_bound = "%*d |%*s %s" % (
boundl + 1,
boundb,
args.columns,
"*" * int(args.columns * (c/maxcount)),
cp
)
print(print_bound)
2 changes: 1 addition & 1 deletion 2017-06-29-ssdp/mmsum
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ s = 0
for line in sys.stdin:
s += float(line)

print s
print(s)