"Fossies" - the Fresh Open Source Software Archive 
Member "dstat-0.7.4/plugins/dstat_top_latency_avg.py" (17 Jan 2019, 2367 Bytes) of package /linux/privat/dstat-0.7.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "dstat_top_latency_avg.py" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
0.7.3_vs_0.7.4.
1 ### Dstat most expensive I/O process plugin
2 ### Displays the name of the most expensive I/O process
3 ###
4 ### Authority: dag@wieers.com
5
6 ### For more information, see:
7 ### http://eaglet.rain.com/rick/linux/schedstat/
8
9 class dstat_plugin(dstat):
10 def __init__(self):
11 self.name = 'highest average'
12 self.vars = ('latency process',)
13 self.type = 's'
14 self.width = 17
15 self.scale = 0
16 self.pidset1 = {}
17
18 def check(self):
19 if not os.access('/proc/self/schedstat', os.R_OK):
20 raise Exception('Kernel has no scheduler statistics [CONFIG_SCHEDSTATS], use at least 2.6.12')
21
22 def extract(self):
23 self.output = ''
24 self.pidset2 = {}
25 self.val['result'] = 0
26 for pid in proc_pidlist():
27 try:
28 ### Reset values
29 if pid not in self.pidset1:
30 self.pidset1[pid] = {'wait_ticks': 0, 'ran': 0}
31
32 ### Extract name
33 name = proc_splitline('/proc/%s/stat' % pid)[1][1:-1]
34
35 ### Extract counters
36 l = proc_splitline('/proc/%s/schedstat' % pid)
37 except IOError:
38 continue
39 except IndexError:
40 continue
41
42 if len(l) != 3: continue
43
44 self.pidset2[pid] = {'wait_ticks': int(l[1]), 'ran': int(l[2])}
45
46 if self.pidset2[pid]['ran'] - self.pidset1[pid]['ran'] > 0:
47 avgwait = (self.pidset2[pid]['wait_ticks'] - self.pidset1[pid]['wait_ticks']) * 1.0 / (self.pidset2[pid]['ran'] - self.pidset1[pid]['ran']) / elapsed
48 else:
49 avgwait = 0
50
51 ### Get the process that spends the most jiffies
52 if avgwait > self.val['result']:
53 self.val['result'] = avgwait
54 self.val['pid'] = pid
55 self.val['name'] = getnamebypid(pid, name)
56
57 if step == op.delay:
58 self.pidset1 = self.pidset2
59
60 if self.val['result'] != 0.0:
61 self.output = '%-*s%s' % (self.width-4, self.val['name'][0:self.width-4], cprint(self.val['result'], 'f', 4, 100))
62
63 ### Debug (show PID)
64 # self.output = '%*s %-*s' % (5, self.val['pid'], self.width-6, self.val['name'])
65
66 def showcsv(self):
67 return '%s / %.4f' % (self.val['name'], self.val['result'])
68
69 # vim:ts=4:sw=4:et