psutil

measure elapsed time, amount of memory and cpu used by the extern program

笑着哭i 提交于 2019-12-07 23:41:28
I'm executing an external program through Python. I want to know what is the best choice for calling the outside program, with subprocess.Popen() or with subprocess.call() . Also, I need to measure elapsed time, the amount of memory and CPU used by the external program. I've heard of psutil , but I don't really know which to choose. also I need to measure elapsed time, amount of memory and cpu used by the extern program (I'm going to assume you only need the information available in your platform's rusage . And, since Windows has no such thing at all, I'm also going to assume you don't care

psutil: Measuring the cpu usage of a specific process

孤街醉人 提交于 2019-12-07 03:30:56
问题 Im trying to measure the cpu usage of a process tree. Currently getting the cpu_usage of a process (without children) will do, but I'm getting weird results. import psutil p = psutil.Process(PID) p.cpu_percent gives me back float > 100 , how is that even possible? btw PID is the pid of something simple as def foo(): i = 0 while True: i += 1 which according to task manager its cpu usage is around 12% I want to get an output of 12.5 or something like that. 回答1: I read some documentation about

python psutil psutil.get_process_list() error

拥有回忆 提交于 2019-12-07 03:18:24
问题 Im trying to do some things with python psutil but get a strange error. procs = psutil.get_process_list() Gets me the following error: AttributeError: 'module' object has no attribute 'get_process_list' The only thing i found about it was this: https://github.com/giampaolo/psutil/issues/524 But no real solution besides pasting it to another directory (which I tried but is not working for me). Does anyone has a clue why I get this error? Great thanx in advance! 回答1: After checking the

Python监控服务器利器--psutil

喜欢而已 提交于 2019-12-06 03:28:29
服务器的监控通过安装一些常用的监控软件之外,有时也需要运行一些shell或Python脚本;shell下可以使用系统自带的ps/free/top/df等shell命令,Python可以调用subprocess等模块来运行shell命令,不过这么做就比较麻烦。这里有一个比较好用的第三方模块:psutil。   psutil是一个跨平台的库,用于在Python中检索有关运行进程和系统利用率(CPU,内存,磁盘,网络,传感器)的信息。它主要用于系统监视,分析,限制进程资源和运行进程的管理。它实现了UNIX命令行工具提供的许多功能,例如:ps,top,lsof,netstat,ifconfig,who,df,kill,free,nice,ionice,iostat,iotop,uptime,pidof,tty,taskset,pmap。 psutil目前支持以下平台: Linux Windows OSX, FreeBSD, OpenBSD, NetBSD Sun Solaris AIX ... 等装有Python2.6至3.6的32-bit和64-bit架构. 也可以在PyPy上运行。 安装 文中示例均在Python版本3.6环境下运行; # pip3 install psutil 常用模块 获取psutil版本信息 In [1]: import psutil In [2]: psutil

How to get the percentage of memory usage of a process?

跟風遠走 提交于 2019-12-05 22:10:31
问题 Using the following code, I can get the memory consumption of a give process in MiB: def memory_usage_psutil(): # return the memory usage in MB import psutil process = psutil.Process(os.getpid()) mem = process.get_memory_info()[0] / float(2 ** 20) return mem How can I change this to return the percentage of memory consumption? Update : I need to get the current value of %MEM column when executing the top command in terminal for a specific process. Example : I need this function to return 14.2

python 设置运行进程的CPU

☆樱花仙子☆ 提交于 2019-12-05 20:41:38
Nginx服务器会把自己的每个worker进程绑定到一个CPU上,以期减少进程间切换所带来的开销,最大限度利用多核框架。在实现上,使用Linux的sched_setaffinity()这个函数来实现。第三方库affinity封装了该函数,使得我们可以将python的进程绑定到指定的CPU上。 用法非常简单 affinity.get_process_affinity_mask(pid) #查看pid这个进程用了哪一个CPU affinity.set_process_affinity_mask(pid, 2L) #设置pid在2这个进程上运行 如果你的机器不是多核的,也就没有必要这么设置了,毕竟只有一个CPU。那么如何知道自己的机器有几颗CPU呢? #coding=utf-8 import psutil p = psutil.Process() pro_info = p.as_dict(attrs=['pid', 'name', 'username']) print psutil.cpu_count() psutil开源库,可以获取系统状态,通过它可以知晓机器的CPU个数 来源: CSDN 作者: 酷python 链接: https://blog.csdn.net/KWSY2008/article/details/52041768

python psutil psutil.get_process_list() error

穿精又带淫゛_ 提交于 2019-12-05 09:12:10
Im trying to do some things with python psutil but get a strange error. procs = psutil.get_process_list() Gets me the following error: AttributeError: 'module' object has no attribute 'get_process_list' The only thing i found about it was this: https://github.com/giampaolo/psutil/issues/524 But no real solution besides pasting it to another directory (which I tried but is not working for me). Does anyone has a clue why I get this error? Great thanx in advance! Anand S Kumar After checking the documentation here , I do not see a get_process_list() function in psutil, it has been deprecated

psutil: Measuring the cpu usage of a specific process

大兔子大兔子 提交于 2019-12-05 08:03:31
Im trying to measure the cpu usage of a process tree. Currently getting the cpu_usage of a process (without children) will do, but I'm getting weird results. import psutil p = psutil.Process(PID) p.cpu_percent gives me back float > 100 , how is that even possible? btw PID is the pid of something simple as def foo(): i = 0 while True: i += 1 which according to task manager its cpu usage is around 12% I want to get an output of 12.5 or something like that. I read some documentation about psutil and here is what I got: Note: a percentage > 100 is legitimate as it can result from a process with

psutil in Apache Spark

孤人 提交于 2019-12-05 03:23:50
I'm using PySpark 1.5.2. I got UserWarning Please install psutil to have better support with spilling after I issue the command .collect() Why is this warning showed? How can I install psutil ? pip install psutil If you need to install specifically for python 2 or 3, try using pip2 or pip3 ; it works for both major versions. Here is the PyPI package for psutil. y can clone or download the psutil project in the following link: https://github.com/giampaolo/psutil.git then run setup.py to install psutil in 'spark/python/pyspark/shuffle.py' y can see the following codes: def get_used_memory(): """

python模块之psutil详解

允我心安 提交于 2019-12-05 01:11:34
目录 python模块之psutil详解 简介 功能函数 CPU相关: 示例: Memory内存相关: 单位转换 Disk相关: Network相关: 进程管理 进程相关信息的方法: python模块之psutil详解 简介 psutil是一个开源切跨平台的库,其提供了便利的函数用来获取才做系统的信息,比如CPU,内存,磁盘,网络等。此外,psutil还可以用来进行进程管理,包括判断进程是否存在、获取进程列表、获取进程详细信息等。而且psutil还提供了许多命令行工具提供的功能,包括:ps,top,lsof,netstat,ifconfig, who,df,kill,free,nice,ionice,iostat,iotop,uptime,pidof,tty,taskset,pmap。 psutil是一个跨平台的库,在官方网站上查到其支持如下操作系统。 Linux Windows OSX FreeBSD OpenBSD NetBSD Sun Solaris AIX Works with Python versions from 2.6 to 3.X. psutil包含了异常、类、功能函数和常量,其中功能函数用来获取系统的信息,如CPU、磁盘、内存、网络等。类用来实现进程的管理功能 功能函数 根据函数的功能,主要分为CPU、磁盘、内存、网络几类