运行python脚本后如何查找CPU使用率和内存使用率 [英] How to find CPU utilization and memory usage after running a python script

查看:348
本文介绍了运行python脚本后如何查找CPU使用率和内存使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中工作,我有一个python脚本,可以从文本文件中读取数据并将其保存到数据库中.

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

我有一些要求要低于3分

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

但是我不明白如何找到另外两点? 我用Google搜索并找到了一些python模块 psutil ,但是我很困惑,真的不知道如何用这实现另外两点....

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....

有人可以让我知道如何在运行python脚本(执行某些任务)时找到CPU Memory utilizationMemory Usage吗?

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) ?

推荐答案

看看 RunSnakeRun (主页)用于CPU分析和

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

我以前使用过RunSnakeRun,并对它的性能感到非常满意.它甚至可以为您将cProfile转储处理为可视化文件,以便您可以轻松查看代码大部分时间都花在了哪里.

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在记忆方面也做同样的事情.

Meliae does the same thing for memory.

关于CPU使用率,您可能只想在命令行中按top(假设是Linux发行版)并跟踪您的进程以查看它占用了多少CPU

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

希望这会有所帮助

这篇关于运行python脚本后如何查找CPU使用率和内存使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆