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
|
#!/usr/bin/python
import glob
import os
import shutil
def read_tis(fobj):
d = {}
for line in fobj:
freq, time = map(int, line.strip().split())
d[freq] = time
return d
def comp(f1, f2):
d1 = read_tis(open(f1))
d2 = read_tis(open(f2))
for k in sorted(d1):
v1 = d1[k]
v2 = d2[k]
print k, '+' + str(v2 - v1)
def main():
cpus = glob.glob("/sys/bus/cpu/devices/cpu*")
for cpu in cpus:
id = os.path.basename(cpu)
last = id + '_time_in_state'
tis = os.path.join(cpu, "cpufreq/stats/time_in_state")
if os.path.exists(last):
print id
comp(last, tis)
shutil.copyfile(tis, last)
print
if __name__ == '__main__':
main()
|