Search code examples
pythoncpumonitor

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. I know profile,cProfile and line_profiler. but they are only statistic the time of each line or function using the cpu. If my program is io-intensive, it may be use a long time but doesn't really use the calculation of the cpu. So I want to find a util which could monitor the real calculation of the cpu. Have anybody an idea?


Solution

  • cProfile and profile both accept a time base function as a parameter. Just pass time.clock instead of the default time.time.