コード例 #1
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,
    }
コード例 #2
0
    def get_configs(self):

        configs = {}
        for name, default in self.configs.items():
            cls = default.__class__
            path = self.paths[name]
            if os.path.exists(path):
                try:
                    configs[name] = self._PARSERS[cls](fileops.read(path))
                except IOError as e:
                    if e.errno == errno.EOPNOTSUPP:
                        pass
                    else:
                        raise
        return configs
コード例 #3
0
ファイル: cgroup.py プロジェクト: rkasdf/cgrouputils
    def get_configs(self):

        configs = {}
        for name, default in self.configs.items():
            cls = default.__class__
            path = self.paths[name]
            if os.path.exists(path):
                try:
                    configs[name] = self._PARSERS[cls](fileops.read(path))
                except IOError as e:
                    if e.errno == errno.EOPNOTSUPP:
                        pass
                    else:
                        raise
        return configs
コード例 #4
0
 def get_configs(self):
     """
     It returns a name and a current value pairs of control files
     which are categorised in the configs group.
     """
     configs = {}
     for name, default in self.configs.items():
         cls = default.__class__
         path = self.paths[name]
         if os.path.exists(path):
             try:
                 configs[name] = self._PARSERS[cls](fileops.read(path))
             except IOError as 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
     return configs
コード例 #5
0
    def get_stats(self):

        stats = {}
        for name, cls in self.stats.items():
            path = self.paths[name]
            if os.path.exists(path):
                try:
                    stats[name] = self._PARSERS[cls](fileops.read(path))
                except IOError as e:
                    # XXX: we have to distinguish unexpected errors from the expected ones
                    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
                    if e.errno == errno.EIO:
                        # memory.kmem.slabinfo throws EIO until limit_in_bytes is set.
                        pass
                    else:
                        raise
        return stats
コード例 #6
0
ファイル: cgroup.py プロジェクト: rkasdf/cgrouputils
    def get_stats(self):

        stats = {}
        for name, cls in self.stats.items():
            path = self.paths[name]
            if os.path.exists(path):
                try:
                    stats[name] = self._PARSERS[cls](fileops.read(path))
                except IOError as e:
                    # XXX: we have to distinguish unexpected errors from the expected ones
                    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
                    if e.errno == errno.EIO:
                        # memory.kmem.slabinfo throws EIO until limit_in_bytes is set.
                        pass
                    else:
                        raise
        return stats
コード例 #7
0
ファイル: cgroup.py プロジェクト: peo3/cgroup-utils
 def get_configs(self):
     """
     It returns a name and a current value pairs of control files
     which are categorised in the configs group.
     """
     configs = {}
     for name, default in self.configs.items():
         cls = default.__class__
         path = self.paths[name]
         if os.path.exists(path):
             try:
                 configs[name] = self._PARSERS[cls](fileops.read(path))
             except IOError as 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
     return configs
コード例 #8
0
ファイル: event.py プロジェクト: novas0x2a/cgroup-utils
    def run(self, args):
        if len(args) == 0:
            self.parser.error("Less arguments: " + " ".join(args))

        if self.options.debug:
            print args

        target_file = args[0]

        if not os.path.exists(target_file):
            print "File not found: %s" % target_file
            sys.exit(1)

        target_name = os.path.basename(target_file)

        arguments = []
        if target_name in ["memory.usage_in_bytes", "memory.memsw.usage_in_bytes"]:
            self.parser.usage = "%%prog %s [options] <target_file> <threshold>" % self.NAME
            if len(args) < 2:
                self.parser.error("Less arguments: " + " ".join(args))

            if len(args) > 2:
                self.parser.error("Too many arguments: " + " ".join(args))
            threshold = args[1]

            if threshold[0] == "+":
                cur = long(fileops.read(target_file))
                threshold = threshold.replace("+", "")
                threshold = cur + self._parse_value(threshold)
            elif threshold[0] == "-":
                cur = long(fileops.read(target_file))
                threshold = threshold.replace("-", "")
                threshold = cur - self._parse_value(threshold)
            else:
                threshold = self._parse_value(threshold)

            if self.options.verbose:
                print "Threshold: %d (%s)" % (threshold, formatter.byte(threshold))

            arguments.append(threshold)

        elif target_name == "memory.oom_control":
            self.parser.usage = "%%prog %s [options] <target_file>" % self.NAME
            if len(args) != 1:
                self.parser.error("Too many arguments: " + " ".join(args))

        else:
            files = ", ".join(cgroup.EventListener.SUPPORTED_FILES)
            message = "Target file not supported: %s\n" % target_name
            message += "(Supported files: %s)" % files
            self.parser.error(message)

        cg = cgroup.get_cgroup(os.path.dirname(target_file))

        if self.options.verbose:
            self._show_memory_usage("Before", cg)

        pid = os.fork()
        if pid == 0:
            listener = cgroup.EventListener(cg, target_name)
            listener.register(arguments)

            # ret = listener.wait()
            listener.wait()
            os._exit(0)

        timed_out = False
        if self.options.timeout_seconds:
            remained = self.options.timeout_seconds
            while remained > 0:
                ret = os.waitpid(pid, os.WNOHANG)

                if ret != (0, 0):
                    break
                time.sleep(0.1)
                remained -= 0.1
            else:
                timed_out = True
                os.kill(pid, signal.SIGTERM)
        else:
            os.waitpid(pid, 0)

        if not os.path.exists(cg.fullpath):
            print ("The cgroup seems to have been removed.")
            sys.exit(1)

        if self.options.verbose:
            self._show_memory_usage("After", cg)

        if timed_out:
            if self.options.verbose:
                print ("Timed out")
            sys.exit(2)
        else:
            sys.exit(0)
コード例 #9
0
ファイル: event.py プロジェクト: tdrjnr/cgroup-utils
    def run(self):
        if not os.path.exists(self.args.target_file):
            print("File not found: %s" % self.args.target_file)
            sys.exit(1)
        target_file = self.args.target_file

        target_name = os.path.basename(target_file)

        arguments = []
        if target_name in [
                'memory.usage_in_bytes', 'memory.memsw.usage_in_bytes'
        ]:
            if not self.args.threshold:
                self.parser.error('Less arguments: ' + ' '.join(self.args))
            threshold = self.args.threshold

            if threshold[0] == '+':
                cur = long(fileops.read(target_file))
                threshold = threshold.replace('+', '')
                threshold = cur + self._parse_value(threshold)
            elif threshold[0] == '-':
                cur = long(fileops.read(target_file))
                threshold = threshold.replace('-', '')
                threshold = cur - self._parse_value(threshold)
            else:
                threshold = self._parse_value(threshold)

            if self.args.verbose:
                print("Threshold: %d (%s)" %
                      (threshold, formatter.byte(threshold)))

            arguments.append(threshold)

        elif target_name == 'memory.oom_control':
            if self.args.threshold:
                self.parser.error('Too many arguments: ' + ' '.join(self.args))

        elif target_name == 'memory.pressure_level':
            SUPPORTED_TERMS = ['low', 'medium', 'critical']
            if not self.args.threshold:
                self.parser.error('Less arguments: ' + ' '.join(self.args))
            if self.args.threshold not in SUPPORTED_TERMS:
                self.parser.error('Use one of %p' % SUPPORTED_TERMS)

            arguments.append(self.args.threshold)

        else:
            files = ', '.join(cgroup.EventListener.SUPPORTED_FILES)
            message = "Target file not supported: %s\n" % target_name
            message += "(Supported files: %s)" % files
            self.parser.error(message)

        cg = cgroup.get_cgroup(os.path.dirname(target_file))

        if self.args.verbose:
            self._show_memory_usage('Before', cg)

        pid = os.fork()
        if pid == 0:
            listener = cgroup.EventListener(cg, target_name)
            listener.register(arguments)

            # ret = listener.wait()
            listener.wait()
            os._exit(0)

        timed_out = False
        if self.args.timeout_seconds:
            remained = self.args.timeout_seconds
            while remained > 0:
                ret = os.waitpid(pid, os.WNOHANG)

                if ret != (0, 0):
                    break
                time.sleep(0.1)
                remained -= 0.1
            else:
                timed_out = True
                os.kill(pid, signal.SIGTERM)
        else:
            os.waitpid(pid, 0)

        if not os.path.exists(cg.fullpath):
            print('The cgroup seems to have been removed.')
            sys.exit(1)

        if self.args.verbose:
            self._show_memory_usage('After', cg)

        if timed_out:
            if self.args.verbose:
                print('Timed out')
            sys.exit(2)
        else:
            sys.exit(0)
コード例 #10
0
ファイル: event.py プロジェクト: chinpeng/cgroup-utils
    def run(self):
        if not os.path.exists(self.args.target_file):
            print("File not found: %s" % self.args.target_file)
            sys.exit(1)
        target_file = self.args.target_file

        target_name = os.path.basename(target_file)

        arguments = []
        if target_name in ['memory.usage_in_bytes', 'memory.memsw.usage_in_bytes']:
            if not self.args.threshold:
                self.parser.error('Less arguments: ' + ' '.join(self.args))
            threshold = self.args.threshold

            if threshold[0] == '+':
                cur = long(fileops.read(target_file))
                threshold = threshold.replace('+', '')
                threshold = cur + self._parse_value(threshold)
            elif threshold[0] == '-':
                cur = long(fileops.read(target_file))
                threshold = threshold.replace('-', '')
                threshold = cur - self._parse_value(threshold)
            else:
                threshold = self._parse_value(threshold)

            if self.args.verbose:
                print("Threshold: %d (%s)" % (threshold, formatter.byte(threshold)))

            arguments.append(threshold)

        elif target_name == 'memory.oom_control':
            if self.args.threshold:
                self.parser.error('Too many arguments: ' + ' '.join(self.args))

        elif target_name == 'memory.pressure_level':
            SUPPORTED_TERMS = ['low', 'medium', 'critical']
            if not self.args.threshold:
                self.parser.error('Less arguments: ' + ' '.join(self.args))
            if self.args.threshold not in SUPPORTED_TERMS:
                self.parser.error('Use one of %p' % SUPPORTED_TERMS)

            arguments.append(self.args.threshold)

        else:
            files = ', '.join(cgroup.EventListener.SUPPORTED_FILES)
            message = "Target file not supported: %s\n" % target_name
            message += "(Supported files: %s)" % files
            self.parser.error(message)

        cg = cgroup.get_cgroup(os.path.dirname(target_file))

        if self.args.verbose:
            self._show_memory_usage('Before', cg)

        pid = os.fork()
        if pid == 0:
            listener = cgroup.EventListener(cg, target_name)
            listener.register(arguments)

            #ret = listener.wait()
            listener.wait()
            os._exit(0)

        timed_out = False
        if self.args.timeout_seconds:
            remained = self.args.timeout_seconds
            while remained > 0:
                ret = os.waitpid(pid, os.WNOHANG)

                if ret != (0, 0):
                    break
                time.sleep(0.1)
                remained -= 0.1
            else:
                timed_out = True
                os.kill(pid, signal.SIGTERM)
        else:
            os.waitpid(pid, 0)

        if not os.path.exists(cg.fullpath):
            print('The cgroup seems to have been removed.')
            sys.exit(1)

        if self.args.verbose:
            self._show_memory_usage('After', cg)

        if timed_out:
            if self.args.verbose:
                print('Timed out')
            sys.exit(2)
        else:
            sys.exit(0)