[comp.unix.questions] accounting...

hubcap@hubcap.UUCP (Mike Marshall) (03/08/88)

I need to map standard BSD accounting information into a format
that is palatable to our home-grown accounting programs. I need to 
charge people for CPU time. I see three fields which in themselves,
or in some combination, might give me a reasonable number to use:
  - ac_utime        defined as "user time"
  - ac_stime                   "system time"
  - ac_etime                   "elapsed time"

Other than the little blurb I included above, I know nothing about how
to interpret the data in these fields. I have looked in acct(2) and acct(5).
Where might I find out more info? What can you tell me about these fields?

Thanks for any help.

-Mike Marshall       hubcap@hubcap.clemson.edu        ...!hubcap!hubcap

breck@aimt.UUCP (Robert Breckinridge Beatie) (03/09/88)

In article <1094@hubcap.UUCP>, hubcap@hubcap.UUCP (Mike Marshall) writes:
> ... I need to 
> charge people for CPU time. I see three fields which in themselves,
> or in some combination, might give me a reasonable number to use:
>   - ac_utime        defined as "user time"
>   - ac_stime                   "system time"
>   - ac_etime                   "elapsed time"
> ... What can you tell me about these fields?

The ac_utime and ac_stime fields are the ones you want to charge for cpu time.
On many systems they store the amount of cpu time, in seconds, spent by the
process in user and system state respectively.

The fields are normally stored in a "pseudo floating point" format.  The top
3 bits of the word are the exponent with the bottom 13 bits being the
mantissa.

Here's a snippet of code to translate the fields:

time_t
cvrt(tim)
comp_t tim;
{
    unsigned int exponent;
    time_t mantissa;

    mantissa = tim & 0x1fff;
    exponent = tim >> 13;
    while(exponent--)
	mantissa <<= 3;			/* multiply by 8 (base of exponent) */
    return mantissa;
}

At least I think this works.  It's based on recollection from a program
I whipped up a year ago to read the process accounting file.

One possible problem you might run into is the units of the number stored
in the ac_{s,u}time fields.  On some systems the units are seconds and
commands that take less than 1 second of cpu time have 0 stored in the
process accounting file.  On other systems the units are 1/CLK_TCK seconds
so to get numbers in seconds, you'll have to divide by CLK_TCK (Whatever
that value might be).
-- 
Breck Beatie
{uunet,ames!coherent}!aimt!breck
"Sloppy as hell Little Father.  You've embarassed me no end."

davidsen@steinmetz.steinmetz.UUCP (William E. Davidsen Jr) (03/11/88)

  You have gotten a few good replies, but I will add a few more points.
The accounting fields on some systems store a pseudo float number as
described by another poster. As mentioned these can be in seconds or
ticks.

  On Ultrix the values are stored as floats rather than shorts. I don't
know if that's typical of BSD, since Sun uses shorts, also. The least
portable value is the memory. In addition to several formats, the values
may be in K-sec (core product) or K-cpu (increment the could by the K
every time the process is charged for a cpu cycle) or K-clock (I think
this is done by bumping the count every time the process is dispatched).
Just to keep from being portable, some keep the mem in K and others in
bytes!

  I learned a lot more than I wanted to know when I wrote a functional
acctcom clone for a unix-pc. Since then I have ported it to Xenix 286
and 386 (not remotely the same), and looked at Suns. When it reaches
another steady state I will send it off to sources.unix, although the
backlog must be fierce, as I sent my keyword index to text program off
to them several months ago.

  The original poster should let us know if it's a BSD or SysV system,
since some of the fields are very diferent.
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me

icsu6000@caesar.cs.mtsu.edu (Mathisen) (07/11/88)

  Does anybody have a set of accounting scripts that would run on a VAX under
Ultrix 2.0 ??  Basically what I need is some info on who's using what
resources, but I haven't delved into the manuals yet.  If you do, and would be
willing to share them, please send mail to:

icsu6000%mtsunix1.bitnet@cunyvm.cuny.edu

or if you're brave...

icsu6000%caesar.cs.mtsu.edu (192.31.215.202), We're supposed to be in HOSTS.TXT,
but I haven't gotten a recent copy, and don't run a name server.

Thanx.
Jaye Mathisen
-- Jaye Mathisen
mathisen.sys_admin.sys_org
icsu6000%mtsunix1.BITNET@cunyvm.cuny.edu
icsu6000%mtsunix1.BITNET