7

I've been looking at using process accounting for keeping track of various users and sites running scripts that are problematic in our environment instead of trying to do something like scraping top at regular intervals.

The one that isn't particularly clear is which fields really denotes the cpu seconds/minutes used. The manual pages I have read say the 'cpu' column is for seconds burned, however there is alo the 'cp' column displayed with -m - and they can show different totals. For example:

When I use the -m flag, I get

 $sa -m | grep username
 username 14944      65.53re      29.90cp     5308k

When I use the -u flag and total up the column for 'cpu', I get the following:

 sa -u |grep username|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'
 1032.86

Can anybody help me understand the difference between the 'cp' and 'cpu' columns in these two different modes?

Thanks!

epic9x
  • 1,618
  • 10
  • 9

1 Answers1

6

Let me use an example to help explain what your results above show:

First: I created a bash script that I ran as the user patrickr which was meant to put enough load on the system to be noticeable.

#!/bin/bash
#this file is named loop_script.sh
for i in {1..5000}
do
   echo "Welcome $i times"
done

Second: I uninstalled and then reinstalled acct so that my files in /var/log/acct would be fresh. Create a copy of the /var/log/acct/pacct file so that in the future you can easily truncate the file with a properly formatted file (you can't just delete and recreate the file - sa will stop working if you do that). Note that this file is a log of all commands on the system and as far as I can tell there is no way to pull parts on the log based on time periods.

Third: I then ran this script twice as patrickr

patrickr@hostname:~$ bash loop_script.sh

I'll give you the results and then I'll explain them:

Ran as root (or any user other that patrickr) After first loop as patrickr:

**sa -m**
                            24       0.09re       0.03cp         0avio       894k
root                        22       0.07re       0.02cp         0avio       853k
patrickr                    2       0.02re       0.01cp         0avio      1336k

**sa -u |grep patrickr**

patrickr   0.38 cpu     1336k mem      0 io bash             

After second loop as patrickr:

**sa -m**
                            30       0.09re       0.03cp         0avio       850k
root                        27       0.07re       0.02cp         0avio       814k
patrickr                    3       0.02re       0.01cp         0avio      1178k

**sa -u |grep patrickr**

patrickr   0.38 cpu     1336k mem      0 io bash            
patrickr   0.35 cpu     1336k mem      0 io bash            
patrickr   0.00 cpu      863k mem      0 io ls  (I happened to also run ls at patrickr)

**sa -u**

The results returned 106 results for a total of 2.86cpu that averaged to 0.03cp

Here's what you're seeing:

sa -m is showing averages for the all the activity for this server overtime. This file grows larger over time as more commands run.

sa -u | grep patrickr is showing the sum of the system and user time in cpu minutes for specific commands.

Running: sa -u |grep patrickr|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'

Will give you a combined total for user patrick but the sa -m command is actually giving you averages. Take a look at the memory values is you need a second example. They're averaged too.

If I add the three results listed above for patrickr, .35 + .37 + .0 and divide by 106 and round to the to the nearest hundredth I'll get 0.01cp.

The result of 0.01cp is the average load of user patrickr on the system in comparison to all load on the system from the time that the acct application was installed (ie since the file /var/log/acct/pacct started keeping track).

Output Fields
cpu   -  sum of system and user time in cpu minutes
re    -  actual time in minutes
k     -  cpu-time averaged core usage, in 1k units
k*sec -  cpu storage integral (kilo-core seconds)
u     -  user cpu time in cpu minutes
s     -  system time in cpu minutes

A good resource that will help you is at beginlinux.com (original link found here).

Patrick R
  • 2,925
  • 1
  • 18
  • 27
  • I just wanted to apologize for the incredible delay on saying thank you for this response, this was a fantastic resource for me, and I was remiss in not saying so! – epic9x Aug 19 '10 at 04:10