-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfer-report
executable file
·105 lines (74 loc) · 2.79 KB
/
perfer-report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
import pprint as pprint
import time as time
import csv as csv
import sys as sys
import perfer as perfer
# Locally defined (maybe later to be put into module, with
# some surrounding functionality?
end="Command finish time (calculated)"
numberFields = (
perfer.wall,
perfer.userCpu,
perfer.sysCpu,
perfer.mem,
perfer.cacheio,
perfer.diskio,
perfer.swapout,
perfer.blockin,
perfer.blockout,
perfer.vcsw,
perfer.icsw,
perfer.start
)
#####
##### SUBROUTINES / OUTPUT / FORMATTING
#####
def perferReader(inputFile):
reader = csv.DictReader(inputFile)
dataPoints = []
for line in reader:
for number in numberFields:
# NOTE: Some of these are actually integers...
line[number] = float(line[number])
line[end] = line[perfer.start] + line[perfer.wall] # Calcuated, for convenience(?)
dataPoints.append(line)
return dataPoints
def topNaggregateMeasurements(data, variable, aggregateOn=perfer.cmd, N=5):
# After aggregating based on the specified variable, then:
# sort by the 'variable' being tested, to report the highest N values in that
# column.
aggCol = 0
dataCol = 1
valueCol = 0
countCol = 1
aggregate = {}
for datapoint in data:
agg = datapoint[aggregateOn]
thisAgg = aggregate.get(agg, (0.0, 0))
# Add the value for this datapoint to previous sum, starting at 0.0.
# Increment the counter for # of occurrences aggregated into this sum
aggregate[agg] = ( datapoint.get(variable) + thisAgg[valueCol], thisAgg[countCol] + 1)
output = list(aggregate.items())
output.sort(key=lambda datapoint: datapoint[dataCol][valueCol])
print("Programs using the most %s" % (variable))
print("total\t\tcount\t(avg)\taggregate")
# return output[(-1*(N)):]
for topAgg in output[(-1*N):]:
print("%f:\t%d\t(%f)\t%s" % (topAgg[dataCol][valueCol], topAgg[dataCol][countCol], topAgg[dataCol][valueCol] / topAgg[dataCol][countCol], topAgg[aggCol]))
def topNmeasurements(data, variable, N=5):
# sort by the 'variable' being tested, to report the highest N values in that
# column.
data.sort(key=lambda datapoint: datapoint[variable])
return data[(-1*N):]
if __name__ == "__main__":
reportOn = (perfer.userCpu, perfer.sysCpu, perfer.mem, perfer.blockin, perfer.blockout,)
data = perferReader(sys.stdin)
print("Individual processes using the most CPU")
measures = topNmeasurements(data, perfer.userCpu)
for measure in measures:
print("%f:\t%s" % (measure[perfer.userCpu], measure[perfer.cmd]))
print()
for report in reportOn:
print()
topNaggregateMeasurements(data, report)