473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

clocking subprocesses

Hi,

I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions. This should be really
easy for someone, so here goes:

I'm running some numerical simulations under Ubuntu, and using Python
as my scripting language to automatically manage input and output. I
need to have a precise performance measurement (CPU time) of how long
it takes to run my simulations.

Right now I have something like:

stime = time.time()
subprocess.call(["./mysim","args"])
ftime = time.time()
print ftime-stime

However, time.time() only gives wall-clock time, so I'm also measuring
the time it takes to run other processes running at the same time.
What I'd rather have is:

stime = time.clock()
subprocess.call(["./mysim","args"])
ftime = time.clock()
print ftime-stime

But this, of course, usually outputs 0, because time.clock() does not
count the CPU ticks of the subprocess.

So, long story short, I need to get CPU time of something I call using
subprocess.call(). I don't want to have to profile my code, since it
will significantly reduce computation time.

Thanks for the advice.

Kevin
Mar 3 '08 #1
3 6226
On Mar 3, 11:57*am, barnbu...@gmail.com wrote:
So, long story short, I need to get CPU time of something I call using
subprocess.call(). *
Run your command through the "time" program. You can parse the output
format of "time", or set a custom output format. This mostly applies
to Unix-like systems but there is probably an equivalent somewhere on
Windows.

Preston
Mar 3 '08 #2
On Mar 3, 12:41 pm, Preston Landers <pland...@gmail.comwrote:
>
Run your command through the "time" program. You can parse the output
format of "time", or set a custom output format. This mostly applies
to Unix-like systems but there is probably an equivalent somewhere on
Windows.

Preston
Thanks for the quick answer. That seems to work, though, I'll write a
timesubprocess() function which runs the program through time and
spits the formatted out to a file, then parses that file, then returns
the execution time. There doesn't appear to be a more elegant way to
do this.

Kevin
Mar 3 '08 #3
On Mar 3, 9:57 am, barnbu...@gmail.com wrote:
Hi,

I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions. This should be really
easy for someone, so here goes:

I'm running some numerical simulations under Ubuntu, and using Python
as my scripting language to automatically manage input and output. I
need to have a precise performance measurement (CPU time) of how long
it takes to run my simulations.

Right now I have something like:

stime = time.time()
subprocess.call(["./mysim","args"])
ftime = time.time()
print ftime-stime

However, time.time() only gives wall-clock time, so I'm also measuring
the time it takes to run other processes running at the same time.
What I'd rather have is:

stime = time.clock()
subprocess.call(["./mysim","args"])
ftime = time.clock()
print ftime-stime

But this, of course, usually outputs 0, because time.clock() does not
count the CPU ticks of the subprocess.

So, long story short, I need to get CPU time of something I call using
subprocess.call(). I don't want to have to profile my code, since it
will significantly reduce computation time.
Use os.times(). It returns a 5-tuple and what you want is child cpu
times.

times(...)
times() -(utime, stime, cutime, cstime, elapsed_time)

Return a tuple of floating point numbers indicating process times.

cutime+cstime will give you the total CPU used by child (your
simulation).

Karthik

>
Thanks for the advice.

Kevin
Mar 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jane Austine | last post by:
Running Python 2.3 on Win XP It seems like socket is working interdependently with subprocesses of the process which created socket. ------------------------------------ #the server side >>>...
2
by: Marcos | last post by:
Hi guys, I realise this question has been answered in one form or another many times before but I can't quite find the solution I need. I am trying to run multiple subprocesses from a python...
2
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This...
2
by: None | last post by:
I'm using the HttpWebRequest/Response methods and I'm trying to figure out how to calculate the effective transfer rare the file is being received at (like you see in IE when you download...
3
by: babis85 | last post by:
Hello guys, i have this part of code and i want to compute the time of processes A, B and C : /* process A */ pid_t pid1, pid2, pid; struct rusage ru1, ru2; pid1 = fork(); if (pid != 0) {/*...
3
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the...
1
by: Gal Diskin | last post by:
Hi all, I'm writing a python program using threads to open several subprocesses concurrently (using module subprocess) and wait on them. I was wondering if there is a possibilty that a thread will...
5
by: madgunnercurz | last post by:
i currently have a database for tracking members arrival and exit times. however due to new demands my training centre are wanting a barcode system setup where all the user has to do is use a wedge...
1
by: anchamal | last post by:
I’m using Ms Access 2003 and I have this problem in the query, I created two tables named timein and timeout. The first one contains the time field that the employees are coming (timein) to work...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.