Skip to content

Commit

Permalink
add jmap histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
devwebcl committed Jun 25, 2018
1 parent 71f170e commit 6e5dae9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions oql/JDatta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python
import sys
import operator

# The histogram file path should be given in argument
# The file should have two columns, key and value
# Each line in the histogram file should contain the key
# then a space and then the value
# The following code would sum the values against the same
# key and print the result in descending order

f = open(sys.argv[1]) # Open the histogram file

# Create histogram map
hist = {}
for line in f:
line = line.strip()
if line == "":
continue
fields = line.split()
mtype = fields[0].strip()
mval = fields[1].strip()

if mtype in hist:
hist[mtype] = hist[mtype] + int(mval)
else:
# print ">>>" + mval
hist[mtype] = int(mval)

# Sort in descending order
sorted_hist = reversed(sorted(hist.items(), key=operator.itemgetter(1)))

# print
for i in sorted_hist:
print i[1], "\t", i[0]

0 comments on commit 6e5dae9

Please sign in to comment.