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


Python Process.memory_info方法代码示例

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


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

示例1: trace_memory_usage

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
   def trace_memory_usage(self, frame, event, arg):
      """Callback for sys.settrace

      Args:
         frame: frame is the current stack frame
         event: event is a string: 'call', 'line', 'return', 'exception', 'c_call', 'c_return', or 'c_exception'
         arg: arg depends on the event type.

      Returns:
         function: wrap_func
      """
      if event in ('call', 'line', 'return') and frame.f_code in self.code_map:
         if event != 'call':
            # "call" event just saves the lineno but not the memory
            process = Process(getpid())
            mem = process.memory_info()[0] / float(2 ** 20)
            # if there is already a measurement for that line get the max
            old_mem = self.code_map[frame.f_code].get(self.prevline, 0)
            self.code_map[frame.f_code][self.prevline] = max(mem, old_mem)
         self.prevline = frame.f_lineno

      if self._original_trace_function is not None:
         self._original_trace_function(frame, event, arg)

      return self.trace_memory_usage
开发者ID:peter1000,项目名称:SpeedIT,代码行数:27,代码来源:LineMemoryProfileIT.py

示例2: __memory_watcher

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
 def __memory_watcher(self, data):
     max_memory = 0
     try:
         p = Process(data[0])
         memory = 1
         while 0 < memory and max_memory <= self.__mem_lim:
             if os_name.lower() == 'linux':
                 memory = p.memory_info()[0] - p.memory_info_ex().shared
             elif os_name.lower() == 'darwin':
                 memory = p.memory_info()[0]
             elif os_name.lower() == 'windows':
                 memory = p.memory_info_ex().private
             if max_memory < memory:
                 max_memory = memory
         data[1]()
     except NoSuchProcess:
         pass
     finally:
         data.append(max_memory)
开发者ID:CompLand,项目名称:Judger,代码行数:21,代码来源:judger.py

示例3: process_with_stats

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
def process_with_stats(name, stdin, times=1):
    if times > 1:
        results = []
        for _ in xrange(0, times):
            results.append(process_with_stats(name, stdin, 1))

        result = {'execution': reduce(lambda a, c:
                                      a+c['execution']/float(times),
                                      results, 0),
                  'memory': reduce(lambda a, c:
                                   max(a, c['memory']), results, 0),
                  'output': results[0]['output'],
                  'status': results[0]['status']}

        return result

    process = Popen(name, stdin=PIPE, stdout=PIPE, stderr=DEVNULL,
                    close_fds=True)
    process.stdin.write(stdin.getvalue())
    process.stdin.close()

    stats = Process(process.pid)

    memory_usage = stats.memory_info().rss
    while process.poll() is None:
        try:
            memory_usage = max(memory_usage, stats.memory_info().rss)
        except:
            memory_usage = 0
        sleep(1/1000.0)

    execution_time = time() - stats.create_time()
    output = process.stdout.read()

    if memory_usage == 0 and process.returncode == 0:
        return process_with_stats(name, stdin)

    return {'execution': execution_time,
            'memory': memory_usage,
            'output': output,
            'status': process.returncode}
开发者ID:alfanick,项目名称:sbh-alternating,代码行数:43,代码来源:sbh_benchmark.py

示例4: get_memory

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
def get_memory(pid):
    # return the memory usage in MB, psutil should be 4.0 version
    from psutil import Process, __version__

    # if __version__ < '4.0.0':
    #     raise Exception('psutil module should be 4.0.0 version at least.')

    if pid_exists(pid):
        process = Process(pid)
        # mem = process.memory_full_info().uss / float(1024*1024)
        mem = process.memory_info().rss / float(1024*1024)
        return mem
    return 0
开发者ID:28sui,项目名称:uliweb,代码行数:15,代码来源:workers.py

示例5: memory_usage

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
    def memory_usage(self):
        self._ensure_initialized()

        usage = 0
        agents = []

        for name, container in self._map_container_by_name().iteritems():
            info = self._docker.inspect_container(container)
            pid = info['State']['Pid']
            process = Process(pid)
            mem = process.memory_info()
            usage = usage + mem.rss
            agents.append({'name': name, 'memory_usage': mem.rss})

        avg = usage / len(agents) if len(agents) > 0 else 0

        return {'total_usage': usage, 'average_usage': avg, 'agents': agents}
开发者ID:vivekbsable,项目名称:pixelated-dispatcher,代码行数:19,代码来源:__init__.py

示例6: memory_usage

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
def memory_usage():
    "Return the memory usage of this process in MB."
    p = Process(getpid())
    return p.memory_info()[0] / 2**20
开发者ID:Ambier,项目名称:arsenal,代码行数:6,代码来源:sysutil.py

示例7: memory_usage

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import memory_info [as 别名]
 def memory_usage(self):
     p = Process(self._process.pid)
     mem = p.memory_info()
     return mem.rss
开发者ID:mmircea16,项目名称:pixelated-dispatcher,代码行数:6,代码来源:adapter.py


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