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