Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cputime call count
- foo 500 1
- bar 1500 3
- #!/usr/sbin/dtrace -s
- pid$1:$2::entry
- {
- ++self->call_depth[probefunc];
- self->start[probefunc, self->call_depth[probefunc]] = timestamp;
- self->vstart[probefunc, self->call_depth[probefunc]] = vtimestamp;
- }
- pid$1:$2::return
- /self->start[probefunc, self->call_depth[probefunc]]/
- {
- @function_walltime[probefunc] = sum(timestamp - self->start[probefunc, self->call_depth[probefunc]]);
- self->start[probefunc, self->call_depth[probefunc]] = 0;
- @function_cputime[probefunc] = sum(vtimestamp - self->vstart[probefunc, self->call_depth[probefunc]]);
- self->vstart[probefunc, self->call_depth[probefunc]] = 0;
- --self->call_depth[probefunc];
- }
- #!/usr/sbin/dtrace -qs
- pid$1:$2::entry
- {
- self->vstart[probefunc] = vtimestamp;
- }
- pid$1:$2::return
- {
- this->cputime = vtimestamp - self->vstart[probefunc];
- /* Sub the caller function CPU time */
- @function_cputime[ufunc(ucaller)] = sum(-(this->cputime));
- /* Add the callee function (current function) CPU time */
- @function_cputime[ufunc(uregs[R_PC])] = sum(this->cputime);
- /* Add the callee function (current function) count */
- @function_count[ufunc(uregs[R_PC])] = sum(1);
- }
- #!/usr/sbin/dtrace -s
- #pragma option quiet
- pid$1:$2::entry
- /self->start[probefunc] == 0/
- {
- this->call_depth = self->call_depth++;
- self->func_pcs[this->call_depth] = uregs[R_PC];
- self->start[probefunc] = timestamp;
- self->vstart[probefunc] = vtimestamp;
- @function_entry_count[ufunc(uregs[R_PC])] = count();
- }
- pid$1:$2::return
- /self->start[probefunc]/
- {
- this->call_depth = --self->call_depth;
- this->wall_elapsed = timestamp - self->start[probefunc];
- self->start[probefunc] = 0;
- this->cpu_elapsed = vtimestamp - self->vstart[probefunc];
- self->vstart[probefunc] = 0;
- @function_walltime_inc[ufunc(uregs[R_PC])] = sum(this->wall_elapsed);
- @function_walltime_exc[ufunc(uregs[R_PC])] = sum(this->wall_elapsed);
- @function_cputime_inc[ufunc(uregs[R_PC])] = sum(this->cpu_elapsed);
- @function_cputime_exc[ufunc(uregs[R_PC])] = sum(this->cpu_elapsed);
- @function_return_count[ufunc(uregs[R_PC])] = count();
- }
- pid$1:$2::return
- /this->call_depth > 0/
- {
- this->caller_pc = self->func_pcs[this->call_depth - 1];
- @function_walltime_exc[ufunc(this->caller_pc)] = sum(-(this->wall_elapsed));
- @function_cputime_exc[ufunc(this->caller_pc)] = sum(-(this->cpu_elapsed));
- }
- dtrace:::END
- {
- /* normalize to millisecons */
- normalize(@function_walltime_inc, 1000000);
- normalize(@function_walltime_exc, 1000000);
- normalize(@function_cputime_inc, 1000000);
- normalize(@function_cputime_exc, 1000000);
- printf("n");
- printf("%-60s %21s %21s %25sn", "", "INCLUSIVE", "EXCLUSIVE", "CALL COUNT");
- printf("%-60s %10s %10s %10s %10s %12s %12sn",
- "MODULE`FUNCTION", "WALL [ms]", "CPU [ms]", "WALL [ms]", "CPU [ms]", "ENTRY", "RETURN");
- printa("%-60A %@10d %@10d %@10d %@10d %@12d %@12dn",
- @function_walltime_inc, @function_cputime_inc,
- @function_walltime_exc, @function_cputime_exc,
- @function_entry_count, @function_return_count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement