Question

In my application I have many threads created using threading module and I need to get as many information about them as possible. Without any problem I can take info about running time. But how to get such information as memory usage of thread and CPU usage (and best would be CPU time).

I found yappi module but it don't fit to me.

Was it helpful?

Solution

Well i don't know which os you are using, but i suggest you look for tools or apis provided by your os to solve this question.

For example in Linux for every process there exists a directory /proc/[pid]/, [pid] beeing the process id. In this directory you will find various pseudo-files, that hold information about almost every aspect of the process. You can open these in python like any other file, so it's very easy to get this information. One of the most important files for your question is /proc/[pid]/stat.

Also there are additional directories /proc/[pid]/task/[tid], [tid] beeing the thread id. These hold informations per thread.

So you see in Linux you could get your information via simple file operations like open() and .read(). I quess that most other operating systems will provide this information too, one way or the other.

To learn more about /proc use man proc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top