Eli Courtwright
Eli Courtwright

Reputation: 192921

Measuring CPU time per-thread on Windows

I'm developing a long-running multi-threaded Python application for Windows, and I want the process to know the CPU time that each of its threads has taken. I can get the overall times for the entire process with os.times() but I need to know the per-thread times.

I know that there are external tools such as the Sysinternals Process Explorer, but my program itself needs to have this information. If I were on Linux, I look in the /proc filesystem, as described here. If I were writing C code, I'd use the GetThreadTimes call, as described here.

So how can I accomplish this on Windows using Python?

Upvotes: 2

Views: 1275

Answers (2)

Sumer Cip
Sumer Cip

Reputation: 169

Or you can simply use yappi. (https://code.google.com/p/yappi/) It transparently uses GetThreadTimes() if CPU clock type is selected for profiling.

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

Upvotes: 1

Nick Bastin
Nick Bastin

Reputation: 31299

win32process.GetThreadTimes

You want the Python for Windows Extensions to do hairy windows things.

Upvotes: 1

Related Questions