Instruments: Average CPU Load over one minute

Discussion in 'Mac Programming' started by hob, Apr 17, 2008.

  1. hob
    macrumors 68020

    hob

    Joined:
    Oct 4, 2003
    Location:
    London, UK
    #1
    Hi everyone.

    I've written some compositions in Quartz Composer and want to demonstrate how they tax the CPU in various conditions.

    I've opened up Instruments and I can get it to give me a readout for the individual process (Quartz Composer) but I can't see any obvious way to average the CPU load... I can see the peaks, but I'd much rather know what the average is over 1 minute, in this instance (I want to compare different compositions - there's no variables within them as such...)

    I found a little DTrace script in the apple docs, but couldn't really get it to work... it would quit with an error after about 45 seconds...

    Anyone got any ideas?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Haven't made the leap to Leopard yet, so I can't comment on Instruments, but:

    date ; ps -aux | grep PID | grep -v grep | awk '{print $10}'; sleep 60 ;date;ps -aux | grep PID | grep -v grep | awk '{print $10}'

    Replace PID with the PID you want to monitor.

    You'll have to do some math yourself. There's probably a way to subtract the first cpu time from the second, then divide by .6 to get the precentage used, but you can at least do those 2 calculations yourself now to get what you're looking for.

    -Lee
     
  3. macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #3
    Run uptime for a baseline, run the thing for one minute, take uptime again.
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    I think that will only give the one, five, and fifteen minute load averages. Even with the minutely load average this says very little about the CPU usage of the process in question. I may be misinterpreting but this seems to, at best, give a general trend of system load, which most definitely should trend up when an additional task is added.

    -Lee
     
  5. macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #5
    Could be I'm misinterpreting the problem, but that sounds about what's right; assuming nothing but the target process is running, the two one-minute averages subtracted ought to give some idea of the system load for the target process.
     
  6. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    It would probably be difficult to keep everything else on the system at bay during the test. There are plenty of background processes whose activity may vary during the test, etc.

    Since the load average is based on the length of the run queue and the number of running processes, the amount of CPU the process is actually using may have little or no effect on the load average. The fact that there is one more process may slightly affect the average, but how much CPU it uses may not. The relative impact on load average of different programs may give you some indication of which is more intensive, but not necessarily.

    We're both interpreting the request slightly differently, so the OP might want to clarify. "how they tax the CPU", "average the CPU load", and "the average is over 1 minute" are pretty wide open in terms of what you want. What I provided allows for computation of the average % of a single CPU core over the minute is, what GeeYouEye provided will allow you to get a general idea of impact on the system. Either of these may fit the need, or they might both miss the target.

    -Lee
     

Share This Page