python查看cpu占用率的命令_运行python脚本后如何查找CPU使用率和内存使用率

I am working in python, I had a python script that reads the data from text file and saves in to database.

I got some requirement like to find below 3 points

1. Total execution time taken by the script for running

2. CPU utilization (For process performing by the python script)

3. Memory usage (For process performing by the python script)

For the first point i.e., i am finding the total execution time taken by the script to process(read the text file and saving in to database) as below

python -m cProfile script_that_runs_process.py

But i am unable to understand how to find the another two points ?

I googled and found some python module psutil , but i am confused and really don't know on how to implement the another two points with this....

Can anyone please let me know on how to find CPU Memory utilization, Memory Usage when a python script is runned(That performs certain task) ?

解决方案

Take a look at RunSnakeRun (homepage) for CPU profiling and meliae for memory profiling.

I've used RunSnakeRun before and am very happy with how it performs. It even processes the cProfile dump into a visual for you so you can easily see where your code is spending most of its time.

Meliae does the same thing for memory.

As for CPU usage, you might want to just hit top in the commandline (assuming a linux distro) and track your process to see how much of the CPU it's hogging

Hope this helps

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值