He is looking for more precise measure like every second as in top on
Linux. So my links were examples how it's done on another system. In
this concrete case :

-m

Report microstate process accounting information. In addition to all
fields listed in -v mode, this mode also includes the percentage of
time the process has spent processing system traps, text page faults,
data page faults, waiting for user locks and waiting for CPU (latency
time).

pr_pctcpu Field
The CPU field that prstat prints is pr_pctcpu, which is fetched by
user-level tools from procfs. It is maintained for each thread as
thread->t_pctcpu by the cpu_update_pct() function in
common/os/msacct.c. This takes a high-resolution timestamp and
calculates the elapsed time since the last measurement, which was
stored in each thread's t_hrtime. cpu_update_pct() is called by
scheduling events, producing an extremely accurate measurement as this
is based on events and not ticks. cpu_update_pct() is also called by
procfs when a pr_pctcpu value is read, at which point every thread's
t_pctcpu is aggregated into pr_pctcpu.

The cpu_update_pct() function processes t_pctcpu as a decayed average
by using two other functions: cpu_grow() and cpu_decay(). The way this
behaves may be quite familiar: If a CPU-bound process begins, the
reported CPU value is not immediately 100%; instead it increases
quickly at first and then slows down, gradually reaching 100. The
algorithm has the following comment above the cpu_decay() function.

/*
 * Given the old percent cpu and a time delta in nanoseconds,
 * return the new decayed percent cpu:  pct * exp(-tau),
 * where 'tau' is the time delta multiplied by a decay factor.
 * We have chosen the decay factor (cpu_decay_factor in param.c)
 * to make the decay over five seconds be approximately 20%.
 *
...



This comment explains that the rate of t_pctcpu change should be 20%
for every five seconds (and the same for pr_pctcpu).

User-level commands read pr_pctcpu by reading /proc/<pid>/psinfo for
each process, which contains pr_pctcpu in a psinfo struct as defined
in /usr/ include/sys/procfs.h.


On Fri, Jan 15, 2010 at 8:56 AM, Philip Guenther <guent...@gmail.com> wrote:
> On Thu, Jan 14, 2010 at 10:51 PM, Tomas Bodzar <tomas.bod...@gmail.com>
wrote:
>> Mmm maybe you are looking for something like -m option in prstat(1M)
>> command http://docs.sun.com/app/docs/doc/819-2240/prstat-1m?l=en&a=view
>> . Here you can find code
>> http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/prstat/
>
> Right, he should look at something which doesn't actually do what he
> wants and doesn't compile on OpenBSD because it relies on kernel
> structures that OpenBSD doesn't contain.
>
> Umm, what?
>
> If you had asked "What problem are you trying to solve?" then I would
> have applauded because, on reflection, that's a good question in this
> case. B As is, I don't understand how your message helps the original
> poster. B Could you clarify it?
>
>
> Philip Guenther
>



--
http://www.openbsd.org/lyrics.html

Reply via email to