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


Python gc.get_stats方法代码示例

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


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

示例1: test_get_stats

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def test_get_stats(self):
        stats = gc.get_stats()
        self.assertEqual(len(stats), 3)
        for st in stats:
            self.assertIsInstance(st, dict)
            self.assertEqual(set(st),
                             {"collected", "collections", "uncollectable"})
            self.assertGreaterEqual(st["collected"], 0)
            self.assertGreaterEqual(st["collections"], 0)
            self.assertGreaterEqual(st["uncollectable"], 0)
        # Check that collection counts are incremented correctly
        if gc.isenabled():
            self.addCleanup(gc.enable)
            gc.disable()
        old = gc.get_stats()
        gc.collect(0)
        new = gc.get_stats()
        self.assertEqual(new[0]["collections"], old[0]["collections"] + 1)
        self.assertEqual(new[1]["collections"], old[1]["collections"])
        self.assertEqual(new[2]["collections"], old[2]["collections"])
        gc.collect(2)
        new = gc.get_stats()
        self.assertEqual(new[0]["collections"], old[0]["collections"] + 1)
        self.assertEqual(new[1]["collections"], old[1]["collections"])
        self.assertEqual(new[2]["collections"], old[2]["collections"] + 1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_gc.py

示例2: collect

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def collect(self):
        collected = CounterMetricFamily(
            'python_gc_objects_collected',
            'Objects collected during gc',
            labels=['generation'],
        )
        uncollectable = CounterMetricFamily(
            'python_gc_objects_uncollectable',
            'Uncollectable object found during GC',
            labels=['generation'],
        )

        collections = CounterMetricFamily(
            'python_gc_collections',
            'Number of times this generation was collected',
            labels=['generation'],
        )

        for generation, stat in enumerate(gc.get_stats()):
            generation = str(generation)
            collected.add_metric([generation], value=stat['collected'])
            uncollectable.add_metric([generation], value=stat['uncollectable'])
            collections.add_metric([generation], value=stat['collections'])

        return [collected, uncollectable, collections] 
开发者ID:prometheus,项目名称:client_python,代码行数:27,代码来源:gc_collector.py

示例3: collect

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def collect(self):
        collected = CounterMetricFamily(
            f"{self.namespace}python_gc_objects_collected",
            "Objects collected during gc",
            labels=["generation"],
        )
        uncollectable = CounterMetricFamily(
            f"{self.namespace}python_gc_objects_uncollectable",
            "Uncollectable object found during GC",
            labels=["generation"],
        )

        collections = CounterMetricFamily(
            f"{self.namespace}python_gc_collections",
            "Number of times this generation was collected",
            labels=["generation"],
        )

        for generation, stat in enumerate(gc.get_stats()):
            generation = str(generation)
            collected.add_metric([generation], value=stat["collected"])
            uncollectable.add_metric([generation], value=stat["uncollectable"])
            collections.add_metric([generation], value=stat["collections"])

        return [collected, uncollectable, collections] 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:27,代码来源:gc.py

示例4: memusage

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def memusage(do_dump_rpy_heap=True, do_objgraph=True):
    # type: (Optional[bool], Optional[bool]) -> str
    """Returning a str of memory usage stats"""
    def trap_err(func, *args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:  # pragma: nocover
            # include both __str/repr__, sometimes one's useless
            buf.writelines([func.__name__, ': ', repr(e), ': ', str(e)])

    buf = StringIO()
    rusage = trap_err(resource.getrusage, resource.RUSAGE_SELF)
    buf.writelines([repr(rusage), '\n\n'])
    trap_err(pmap_extended, buf)
    trap_err(jemalloc_stats, buf)
    trap_err(glibc_malloc_info, buf)
    if hasattr(gc, 'get_stats'):
        buf.writelines(['\n\n', gc.get_stats(), '\n\n'])
    if do_dump_rpy_heap:
        # dump rpython's heap before objgraph potentially pollutes the
        # heap with its heavy workload
        trap_err(dump_rpy_heap, buf)
    trap_err(get_stats_asmmemmgr, buf)
    buf.write('\n\n')
    if do_objgraph:
        trap_err(objgraph.show_most_common_types, limit=0, file=buf)
    return buf.getvalue() 
开发者ID:mozilla-services,项目名称:autopush,代码行数:29,代码来源:memusage.py

示例5: run

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def run(self, args):

        print("Gxf %s - %s\n" % (gxf.__version__, gxf.__author__))

        gcstats = gc.get_stats()

        headers = ["generation", "collections", "collected", "uncollectable"]
        tbldata = [["gen %d" % i] + [s[h] for h in headers[1:]]
                   for i, s in enumerate(gcstats)]

        print("Garbage collector statistics:\n")
        print(tabulate.tabulate(tbldata, headers=headers)) 
开发者ID:wapiflapi,项目名称:gxf,代码行数:14,代码来源:meta.py

示例6: dev_memorysummary

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def dev_memorysummary(self):
        return {"stats": gc.get_stats()} 
开发者ID:gdassori,项目名称:spruned,代码行数:4,代码来源:jsonrpc_server.py

示例7: dev_collect

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def dev_collect(self):
        res = {
            "before": gc.get_stats()
        }
        gc.collect()
        res['after'] = gc.get_stats()
        return res 
开发者ID:gdassori,项目名称:spruned,代码行数:9,代码来源:jsonrpc_server.py

示例8: __init__

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def __init__(self, registry=REGISTRY):
        if not hasattr(gc, 'get_stats') or platform.python_implementation() != 'CPython':
            return
        registry.register(self) 
开发者ID:prometheus,项目名称:client_python,代码行数:6,代码来源:gc_collector.py

示例9: __init__

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def __init__(
        self, registry: CollectorRegistry, namespace: str = "", gc=gc
    ) -> None:
        if (
            not hasattr(gc, "get_stats")
            or platform.python_implementation() != "CPython"
        ):
            return
        if namespace:
            self.namespace = f"{namespace}_"
        registry.register(self) 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:13,代码来源:gc.py

示例10: report

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_stats [as 别名]
def report(self):
        # CPU
        if not runtime_info.OS_WIN:
            cpu_time = read_cpu_time()
            if cpu_time != None:
                cpu_time_metric = self.report_metric(Metric.TYPE_COUNTER, Metric.CATEGORY_CPU, Metric.NAME_CPU_TIME, Metric.UNIT_NANOSECOND, cpu_time)
                if cpu_time_metric.has_measurement():
                    cpu_usage = (cpu_time_metric.measurement.value / (60 * 1e9)) * 100
                    try:
                        cpu_usage = cpu_usage / multiprocessing.cpu_count()
                    except Exception:
                        pass

                    self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_CPU, Metric.NAME_CPU_USAGE, Metric.UNIT_PERCENT, cpu_usage)


        # Memory
        if not runtime_info.OS_WIN:
            max_rss = read_max_rss()
            if max_rss != None:
                self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_MAX_RSS, Metric.UNIT_KILOBYTE, max_rss)

        if runtime_info.OS_LINUX:
            current_rss = read_current_rss()
            if current_rss != None:
                self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_CURRENT_RSS, Metric.UNIT_KILOBYTE, current_rss)

            vm_size = read_vm_size()
            if vm_size != None:
                self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_VM_SIZE, Metric.UNIT_KILOBYTE, vm_size)


        # GC stats
        gc_count0, gc_count1, gc_count2 = gc.get_count()
        total_gc_count = gc_count0 + gc_count1 + gc_count2
        self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_COUNT, Metric.UNIT_NONE, total_gc_count)

        if min_version(3, 4):
            gc_stats = gc.get_stats()
            if gc_stats and gc_stats[0] and gc_stats[1] and gc_stats[2]:
                total_collections = gc_stats[0]['collections'] + gc_stats[1]['collections'] + gc_stats[2]['collections']
                self.report_metric(Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTIONS, Metric.UNIT_NONE, total_collections)

                total_collected = gc_stats[0]['collected'] + gc_stats[1]['collected'] + gc_stats[2]['collected']
                self.report_metric(Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTED, Metric.UNIT_NONE, total_collected)

                total_uncollectable = gc_stats[0]['uncollectable'] + gc_stats[1]['uncollectable'] + gc_stats[2]['uncollectable']
                self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_UNCOLLECTABLE, Metric.UNIT_NONE, total_uncollectable)

        # Runtime
        thread_count = threading.active_count()
        self.report_metric(Metric.TYPE_STATE, Metric.CATEGORY_RUNTIME, Metric.NAME_THREAD_COUNT, Metric.UNIT_NONE, thread_count) 
开发者ID:stackimpact,项目名称:stackimpact-python,代码行数:54,代码来源:process_reporter.py


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