Tuesday, 15 July 2014

solaris - How can I display microseconds cpu consumed per process using dtrace? -



solaris - How can I display microseconds cpu consumed per process using dtrace? -

using dtrace on solaris, able accumulate on-cpu time given process (or execname) interval start until control-c next script:

!/usr/sbin/dtrace -qs dtrace:::begin { total = 0; } sched:::on-cpu /execname == $$1/ { self->start = vtimestamp; } sched:::off-cpu /self->start/ { this->time = vtimestamp - self->start; total += this->time; self->start = 0; } dtrace:::end { printf("total time on cpu: %d us\n",total/1000); }

(accumulated time has fine-grain granularity allowing nano/microsecond accumulation.)

over same timeframe, accumulate or many processes in array , study on accumulated cpu time @ break (^c).

what best way this?

okay, bit more work i've solved problem.

here way microseconds processes (but display per process) on interval.

#!/usr/sbin/dtrace -qs dtrace:::begin { total = 0; starttimestamp=timestamp; printf("starting...\n"); } sched:::on-cpu /pid!=0/ { self->start = vtimestamp; } sched:::off-cpu /self->start && pid!=0/ { this->time = vtimestamp - self->start; total += this->time; @proctime[pid,uid,execname,curpsinfo->pr_psargs] = sum( this->time/1000 ); self->start = 0; } dtrace:::end { printf("elapsed time %d usec\n",(timestamp-starttimestamp)/1000); printf("total time on cpu: %d us\n",total/1000); printa(@proctime); }

process solaris cpu dtrace

No comments:

Post a Comment