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


Python Process.get_memory_percent方法代码示例

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


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

示例1: update_process_list

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_memory_percent [as 别名]
def update_process_list():
    global PS
    plist = []
    for pid in psutil.get_pid_list():
        try:
            p = Process(pid)
            plist.append((p,p.get_cpu_percent(),p.get_memory_percent())) 
        except psutil.NoSuchProcess:
            continue
    # copy plist to PS
    PS = sorted(plist[:], key=lambda e: e[1] if e[1] > e[2] else e[2], reverse=True)[:25]
开发者ID:ViktorNova,项目名称:mod-ui,代码行数:13,代码来源:sysmond.py

示例2: _on_server

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_memory_percent [as 别名]
    def _on_server(self, args):
        
        os.chdir(self.original_dir)
        abs_args_path = os.path.abspath(args.path)
        component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read()
        
        out = {
            'component_details': component_details,
            'component_full_path': abs_args_path,
            'component_host': current_host(),
            'component_running': False,
            'current_time': datetime.now().isoformat(),
            'current_time_utc': datetime.utcnow().isoformat(),
            'master_proc_connections': None,
            'master_proc_pid': None,
            'master_proc_name': None,
            'master_proc_create_time': None,
            'master_proc_create_time_utc': None,
            'master_proc_username': None,            
            'master_proc_workers_no': None,
            'master_proc_workers_pids': None,
        }

        master_proc_pid = self._zdaemon_command('status')
        master_proc_pid = master_proc_pid.values()
        if master_proc_pid and master_proc_pid[0]:
            out['component_running'] = True
            master_proc_pid = int(master_proc_pid[0])
            master_proc = Process(master_proc_pid)
            workers_pids = sorted(elem.pid for elem in master_proc.get_children())
            
            out['master_proc_connections'] = master_proc.get_connections()
            out['master_proc_pid'] = master_proc.pid
            out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time).isoformat()
            out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_proc.create_time, UTC).isoformat()
            out['master_proc_username'] = master_proc.username
            out['master_proc_name'] = master_proc.name
            out['master_proc_workers_no'] = len(workers_pids)
            out['master_proc_workers_pids'] = workers_pids
            
            for pid in workers_pids:
                worker = Process(pid)
                worker_memory_percent = worker.get_memory_percent()
                out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time).isoformat()
                out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time, UTC).isoformat()
                out['worker_{}_connections'.format(pid)] = worker.get_connections()
            
        if getattr(args, 'json', False):
            out['component_details'] = loads(out['component_details'])
            self.logger.info(dumps(out))
        else:
            cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH
            cols_width = (elem.strip() for elem in cols_width.split(','))
            cols_width = [int(elem) for elem in cols_width]
            
            table = Texttable()
            table.set_cols_width(cols_width)
            
            # Use text ('t') instead of auto so that boolean values don't get converted into ints
            table.set_cols_dtype(['t', 't']) 
            
            rows = [['Key', 'Value']]
            rows.extend(sorted(out.items()))
            
            table.add_rows(rows)
            
            self.logger.info(table.draw())
开发者ID:barowski,项目名称:zato,代码行数:69,代码来源:info.py

示例3: get_info

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_memory_percent [as 别名]
def get_info(process=None, interval=0):
    """Return information about a process.

    If process is None, will return the information about the current process
    """
    if process is None:
        process = Process(os.getpid())

    info = {}
    try:
        mem_info = process.get_memory_info()
        info['mem_info1'] = bytes2human(mem_info[0])
        info['mem_info2'] = bytes2human(mem_info[1])
    except AccessDenied:
        info['mem_info1'] = info['mem_info2'] = "N/A"

    try:
        info['cpu'] = process.get_cpu_percent(interval=interval)
    except AccessDenied:
        info['cpu'] = "N/A"

    try:
        info['mem'] = round(process.get_memory_percent(), 1)
    except AccessDenied:
        info['mem'] = "N/A"

    try:
        cpu_times = process.get_cpu_times()
        ctime = timedelta(seconds=sum(cpu_times))
        ctime = "%s:%s.%s" % (ctime.seconds // 60 % 60,
                        str((ctime.seconds % 60)).zfill(2),
                        str(ctime.microseconds)[:2])
    except AccessDenied:
        ctime = "N/A"

    info['ctime'] = ctime

    try:
        info['pid'] = process.pid
    except AccessDenied:
        info['pid'] = 'N/A'

    try:
        info['username'] = process.username
    except AccessDenied:
        info['username'] = 'N/A'

    try:
        info['nice'] = process.nice
    except AccessDenied:
        info['nice'] = 'N/A'
    except NoSuchProcess:
        info['nice'] = 'Zombie'

    try:
        cmdline = os.path.basename(shlex.split(process.cmdline[0])[0])
    except (AccessDenied, IndexError):
        cmdline = "N/A"

    info['cmdline'] = cmdline

    info['children'] = []
    for child in process.get_children():
        info['children'].append(get_info(child, interval=interval))

    return info
开发者ID:kuzmich,项目名称:circus,代码行数:68,代码来源:util.py

示例4: __init__

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_memory_percent [as 别名]

#.........这里部分代码省略.........
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:
                data = {field: self.caches[key][FIELD_VALUE][field] for field in fields if field in self.caches[key][FIELD_VALUE]}
                return 1, data
            else:
                return 0, None
        else:
            return 0, None
            
    def hgetall(self, key):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:
                return 1, self.caches[key][FIELD_VALUE]
            else:
                return 0, None
        else:
            return 0, None

    def hexists(self, key, field):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:
                #print self.caches[key][FIELD_VALUE], field
                if field in self.caches[key][FIELD_VALUE]:
                    return 1, 1
                else:
                    return 1, 0
            else:
                return 0, None
        else:
            return 0, None

    def hlen(self, key):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:
                return 1, len(self.caches[key][FIELD_VALUE])
            else:
                return 0, None
        else:
            return 0, None

    def hdel(self, key, fields):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:
                for field in fields:
                    try:
                        del self.caches[key][FIELD_VALUE][field]
                    except KeyError:
                        pass

                return 1, None
            else:
                return 0, None
        else:
            return 0, None

    def hkeys(self, key):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:

                return 1, self.caches[key][FIELD_VALUE].keys()
            else:
                return 0, None
        else:
            return 0, None

    def hvals(self, key):
        if key in self.caches:
            if self.caches[key][FIELD_TYPE] == HASH_TYPE:

                return 1, self.caches[key][FIELD_VALUE].values()
            else:
                return 0, None
        else:
            return 0, None

    def get_status(self):
        from pycached import __version__
        status = {
            'last_cmd_time': self.last_cmd_time,
            'cmd_version': self.version,
            'uptime_in_seconds': int(time.time() - self.start_time),
            'process_id': self.process.pid,
            'pycached_version': __version__,
            'key_size': len(self.caches),
            'next_save_key_size': len(self.keys),
            'next_del_key_size': len(self.delkeys),
            'expire_key_size': len(self.expirekeys),
            'save_time': self.savetime,
            'threads': self.process.get_num_threads(),
            'used_memory': self.process.get_ext_memory_info().rss,
            'used_memory_peak':self.process.get_ext_memory_info().vms,
            'memory_percent': "%0.4f" % self.process.get_memory_percent(),

            #'used_cpu': cpu_percent(),
        }

        return status

    def change_version(self):
        self.last_cmd_time = int(time.time())
        self.version = ''.join(random.sample(string.ascii_letters, 16))
开发者ID:eicesoft,项目名称:pycached,代码行数:104,代码来源:memory.py


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