简体   繁体   English

如何监控python程序中每个代码行的cpu使用率

[英]how to monitor the cpu usage of every code line in python program

Is there any monitor utils that can monitor the cpu usage of every code line use in python program.是否有任何监视器工具可以监视 python 程序中使用的每个代码行的 CPU 使用情况。 I know profile,cProfile and line_profiler.我知道 profile、cProfile 和 line_profiler。 but they are only statistic the time of each line or function using the cpu.但它们只是使用cpu统计每行或function的时间。 If my program is io-intensive, it may be use a long time but doesn't really use the calculation of the cpu.如果我的程序是 io 密集型的,它可能会使用很长时间但并没有真正使用 cpu 的计算。 So I want to find a util which could monitor the real calculation of the cpu.所以我想找到一个可以监控cpu实际计算的工具。 Have anybody an idea?有人有想法吗?

cProfile and profile both accept a time base function as a parameter. cProfileprofile都接受时基 function 作为参数。 Just pass time.clock instead of the default time.time .只需传递time.clock而不是默认的time.time

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM