Results 1 to 7 of 7

Thread: Record duration a program/process is running

  1. #1
    Join Date
    Dec 2007
    Location
    California
    Beans
    128
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Record duration a program/process is running

    I need a way to measure how long I am using a program (Eagle CAD) so I know how long it takes me to complete my projects. I need it to save it's count from previous sessions and have a total time used. Basically a stop watch that automatically starts and stops when the program opens/closes.

    Is there anything like this out there?

    Thanks,
    Justin Rajewski

  2. #2
    Join Date
    Nov 2007
    Location
    England
    Beans
    731
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Record duration a program/process is running

    Not an application I know off hand. Need to have a think. Might be possible to create a script that writes a start time and end time to a launcher.
    Want an alternative to 99% of Windows applications?
    http://www.osalt.com/

    "Dude, real programmers compile" - Plato 428BC

  3. #3
    Join Date
    Aug 2008
    Location
    Hmm..$whereis?
    Beans
    136
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Record duration a program/process is running

    You could try launching the application from the terminal prefixing the name with time command

    For example if you were to launch brasero:

    $time brasero

    then when you exit brasero you would get something like this;

    $ time brasero

    real 0m6.034s
    user 0m0.852s
    sys 0m0.232s

    That, I believe is what you are looking for.Just make sure you don't close the terminal in the meanwhile!!
    Debian 6.0.1(Squeeze)/64bit
    **************************
    MSI K9AGM4-L | AMD Athlon64 X2 4000+ | 2x1GB DDR2 800MHZ(Transcend) | ATI Radeon Xpress 1250(Onboard) | Seagate 250GB SATA II | Acer AL1916W

  4. #4
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Record duration a program/process is running

    You could wrap your program with a script and sum the times. This is not a solution but, it's an example on how to do it for a single session run. You could adapt this to store the information somewhere and later use bc or a spreadsheet to sum it:

    Code:
    START=$(date +%s)
    
    do_something
    
    STOP=$(date +%s)
    RUNTIME=$(expr $STOP - $START)
    HOURS=$(expr $RUNTIME / 3600)
    REMAINDER=$(expr $RUNTIME % 3600)
    MINS=$(expr $REMAINDER / 60)
    SECS=$(expr $REMAINDER % 60)
    
    printf "%02d:%02d:%02d\n" "$HOURS" "$MINS" "$SECS\n"
    Don't try to make something "fast" until you are able to quantify "slow".

  5. #5
    Join Date
    Dec 2007
    Location
    California
    Beans
    128
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Record duration a program/process is running

    Thanks a lot! I edited your script to append it to a text file and edited the launcher to start the script instead of eagle directly. Here's what I got.

    Code:
    START=$(date +%s)
    DATE=$(date)
    
    eagle
    
    STOP=$(date +%s)
    RUNTIME=$(expr $STOP - $START)
    HOURS=$(expr $RUNTIME / 3600)
    REMAINDER=$(expr $RUNTIME % 3600)
    MINS=$(expr $REMAINDER / 60)
    SECS=$(expr $REMAINDER % 60)
    
    echo $DATE: $HOURS:$MINS:$SECS | cat >> ~/Documents/Time/Eagle.txt
    It outputs something like this.
    Code:
    Sat Jun 6 19:02:03 PDT 2009: 0:0:7
    Sat Jun 6 19:05:04 PDT 2009: 0:1:26
    Shell scripting proves very useful once again.

    Justin

  6. #6
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Record duration a program/process is running

    I'm glad it worked. I would however recommend changing your output to something like this:

    Code:
    printf "%s %02d:%02d:%02d %d\n" "$(date)" "$HOURS" "$MINS" "$SECS" "$RUNTIME" >> ~/Documents/Time/Eagle.txt
    I haven't tried that but, the idea is that you get the date, a regularly formatted elapsed time string and finally, seconds elapsed. If the ultimate goal is to eventually sum the total elapsed time or generally do something interesting with it, having it as a field in your logs that is easily accessible with cut or awk will make post processing the information MUCH easier.
    Don't try to make something "fast" until you are able to quantify "slow".

  7. #7
    Join Date
    Dec 2007
    Location
    California
    Beans
    128
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Record duration a program/process is running

    Thanks, I changed it and it works fine.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •