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


Python resource.RUSAGE_SELF属性代码示例

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


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

示例1: print_used_time

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def print_used_time(func):
        ''' 打印运行时间

        :param func: 运行的函数名称
        :return:
        '''

        @wraps(func)
        def wrapper(*args, **kwargs):
            start_time, start_resources = timestamp(), resource_usage(RUSAGE_SELF)
            func(*args, **kwargs)
            end_resources, end_time = resource_usage(RUSAGE_SELF), timestamp()
            print({'消耗时间': {'real': end_time - start_time,
                            'sys': end_resources.ru_stime - start_resources.ru_stime,
                            'user': end_resources.ru_utime - start_resources.ru_utime}})
            return True
        return wrapper 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:19,代码来源:__init__.py

示例2: _get_mem_usage

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def _get_mem_usage(self):
        """
        Gets the RUSAGE memory usage, returns in K. Encapsulates the difference
        between macOS and Linux rss reporting

        :returns: memory usage in kilobytes
        """

        from resource import getrusage, RUSAGE_SELF
        mem = getrusage(RUSAGE_SELF).ru_maxrss
        if sys.platform == 'darwin':
            # man 2 getrusage:
            #     ru_maxrss
            # This is the maximum resident set size utilized (in bytes).
            return mem / 1024  # Kb
        else:
            # linux
            # man 2 getrusage
            #        ru_maxrss (since Linux 2.6.32)
            #  This is the maximum resident set size used (in kilobytes).
            return mem  # Kb 
开发者ID:holzschu,项目名称:python3_ios,代码行数:23,代码来源:helper.py

示例3: update

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def update(self):
            """
            Get memory metrics of current process through `getrusage`.  Only
            available on Unix, on Linux most of the fields are not set,
            and on BSD units are used that are not very helpful, see:

            http://www.perlmonks.org/?node_id=626693

            Furthermore, getrusage only provides accumulated statistics (e.g.
            max rss vs current rss).
            """
            usage = getrusage(RUSAGE_SELF)
            self.rss = usage.ru_maxrss * 1024
            self.data_segment = usage.ru_idrss * 1024 # TODO: ticks?
            self.shared_segment = usage.ru_ixrss * 1024 # TODO: ticks?
            self.stack_segment = usage.ru_isrss * 1024 # TODO: ticks?
            self.vsz = self.data_segment + self.shared_segment + \
                       self.stack_segment

            self.pagefaults = usage.ru_majflt
            return self.rss != 0 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:23,代码来源:process.py

示例4: get_cpu_consumption

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def get_cpu_consumption():
    global daemon_start
    if os.name == 'nt':
        return 0
    # Some special unix maybe?
    try:
        from resource import getrusage, RUSAGE_SELF
    except ImportError:
        return 0
    now = time.time()
    # Maybe we did get back in time?
    if now < daemon_start:
        daemon_start = now
    diff = now - daemon_start
    if diff == 0:
        return 0
    rusage = getrusage(RUSAGE_SELF)
    current_cpu_time = rusage.ru_utime + rusage.ru_stime
    return 100 * current_cpu_time / diff


############# String diffs 
开发者ID:naparuba,项目名称:opsbro,代码行数:24,代码来源:util.py

示例5: memory_monitor

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def memory_monitor(command_queue: Queue, poll_interval=1):
    tracemalloc.start()
    old_max = 0
    snapshot = None
    while True:
        try:
            command_queue.get(timeout=poll_interval)
            if snapshot is not None:
                print(datetime.now())
                display_top(snapshot)

            return
        except Empty:
            max_rss = getrusage(RUSAGE_SELF).ru_maxrss
            if max_rss > old_max:
                old_max = max_rss
            snapshot = tracemalloc.take_snapshot()
            display_top(snapshot, limit=1)
            print(datetime.now(), 'max RSS', old_max) 
开发者ID:automl,项目名称:Auto-PyTorch,代码行数:21,代码来源:mem_test_thread.py

示例6: _get_memory_usage_MB_

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def _get_memory_usage_MB_():
    """
    Return the maximum memory use of this Python process in MB
    """
    to_MB = 1024.
    if platform == 'darwin':
        to_MB *= to_MB
    return getrusage(RUSAGE_SELF).ru_maxrss / to_MB


#=========================================================================
# _get_io_blocksize_MB_
#========================================================================= 
开发者ID:NCAR,项目名称:PyReshaper,代码行数:15,代码来源:reshaper.py

示例7: self

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def self(level=logging.DEBUG):
    log.log(level, rusage(resource.RUSAGE_SELF)) 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:4,代码来源:usage.py

示例8: rusage

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def rusage(target=resource.RUSAGE_SELF):
    r = resource.getrusage(target)
    fmt = "rss = %0.03fM  user = %0.03f  sys = %0.03f"
    return fmt % (r.ru_maxrss / 1024.0, r.ru_utime, r.ru_stime) 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:6,代码来源:usage.py

示例9: memusage

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [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

示例10: _get_mem_usage

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def _get_mem_usage(self):
        from resource import getpagesize, getrusage, RUSAGE_SELF
        mem = getrusage(RUSAGE_SELF).ru_maxrss
        return mem * getpagesize() / 1024 / 1024 
开发者ID:holzschu,项目名称:python3_ios,代码行数:6,代码来源:check_imaging_leaks.py

示例11: init_objects_and_adjacency_records

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def init_objects_and_adjacency_records(self):
        print("Initializing the segmenter...")
        print("Max mem: {} GB".format(resource.getrusage(
            resource.RUSAGE_SELF).ru_maxrss / 1024 / 1024))
        obj_id = 0
        for row in range(self.img_height):
            for col in range(self.img_width):
                pixels = set([(row, col)])
                obj = Object(pixels, obj_id, self)
                self.objects[obj_id] = obj
                self.pixel2obj[(row, col)] = obj
                obj_id += 1

        for row in range(self.img_height):
            for col in range(self.img_width):
                obj1 = self.pixel2obj[(row, col)]
                for o, idx in zip(self.offsets, range(len(self.offsets))):
                    (i, j) = o
                    if (0 <= row + i < self.img_height and
                            0 <= col + j < self.img_width):
                        obj2 = self.pixel2obj[(row + i, col + j)]
                        arec = AdjacencyRecord(obj1, obj2, self, (row, col), idx)
                        self.adjacency_records[arec] = arec
                        obj1.adjacency_list[arec] = arec
                        obj2.adjacency_list[arec] = arec
                        if arec.merge_priority >= 0:
                            heappush(self.queue, (-arec.merge_priority, arec)) 
开发者ID:waldo-seg,项目名称:waldo,代码行数:29,代码来源:segmenter.py

示例12: _get_usage_info

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def _get_usage_info():
    rusage = getrusage(RUSAGE_SELF)
    curr_usage = rusage.ru_utime + rusage.ru_stime
    curr_time = time.time()
    return curr_usage, curr_time 
开发者ID:douban,项目名称:Kenshin,代码行数:7,代码来源:instrumentation.py

示例13: memusage

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def memusage( point = "") :
    usage = resource.getrusage( resource.RUSAGE_SELF) 
    return '''%s: usertime = %s systime = %s mem = %s mb
           '''%( point, usage[ 0 ], usage[ 1 ], 
                ( usage[ 2 ]*resource.getpagesize( ) ) /1000000.0 ) 
开发者ID:edwin-de-jong,项目名称:incremental-sequence-learning,代码行数:7,代码来源:train.py

示例14: generate_parsed_data

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def generate_parsed_data(self):

        # Get a rough idea of how much memory we have to play with
        CHECK_MEM_COUNT = 10000
        kb_free = _get_free_memory_kb()
        starting_maxrss = getrusage(RUSAGE_SELF).ru_maxrss
        check_memory_usage = True
        check_memory_count = 1

        for (comm, pid, cpu, line, data_str) in zip(self.comm_array, self.pid_array,
                                              self.cpu_array, self.line_array,
                                              self.data_array):
            data_dict = {"__comm": comm, "__pid": pid, "__cpu": cpu, "__line": line}
            data_dict.update(self.generate_data_dict(data_str))

            # When running out of memory, Pandas has been observed to segfault
            # rather than throwing a proper Python error.
            # Look at how much memory our process is using and warn if we seem
            # to be getting close to the system's limit, check it only once
            # in the beginning and then every CHECK_MEM_COUNT events
            check_memory_count -= 1
            if check_memory_usage and check_memory_count == 0:
                kb_used = (getrusage(RUSAGE_SELF).ru_maxrss - starting_maxrss)
                if kb_free and kb_used > kb_free * 0.9:
                    warnings.warn("TRAPpy: Appear to be low on memory. "
                                  "If errors arise, try providing more RAM")
                    check_memory_usage = False
                check_memory_count = CHECK_MEM_COUNT

            yield data_dict 
开发者ID:ARM-software,项目名称:trappy,代码行数:32,代码来源:base.py

示例15: install

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RUSAGE_SELF [as 别名]
def install(self):
        self.faults_at_start = get_fault_count(resource.RUSAGE_SELF)
        self.run_start_time = time.time()
        self.real_fork = os.fork
        os.fork = self.my_fork 
开发者ID:dw,项目名称:mitogen,代码行数:7,代码来源:fork_histogram.py


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