Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get process threads information #134

Closed
giampaolo opened this issue May 23, 2014 · 15 comments
Closed

Get process threads information #134

giampaolo opened this issue May 23, 2014 · 15 comments

Comments

@giampaolo
Copy link
Owner

From zip...@gmail.com on November 12, 2010 09:30:32

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: http://code.google.com/p/psutil/issues/detail?id=134

@giampaolo
Copy link
Owner Author

From g.rodola on November 12, 2010 01:40:55

Status: WaitingForReview

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 12, 2010 05:53:11

Some references: 

Windows 
http://stackoverflow.com/questions/1393006/how-to-get-the-cpu-usage-per-thread-on-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-on-mac-osx

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 12, 2010 12:07:10

Summary: Support for per-thread CPU utilization
Labels: -Type-Defect Type-Enhancement

@giampaolo
Copy link
Owner Author

From zip...@gmail.com on November 14, 2010 01:45:38

thank you for reply :)
.
.

@giampaolo
Copy link
Owner Author

From g.rodola on November 14, 2010 15:59:41

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().

Summary: Get process threads information

@giampaolo
Copy link
Owner Author

From zip...@gmail.com on November 16, 2010 00:03:03

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...

@giampaolo
Copy link
Owner Author

From g.rodola on November 16, 2010 01:13:02

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.

@giampaolo
Copy link
Owner Author

From g.rodola on November 16, 2010 12:43:18

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)]

Status: Started
Labels: Progress-1in4

@giampaolo
Copy link
Owner Author

From g.rodola on November 16, 2010 13:54:45

Implemented on Windows in r822 .

Labels: -Progress-1in4 Progress-2in4

@giampaolo
Copy link
Owner Author

From g.rodola on November 19, 2010 14:21:51

Labels: Milestone-0.2.1

@giampaolo
Copy link
Owner Author

From g.rodola on November 20, 2010 11:53:41

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).

Labels: -Progress-2in4 Progress-3in4

@giampaolo
Copy link
Owner Author

From zip...@gmail.com on November 21, 2010 20:04:59

nice update!...

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

.
.
.

@giampaolo
Copy link
Owner Author

From g.rodola on February 17, 2011 06:02:08

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

Status: FixedInSVN
Labels: -Progress-3in4 Progress-4in4

@giampaolo
Copy link
Owner Author

From g.rodola on March 20, 2011 14:55:37

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:56:48

Updated csets after the SVN -> Mercurial migration: r821 == revision 
aa0b3d808dc8 r822 == revision bd431637453d r827 == revision b870cf4e47e6 r922 
== revision e563f0bf792e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant