1

In order to study my Mac system activities I want to visualize uptime, sleeptime and cpu average during each day.

My first guess would be looking at the system logs, but I would like to know which tools are currently available. Most tools I have seen, are only about the current usage, but I just want a daily summary to look at.

1 Answer 1

1

last shows when the computer was shut down or restarted but not when it was put to sleep or woken up:

$ last|head
lauri     ttys002                   Fri Dec 13 11:56   still logged in
lauri     ttys003                   Fri Dec 13 11:55 - 11:56  (00:00)
lauri     ttys002                   Fri Dec 13 11:55 - 11:56  (00:00)
lauri     ttys002                   Fri Dec 13 11:16 - 11:55  (00:38)
lauri     ttys003                   Fri Dec 13 11:16 - 11:55  (00:38)
lauri     console                   Fri Dec 13 10:08   still logged in
reboot    ~                         Fri Dec 13 10:06
shutdown  ~                         Fri Dec 13 10:05
lauri     console                   Fri Dec 13 08:27 - 10:05  (01:38)
reboot    ~                         Fri Dec 13 08:25

pmset -g log also shows when the computer went to sleep or woke up, including the duration of each period of sleep:

$ pmset -g log|awk '$5~/Sleep|Wake/'|head
11/30/13, 6:07:11 AM GMT Sleep                  Software Sleep pid=45: Using AC                                             16949 secs
11/30/13, 10:49:40 AM GM Wake                   Wake [CDNVA] due to XHC1/HID Activity: Using AC
Sleep/Wakes since boot:1   Dark Wake Count in this sleep cycle:0
12/1/13, 2:31:19 AM GMT+ Sleep                  Software Sleep pid=45: Using AC
12/1/13, 3:29:10 AM GMT+ Wake                   Wake [CDNVA] due to XHC1/HID Activity: Using AC                             120 secs
Sleep/Wakes since boot:2   Dark Wake Count in this sleep cycle:0
12/1/13, 3:31:10 AM GMT+ Sleep                  Software Sleep pid=45 to DarkWake: Using AC
12/1/13, 3:33:14 AM GMT+ Sleep                  Software Sleep pid=45: Using AC                                             50927 secs
12/1/13, 5:42:01 PM GMT+ DarkWake               DarkWake [CDN] due to XHC1/: Using AC                                       7 secs
12/1/13, 5:42:08 PM GMT+ Wake                   DarkWake to FullWake [CDNVA] due to HID Activity: Using AC

To measure the average CPU use, you could add a line like this to crontab:

*/5 * * * * ps -eo \%cpu=|awk '{s+=$0}END{print s}'>>~/Documents/cpu-$(date +\%F)

To see what processes use the most CPU, add a line like this to crontab:

* * * * * ps -eco '\%cpu= comm='|sed $'s/^ *//;s/ /\t/'>>~/Documents/cpu

Then run a command like this later:

awk -F$'\t' '{a[$2]+=$1}END{for(i in a)print a[i],i}' ~/Documents/cpu|sort -rn
1
  • I was so afraid of having to implement a solution than downloading a the tool. Oh well, one more fun project to my list ;-) Commented Dec 16, 2013 at 8:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .