nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Get process threads information #134

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

it is a exciting py module i have used... like some days ago,it is slow to use 
the WMI to see the processes infomation...

and if you can add the function which get_cpu_percent of a thread it will be 
better like p.get_cpu_percent(threadID-->in the p process)

What version of psutil are you using? What Python version?
1.3   and 2.5.1

On what operating system? Is it 32bit or 64bit version?
XP  32bit

Original issue reported on code.google.com by zip...@gmail.com on 12 Nov 2010 at 8:30

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 12 Nov 2010 at 9:40

GoogleCodeExporter commented 8 years ago
Some references: 

Windows
http://stackoverflow.com/questions/1393006/how-to-get-the-cpu-usage-per-thread-o
n-windows-win32
http://www.codeproject.com/KB/system/processescpuusage.aspx

Linux (possibly BSD if the C code works)
http://108leaves.com/codediary/?p=1 

OS X
http://stackoverflow.com/questions/1455320/how-to-get-the-cpu-usage-per-thread-o
n-mac-osx

Original comment by jlo...@gmail.com on 12 Nov 2010 at 1:53

GoogleCodeExporter commented 8 years ago

Original comment by jlo...@gmail.com on 12 Nov 2010 at 8:07

GoogleCodeExporter commented 8 years ago
thank you for reply :)
.
.

Original comment by zip...@gmail.com on 14 Nov 2010 at 9:45

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
We should first have a "get_threads()" function returning a list of objects 
(I'd say a namedtuple) including at least thread id, user and kernel times 
information, and possibly also other information.
From there, adding a get_threads_percent() returning a namedtuple including 
thread id and percentage usage, but I'm not sure I like this kind of API (for 
now at least).

I'd say we better focus on implementing get_threads() first, and change the 
subject/discussion of this issue in accordance.
get_threads_percent() is something we might think about later.

Note: get_threads() should deprecate current get_num_threads().

Original comment by g.rodola on 14 Nov 2010 at 11:59

GoogleCodeExporter commented 8 years ago
how to Enum threads in a process?

http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2004-05/0509
.html

it seems that ToolHelp32 in the Kernel32.dll which have some functions like
CreateToolhelp32Snapshot+Thread32First+Thread32Next 

others said it can enum threads in a process 

there is also some c++ code to enum threads in above site...

but it is hard to use c++ or dll with python...

Original comment by zip...@gmail.com on 16 Nov 2010 at 8:03

GoogleCodeExporter commented 8 years ago
Yes, we are already using CreateToolhelp32Snapshot, Thread32First and 
Thread32Next currently to get the number of threads per-process.
I still haven't  looked into it properly, but retrieving other information from 
threads on Windows seems quite straightforward.

Original comment by g.rodola on 16 Nov 2010 at 9:13

GoogleCodeExporter commented 8 years ago
Implemented on Linux in r821.
A new Process.get_threads() method is available returning a namedtuple as such:

>>> p = psutil.Process(os.getpid())
>>> p.get_threads()
[thread(id=3318, user_time=0.01, system_time=0.01)]

Original comment by g.rodola on 16 Nov 2010 at 8:43

GoogleCodeExporter commented 8 years ago
Implemented on Windows in r822.

Original comment by g.rodola on 16 Nov 2010 at 9:54

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 19 Nov 2010 at 10:21

GoogleCodeExporter commented 8 years ago
Implemented for FreeBSD in r827 thanks to: 
http://fxr.googlebit.com/source/usr.bin/procstat/procstat_threads.c?v=8-CURRENT
It turns out procstat utility (wasn't aware of it) has a lot of useful and well 
written code we can borrow (e.g. process files/connections which we can 
reimplement in C).

Original comment by g.rodola on 20 Nov 2010 at 7:53

GoogleCodeExporter commented 8 years ago
nice update!...

it is the best python module to get process infomatinon i have found...quickly 
and fully...

.
.
.

Original comment by zip...@gmail.com on 22 Nov 2010 at 4:04

GoogleCodeExporter commented 8 years ago
Implemented for OSX in r922.
It seems we cannot determine the thread ids, so I used an incremental bogus 
value as a replacement.

Original comment by g.rodola on 17 Feb 2011 at 2:02

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 20 Mar 2011 at 9:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Updated csets after the SVN -> Mercurial migration:
r821 == revision aa0b3d808dc8
r822 == revision bd431637453d
r827 == revision b870cf4e47e6
r922 == revision e563f0bf792e

Original comment by g.rodola on 2 Mar 2013 at 11:56