zhengzheng / psutil

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

get_children run slow under windows7 #415

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. running python -m cProfile aa.py , with content:
#!/usr/bin/env python
# -*- coding=utf-8 -*-

import os
import psutil
from subprocess import Popen

p = Popen(['python', 'test/pyha/sleep.py'])
parent = psutil.Process(os.getpid())
childs = parent.get_children(recursive=True)
print childs
p.wait()

2. the resoult is  
       82    0.001    0.000    6.569    0.080 __init__.py:269(ppid)
        1    0.000    0.000    0.106    0.106 __init__.py:286(name)
       83    0.000    0.000    0.645    0.008 __init__.py:389(create_time)
        1    0.001    0.001    7.262    7.262 __init__.py:496(get_children)
3. get ppid cost 6s with 82 times, it is so slow.

What is the expected output?
get_children should return quickly.

What do you see instead?
get all pid's ppid in one system call rather than per pid.

What version of psutil are you using? What Python version?
python 2.7.2
psutil 1.0.1

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

Please provide any additional information below.

Original issue reported on code.google.com by lisongm...@gmail.com on 3 Aug 2013 at 12:08

GoogleCodeExporter commented 8 years ago
I see no obvious way to speed this up as you're forced to retrieve ppid for all 
processes no matter what.

As for your suggestion: except perhaps for Windows (I should double check) 
there's no operating system providing a system call to retrieve all pid's ppid 
in one shot: you're forced to iterate over all processes.

Original comment by g.rodola on 6 Aug 2013 at 2:16

GoogleCodeExporter commented 8 years ago
I'm going to close this out as invalid.

Original comment by g.rodola on 25 Aug 2013 at 10:56

GoogleCodeExporter commented 8 years ago
>> get all pid's ppid in one system call rather than per pid.
> you're forced to retrieve ppid for all processes no matter what.

It turns out retrieving all parent pids in one call on Windows it was possible 
after all.  I just didn't remember how ppid() was implemented on Windows.
get_children() is now an order of magnitude faster (+20x or something like 
that).
Committed in revision 32ca76279dce.

Original comment by g.rodola on 7 Sep 2013 at 12:33

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 28 Sep 2013 at 10:06

GoogleCodeExporter commented 8 years ago
Closing out as fixed. Release 1.1.0 is now available for download.

Original comment by g.rodola on 28 Sep 2013 at 5:32