Exemplo n.º 1
0
    def __init__(self, pid):
        self.pid = pid

        items = fileops.read('/proc/%d/stat' % pid).split(' ')
        self.name = items[1].lstrip('(').rstrip(')')
        self.state = items[2]
        self.ppid = int(items[3])
        self.pgid = int(items[4])
        self.sid = int(items[5])
        if not self.is_kthread():
            self.name = self._get_fullname()
            cmdline = fileops.read('/proc/%d/cmdline' % self.pid)
            self.cmdline = cmdline.rstrip('\0').replace('\0', ' ')
        else:
            self.cmdline = self.name

        if os.path.exists('/proc/%d/autogroup' % pid):
            autogroup = fileops.read('/proc/%d/autogroup' % pid)
        else:
            autogroup = None
        if autogroup:
            # Ex. "/autogroup-324 nice 0"
            self.autogroup = autogroup.split(' ')[0].replace('/', '')
        else:
            # kthreads don't belong to any autogroup
            self.autogroup = None
Exemplo n.º 2
0
class SubsystemCpu(Subsystem):
    NAME = 'cpu'
    _path_rt_period = '/proc/sys/kernel/sched_rt_period_us'
    _path_rt_runtime = '/proc/sys/kernel/sched_rt_runtime_us'
    STATS = {
        'stat': SimpleStat,
    }
    CONFIGS = {
        'shares':        1024,
        # Are the default values correct?
        'rt_period_us':  long(fileops.read(_path_rt_period)),
        'rt_runtime_us': long(fileops.read(_path_rt_runtime)),
        'cfs_period_us': 100000,
        'cfs_quota_us': -1,
    }
Exemplo n.º 3
0
    def _get_fullname(self):
        cmdline = fileops.read('/proc/%d/cmdline' % self.pid)
        if '\0' in cmdline:
            args = cmdline.rstrip('\0').split('\0')
            if ' ' in args[0]:
                name = args[0].split(' ')[0]
            else:
                name = args[0]
        else:
            #args = [cmdline,]
            args = cmdline.split(' ')
            name = args[0]

        if len(name) == 0:
            name = os.path.basename(' '.join(args[0:2]))
            return name

        if name[0] == '/':
            name = os.path.basename(name)
        name = name.rstrip(':')
        if len(args) >= 2:
            scripts = ['python', 'ruby', 'perl']
            # Want to catch /usr/bin/python1.7 ...
            if len([s for s in scripts if s in name]) > 0:
                name = os.path.basename(' '.join(args[0:2]))
        return name
Exemplo n.º 4
0
 def get_stats(self):
     """
     It returns a name and a value pairs of control files
     which are categorised in the stats group.
     """
     stats = {}
     for name, cls in self.stats.iteritems():
         path = self.paths[name]
         if os.path.exists(path):
             try:
                 stats[name] = self._PARSERS[cls](fileops.read(path))
             except IOError, e:
                 if e.errno == errno.EOPNOTSUPP:
                     # Since 3.5 memory.memsw.* are always created even if disabled.
                     # If disabled we will get EOPNOTSUPP when read or write them.
                     # See commit af36f906c0f4c2ffa0482ecdf856a33dc88ae8c5 of the kernel.
                     pass
                 else:
                     raise
Exemplo n.º 5
0
 def get_stats(self):
     """
     It returns a name and a value pairs of control files
     which are categorised in the stats group.
     """
     stats = {}
     for name, cls in self.stats.iteritems():
         path = self.paths[name]
         if os.path.exists(path):
             try:
                 stats[name] = self._PARSERS[cls](fileops.read(path))
             except IOError, e:
                 if e.errno == errno.EOPNOTSUPP:
                     # Since 3.5 memory.memsw.* are always created even if disabled.
                     # If disabled we will get EOPNOTSUPP when read or write them.
                     # See commit af36f906c0f4c2ffa0482ecdf856a33dc88ae8c5 of the kernel.
                     pass
                 else:
                     raise
Exemplo n.º 6
0
 def _get_fullname(self):
     cmdline = fileops.read('/proc/%d/cmdline' % self.pid)
     if '\0' in cmdline:
         args = cmdline.rstrip('\0').split('\0')
         if ' ' in args[0]:
             name = args[0].split(' ')[0]
         else:
             name = args[0]
     else:
         #args = [cmdline,]
         args = cmdline.split(' ')
         name = args[0]
     if name[0] == '/':
         name = os.path.basename(name)
     name = name.rstrip(':')
     if len(args) >= 2:
         scripts = ['python', 'ruby', 'perl']
         # Want to catch /usr/bin/python1.7 ...
         if len([s for s in scripts if s in name]) > 0:
             name = os.path.basename(' '.join(args[0:2]))
     return name
Exemplo n.º 7
0
 def get_online(self):
     if not os.path.exists('/sys/devices/system/node/'):
         return '0'
     else:
         return fileops.read('/sys/devices/system/node/online').strip()
Exemplo n.º 8
0
 def get_online(self):
     return fileops.read("/sys/devices/system/cpu/online").strip()
Exemplo n.º 9
0
 def cpu_count(self):
     return fileops.read('/proc/cpuinfo').count('processor')