5023N/A# Written using DTrace (Solaris 10 3/05). 5023N/A# $Id: cputimes 3 2007-08-01 10:50:08Z brendan $ 5023N/A# This program accurately measures time consumed by the kernel, but in 5023N/A# doing so creates extra kernel load of it's own. The extra kernel 5023N/A# activity can be measured by running one cputimes and then another, and 5023N/A# comparing the difference in kernel consumed time. This method can be 5023N/A# used to estimate the load created by other DTrace scripts. 5023N/A# USAGE: cputimes [-ahTV] [-t top] [interval [count]] 5023N/A# -V # don't print timestamps 5023N/A# -t num # print top num lines only 5023N/A# cputimes 1 # print every 1 second 5023N/A# cputimes -a 10 # print all processes every 10 secs 5023N/A# cputimes -at 8 5 # print top 8 lines every 5 secs 5023N/A# THREADS The following or the process name, 5023N/A# IDLE Idle time - CPU running idle thread 5023N/A# KERNEL Kernel time - Kernel servicing interrupts, ... 5023N/A# PROCESS Process time - PIDs running on the system 5023N/A# TIME (ns) Sum of the CPU time, ns (nanoseconds) 5023N/A# * This takes into account multiple CPU servers, the total 5023N/A# seconds consumed will be a multiple of the CPU count and interval. 5023N/A# Heisenberg's uncertainty principle. 5023N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 5023N/A# The contents of this file are subject to the terms of the 5023N/A# Common Development and Distribution License, Version 1.0 only 5023N/A# (the "License"). You may not use this file except in compliance 5023N/A# See the License for the specific language governing permissions 5023N/A# and limitations under the License. 5023N/A# Author: Brendan Gregg [Sydney, Australia] 5023N/A# 27-Apr-2005 Brendan Gregg Created this. 5023N/A# 22-Sep-2005 " " Fixed a key corruption bug. 5023N/A# 22-Sep-2005 " " Last update. 5023N/A############################## USAGE: cputimes [-ahTV] [-t top] [interval [count]] cputimes # default output -t num # print top num lines only cputimes 1 # print every 1 second cputimes -a 10 # all processes per 10 sec cputimes -at 8 5 # top 8 lines every 5 secs interval=$1; count=-1; shift ################################# # --- Main Program, DTrace --- inline int OPT_all = '$opt_all'; inline int OPT_time = '$opt_time'; inline int OPT_totals = '$opt_totals'; inline int OPT_top = '$opt_top'; inline int INTERVAL = '$interval'; inline int COUNTER = '$count'; /* Initialise variables */ /* Flag this thread as idle */ sysinfo:unix:idle_enter:idlethread /* Save kernel time between running threads */ this->elapsed = timestamp - cpustart[cpu]; @Procs["KERNEL"] = sum(this->elapsed); /* Save the elapsed time of a thread */ /* determine the name for this thread */ program[cpu] = pid == 0 ? idle[cpu] ? "IDLE" : "KERNEL" : OPT_all ? execname : "PROCESS"; this->elapsed = timestamp - cpustart[cpu]; @Procs[program[cpu]] = sum(this->elapsed); cpustart[cpu] = timestamp; /* Record the start time of a thread */ cpustart[cpu] = timestamp; OPT_time ? printf("%Y,\n", walltimestamp) : 1; printf("%16s %16s\n", "THREADS", "TIME (ns)"); OPT_top ? trunc(@Procs, TOP) : 1; printa("%16s %@16d\n", @Procs);