LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2008, 03:19 PM   #1
Ryzol
Member
 
Registered: Jun 2007
Distribution: Ubuntu, Slackware
Posts: 50

Rep: Reputation: 15
help with a shell script that data parses /usr/bin/time


I'm writing a triple-loop program to measure execution time and memory use of some programs. Basically I have a small program that runs too fast to gather meaningful data so I am running it in a shell script many times and measuring that total time. To gather accurate data I need to subtract the execution time and memory overhead of the empty loop. I also want to subtract the time and memory it takes to seed the program with random data.

This snippet has all the data I want to gather from /usr/bin/time:
Code:
/usr/bin/time --append --output="$HOME/timinglogs/fileName" --format="Program:%C\nRealTime:%e\t\t SystemTime:%S\tUserTime:%U\nAvgTotalMem=%KKBs\t NumSwaps:%W\n" progamName
This is what I have right now:
Code:
#!/bin/bash

#first run the program n times and time that
#then run the seeder n times and time that
#then run an empty function loop n times and time that
#subtract empty function loop from both times
#subtract seed time from run time

##in all these short functions
##$1 is how many times to loop
##$2 is the program to run
run_program() {
    i=0
    while [ $i -lt $1 ]; do
        ./$2 #program name
        let i=$i+1
    done
}

run_seeder() {
    i=0
    while [ $i -lt $1 ]; do
        ./$2 #seeder name
        let i=$i+1
    done
}

empty_loop(){
    i=0
    while [ $i -lt $1]; do
        let i=$i+1
    done
}

my_time () {
    #call time on run_program
    #call time on run_seeder
    #call time on empty loop
    #subtract them
    #log result
   }
My biggest problem (so far) is figuring out a way to automate the subtraction of these numbers.
 
Old 08-04-2008, 04:24 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
The /usr/bin/time command will output its time results onto STDERR, so with proper redirection, you can capture the times which you can parse:

Example:
Code:
$ timeA=$(/usr/bin/time ls 2>&1 1> /dev/null)

$ echo $timeA
0.00 real 0.00 user 0.00 sys
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does www-data have /bin/sh as a shell? reverse Debian 2 11-18-2007 07:35 AM
what is difference between /usr/bin/7za /usr/bin/7z fakie_flip Linux - Software 9 08-14-2006 09:22 PM
Ubuntu 5.10 -> 6.06: diversion of /usr/bin/ldd to /usr/bin/ldd.amd64 by ia32-libs HellSpawn Linux - Software 2 06-04-2006 09:18 PM
data recovery [/usr/bin] ebil Mandriva 1 05-12-2005 08:51 PM
path in services wrong for clamav updated frm 0.75 to 0.80 usr/bin vs usr/local/bin Emmanuel_uk Linux - Newbie 3 04-22-2005 01:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration