Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Measureing memory used by a subprocess

已查看 3 次
跳至第一个未读帖子

Andrew McLean

未读,
2007年4月1日 20:12:532007/4/1
收件人
I want to script the benchmarking of some compression algorithms on a
Windows box. The algorithms are all embodied in command line
executables, such as gzip and bzip2. I would like to measure three things:

1. size of compressed file
2. elapsed time (clock or preferably CPU)
3. memory used

The first is straightforward, as is measuring elapsed clock time. But
how would I get the CPU time used by a sub-process or the memory used?

I'm guessing that the Windows Performance Counters may be relevant, see
the recipe

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303339

But I don't see any obvious way to get the process id of the spawned
subprocess.

- Andrew

Shane Geiger

未读,
2007年4月1日 20:27:212007/4/1
收件人 Andrew McLean、pytho...@python.org
Getting the pid:

http://timgolden.me.uk/python/wmi_cookbook.html

List all running processes

import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name


List all running notepad processes

import wmi
c = wmi.WMI ()
for process in c.Win32_Process (name="notepad.exe"):
print process.ProcessId, process.Name


Create and then destroy a new notepad process

import wmi
c = wmi.WMI ()
process_id, return_value = c.Win32_Process.Create
(CommandLine="notepad.exe")
for process in c.Win32_Process (ProcessId=process_id):
print process.ProcessId, process.Name

result = process.Terminate ()

--
Shane Geiger
IT Director
National Council on Economic Education
sge...@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

sgeiger.vcf
0 个新帖子