当前位置: 首页>>代码示例>>Python>>正文


Python SystemResourceMonitor.range_usage方法代码示例

本文整理汇总了Python中mozsystemmonitor.resourcemonitor.SystemResourceMonitor.range_usage方法的典型用法代码示例。如果您正苦于以下问题:Python SystemResourceMonitor.range_usage方法的具体用法?Python SystemResourceMonitor.range_usage怎么用?Python SystemResourceMonitor.range_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mozsystemmonitor.resourcemonitor.SystemResourceMonitor的用法示例。


在下文中一共展示了SystemResourceMonitor.range_usage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_phases

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]
    def test_phases(self):
        monitor = SystemResourceMonitor(poll_interval=0.25)

        monitor.start()
        time.sleep(1)

        with monitor.phase('phase1'):
            time.sleep(1)

            with monitor.phase('phase2'):
                time.sleep(1)

        monitor.stop()

        self.assertEqual(len(monitor.phases), 2)
        self.assertEqual(['phase2', 'phase1'], monitor.phases.keys())

        all = list(monitor.range_usage())
        data1 = list(monitor.phase_usage('phase1'))
        data2 = list(monitor.phase_usage('phase2'))

        self.assertGreater(len(all), len(data1))
        self.assertGreater(len(data1), len(data2))

        # This could fail if time.time() takes more than 0.1s. It really
        # shouldn't.
        self.assertAlmostEqual(data1[-1].end, data2[-1].end, delta=0.25)
开发者ID:afabbro,项目名称:gecko-dev,代码行数:29,代码来源:test_resource_monitor.py

示例2: test_empty

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]
    def test_empty(self):
        monitor = SystemResourceMonitor(poll_interval=2.0)
        monitor.start()
        monitor.stop()

        data = list(monitor.range_usage())
        self.assertEqual(len(data), 0)
开发者ID:afabbro,项目名称:gecko-dev,代码行数:9,代码来源:test_resource_monitor.py

示例3: test_basic

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]
    def test_basic(self):
        monitor = SystemResourceMonitor(poll_interval=0.5)

        monitor.start()
        time.sleep(3)

        monitor.stop()

        data = list(monitor.range_usage())
        self.assertGreater(len(data), 3)

        self.assertIsInstance(data[0], SystemResourceUsage)
开发者ID:afabbro,项目名称:gecko-dev,代码行数:14,代码来源:test_resource_monitor.py

示例4: BuildMonitor

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]

#.........这里部分代码省略.........
        # Choosing a proper value that is ideal for everyone is hard. We will
        # likely iterate on the logic until people are generally satisfied.
        # If a value is too low, the eventual warning produced does not carry
        # much meaning. If the threshold is too high, people may not see the
        # warning and the warning will thus be ineffective.
        excessive = swap_in > 512 * 1048576 or swap_out > 512 * 1048576
        return excessive, swap_in, swap_out

    @property
    def have_resource_usage(self):
        """Whether resource usage is available."""
        return self.resources.start_time is not None

    def record_resource_usage(self):
        """Record the resource usage of this build.

        We write a log message containing a high-level summary. We also produce
        a data structure containing the low-level resource usage information.
        This data structure can e.g. be serialized into JSON and saved for
        subsequent analysis.

        If no resource usage is available, None is returned.
        """
        if not self.have_resource_usage:
            return None

        cpu_percent = self.resources.aggregate_cpu_percent(phase=None,
            per_cpu=False)
        cpu_times = self.resources.aggregate_cpu_times(phase=None,
            per_cpu=False)
        io = self.resources.aggregate_io(phase=None)

        self._log_resource_usage('Overall system resources', 'resource_usage',
            self.end_time - self.start_time, cpu_percent, cpu_times, io)

        excessive, sin, sout = self.have_excessive_swapping()
        if excessive is not None and (sin or sout):
            sin /= 1048576
            sout /= 1048576
            self.log(logging.WARNING, 'swap_activity',
                {'sin': sin, 'sout': sout},
                'Swap in/out (MB): {sin}/{sout}')

        o = dict(
            version=1,
            start=self.start_time,
            end=self.end_time,
            duration=self.end_time - self.start_time,
            resources=[],
            cpu_percent=cpu_percent,
            cpu_times=cpu_times,
            io=io,
        )

        o['tiers'] = self.tiers.tiered_resource_usage()

        self.tiers.add_resource_fields_to_dict(o)

        for usage in self.resources.range_usage():
            cpu_percent = self.resources.aggregate_cpu_percent(usage.start,
                usage.end, per_cpu=False)
            cpu_times = self.resources.aggregate_cpu_times(usage.start,
                usage.end, per_cpu=False)

            entry = dict(
                start=usage.start,
                end=usage.end,
                virt=list(usage.virt),
                swap=list(usage.swap),
            )

            self.tiers.add_resources_to_dict(entry, start=usage.start,
                    end=usage.end)

            o['resources'].append(entry)

        return o

    def _log_resource_usage(self, prefix, m_type, duration, cpu_percent,
        cpu_times, io, extra_params={}):

        params = dict(
            duration=duration,
            cpu_percent=cpu_percent,
            io_reads=io.read_count,
            io_writes=io.write_count,
            io_read_bytes=io.read_bytes,
            io_write_bytes=io.write_bytes,
            io_read_time=io.read_time,
            io_write_time=io.write_time,
        )

        params.update(extra_params)

        message = prefix + ' - Wall time: {duration:.0f}s; ' \
            'CPU: {cpu_percent:.0f}%; ' \
            'Read bytes: {io_read_bytes}; Write bytes: {io_write_bytes}; ' \
            'Read time: {io_read_time}; Write time: {io_write_time}'

        self.log(logging.WARNING, m_type, params, message)
开发者ID:chenhequn,项目名称:gecko,代码行数:104,代码来源:building.py

示例5: test_no_data

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]
    def test_no_data(self):
        monitor = SystemResourceMonitor()

        data = list(monitor.range_usage())
        self.assertEqual(len(data), 0)
开发者ID:afabbro,项目名称:gecko-dev,代码行数:7,代码来源:test_resource_monitor.py

示例6: BuildMonitor

# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import range_usage [as 别名]

#.........这里部分代码省略.........

    def get_resource_usage(self):
        """ Produce a data structure containing the low-level resource usage information.

        This data structure can e.g. be serialized into JSON and saved for
        subsequent analysis.

        If no resource usage is available, None is returned.
        """
        if not self.have_resource_usage:
            return None

        cpu_percent = self.resources.aggregate_cpu_percent(phase=None, per_cpu=False)
        cpu_times = self.resources.aggregate_cpu_times(phase=None, per_cpu=False)
        io = self.resources.aggregate_io(phase=None)

        o = dict(
            version=3,
            argv=sys.argv,
            start=self.start_time,
            end=self.end_time,
            duration=self.end_time - self.start_time,
            resources=[],
            cpu_percent=cpu_percent,
            cpu_times=cpu_times,
            io=io,
            objects=self.build_objects,
        )

        o["tiers"] = self.tiers.tiered_resource_usage()

        self.tiers.add_resource_fields_to_dict(o)

        for usage in self.resources.range_usage():
            cpu_percent = self.resources.aggregate_cpu_percent(usage.start, usage.end, per_cpu=False)
            cpu_times = self.resources.aggregate_cpu_times(usage.start, usage.end, per_cpu=False)

            entry = dict(start=usage.start, end=usage.end, virt=list(usage.virt), swap=list(usage.swap))

            self.tiers.add_resources_to_dict(entry, start=usage.start, end=usage.end)

            o["resources"].append(entry)

        # If the imports for this file ran before the in-tree virtualenv
        # was bootstrapped (for instance, for a clobber build in automation),
        # psutil might not be available.
        #
        # Treat psutil as optional to avoid an outright failure to log resources
        # TODO: it would be nice to collect data on the storage device as well
        # in this case.
        o["system"] = {}
        if psutil:
            o["system"].update(
                dict(
                    logical_cpu_count=psutil.cpu_count(),
                    physical_cpu_count=psutil.cpu_count(logical=False),
                    swap_total=psutil.swap_memory()[0],
                    vmem_total=psutil.virtual_memory()[0],
                )
            )

        return o

    def log_resource_usage(self, usage):
        """Summarize the resource usage of this build in a log message."""
开发者ID:subsevenx2001,项目名称:gecko-dev,代码行数:69,代码来源:building.py


注:本文中的mozsystemmonitor.resourcemonitor.SystemResourceMonitor.range_usage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。