Python user profile on thread usage

I have a multi-threaded Python application, and I'm currently eliminating the very frequent (90% or more) CPU usage.

I'm going to try the profiler, but I wanted to see if there is a way that I can get CPU usage on the stream from the application. I understand that os.times () will use the processor as a whole - is there something I can run from each thread to get every thread usage? It would be very helpful to determine which thread the processor consumes.

+7
python
source share
3 answers

Other than the profiler, I don't think Python has many built-in functions for monitoring the use of individual threads. In addition, this post provides an example of a simple implementation of a thread profiler. It is mainly focused on Unix based systems, but this is the beginning.

+1
source share

Or you can just use yappi. ( https://code.google.com/p/yappi/ ) It transparently uses GetThreadTimes () if the processor synchronization type is selected for profiling. It will show you the processor time of the running thread.

See also an example: https://code.google.com/p/yappi/wiki/YThreadStats_v082

+2
source share

If you are on Windows, you can take a look at Process Explorer ("procexp.exe" that ships with Microsoft Sysinternals Tools ). There is a tab "Threads" in the properties of each process, which lists all the threads and the time of their processor.

If this does not give you enough information, use Python profiling mechanisms , which are not so difficult to use.

0
source share

All Articles