G''Day Pankaj,
--------pctcpu.d--------
#!/usr/sbin/dtrace -s
#pragma D option quiet
profile:::profile-10hz
{
@sample[execname, pid, tid] = max(curthread->t_pctcpu);
}
profile:::tick-1sec
{
normalize(@sample, 0x80000000 / 100);
printf("\n%-16s %6s %6s %6s\n", "COMM",
"PID", "TID", "%CPU");
printa("%-16s %6d %6d %@6d\n", @sample);
trunc(@sample);
}
--------pctcpu.d--------
# pctcpu.d
COMM PID TID %CPU
bash 613 1 8
perl 2117 1 64
COMM PID TID %CPU
bash 613 1 10
perl 2117 1 62
^C
I demo''d pctcpu as I trust pctmem even less.
Brendan
On Wed, 15 Feb 2006, Brendan Gregg wrote:
> G''Day Pankaj,
>
> On Tue, 14 Feb 2006, Pankaj Maurya wrote:
>
> > hi,
> > The curpsinfo and curlwpsinfo are pointers to psinfo_t and lwpsinf_t
> > structures. I want to access the pr_pctcpu and pr_pctmem fields of
these
> > structures. The basic idea is:
> >
> > profile:::profile-1000
> > /pid == $1/
> > {
> > @ProcessMemUsage = avg(curpsinfo->pr_pctmem);
> > }
> >
> > profile:::tick-1sec
> > {
> > /* print these */
> > printf("%d ", $1);
> > printa("%@d\n", @ProcessMemUsage);
> > }
> >
> > profile:::tick-1sec
> > { clear(@ProcessMemUsage);}
> >
> > Problem encountered: Translator cant translate the pr_pctmem member.
> > I am able to use only the ''int'' fields of the
psinfo_t and lwpsinfo_t
> > structures. type casting into int is not allowed.
> >
> > I know something really silly is there...I am a total newbie, so
please
> > let me know precisely what needs to be done(preferably a working code
> > snippet)
>
> Nothing silly at all. DTrace''s curpsinfo and curlwpsinfo are
provided to
> be useful look-alikes, but aren''t the real structures (not that it
usually
> matters). Have a look through,
>
> /usr/lib/dtrace/procfs.d
>
> the translator syntax will be new to you, but you''ll probably work
out
> what is going on.
>
>
> I only once had the need to dig out pr_pctcpu and pr_pctmem from DTrace,
> and at the time it was already a Perl script to loop over existing PIDs,
> so I simply read it from /proc. Even if I did read pr_pctcpu from DTrace,
> it can''t be printed as floats from an aggregate. If I come up with
a bit
> of code I''ll post it.
>
> no worries,
>
> Brendan
>
> [Sydney, Australia]
>
> _______________________________________________
> dtrace-discuss mailing list
> dtrace-discuss at opensolaris.org
>
>