File: dstat_top_int.py

package info (click to toggle)
dstat 0.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,600 kB
  • sloc: python: 5,964; makefile: 70; sh: 3
file content (66 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download
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
### Author: Dag Wieers <dag@wieers.com>

class dstat_plugin(dstat):
    """
    Top interrupt

    Displays the name of the most frequent interrupt
    """
    def __init__(self):
        self.name = 'most frequent'
        self.vars = ('interrupt',)
        self.type = 's'
        self.width = 20
        self.scale = 0
        self.intset1 = [ ]
        self.open('/proc/stat')
        self.names = self.names()

    def names(self):
        ret = {}
        for line in dopen('/proc/interrupts'):
            l = line.split()
            if len(l) <= cpunr: continue
            l1 = l[0].split(':')[0]
            ### Cleanup possible names from /proc/interrupts
            l2 = ' '.join(l[cpunr+3:])
            l2 = l2.replace('_hcd:', '/')
            l2 = re.sub('@pci[:\d+\.]+', '', l2)
            l2 = re.sub('ahci\[[:\da-z\.]+\]', 'ahci', l2)
            ret[l1] = l2
        return ret

    def extract(self):
        self.output = ''
        self.val['total'] = 0.0
        for line in self.splitlines():
            if line[0] == 'intr':
                self.intset2 = [ int(i) for i in line[3:] ]

        if not self.intset1:
            self.intset1 = [ 0 for i in self.intset2 ]

        for i in range(len(self.intset2)):
            try:
                total = (self.intset2[i] - self.intset1[i]) * 1.0 / elapsed
            except IndexError:
                continue

            ### Put the highest value in self.val
            if total > self.val['total']:
                if str(i+1) in self.names:
                    self.val['name'] = self.names[str(i+1)]
                else:
                    self.val['name'] = 'int ' + str(i+1)
                self.val['total'] = total

        if step == op.delay:
            self.intset1 = self.intset2

        if self.val['total'] != 0.0:
            self.output = '%-15s%s' % (self.val['name'], cprint(self.val['total'], 'd', 5, 1000))

    def showcsv(self):
        return '%s / %f' % (self.val['name'], self.val['total'])

# vim:ts=4:sw=4:et