1238106Sdes#!/usr/sbin/dtrace -s 2238106Sdes/* 3238106Sdes * cpuwalk.d - Measure which CPUs a process runs on. 4238106Sdes * Written using DTrace (Solaris 10 3/05) 5238106Sdes * 6238106Sdes * This program is for multi-CPU servers, and can help identify if a process 7238106Sdes * is running on multiple CPUs concurrently or not. 8238106Sdes * 9238106Sdes * $Id: cpuwalk.d 3 2007-08-01 10:50:08Z brendan $ 10238106Sdes * 11238106Sdes * USAGE: cpuwalk.d [duration] 12238106Sdes * eg, 13238106Sdes * cpuwalk.d 10 # sample for 10 seconds 14238106Sdes * cpuwalk.d # sample until Ctrl-C is hit 15238106Sdes * 16238106Sdes * FIELDS: 17238106Sdes * value CPU id 18238106Sdes * count Number of 1000 hz samples on this CPU 19238106Sdes * 20238106Sdes * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 21238106Sdes * 22238106Sdes * CDDL HEADER START 23238106Sdes * 24269257Sdes * The contents of this file are subject to the terms of the 25269257Sdes * Common Development and Distribution License, Version 1.0 only 26269257Sdes * (the "License"). You may not use this file except in compliance 27269257Sdes * with the License. 28269257Sdes * 29269257Sdes * You can obtain a copy of the license at Docs/cddl1.txt 30269257Sdes * or http://www.opensolaris.org/os/licensing. 31269257Sdes * See the License for the specific language governing permissions 32269257Sdes * and limitations under the License. 33269257Sdes * 34238106Sdes * CDDL HEADER END 35238106Sdes * 36238106Sdes * 22-Sep-2005 Brendan Gregg Created this. 37238106Sdes * 14-Feb-2006 " " Last update. 38238106Sdes */ 39238106Sdes 40238106Sdes#pragma D option quiet 41238106Sdes#pragma D option defaultargs 42238106Sdes 43238106Sdesinline int MAXCPUID = 1024; 44238106Sdes 45238106Sdesdtrace:::BEGIN 46238106Sdes{ 47238106Sdes $1 ? printf("Sampling...\n") : 48238106Sdes printf("Sampling... Hit Ctrl-C to end.\n"); 49238106Sdes seconds = 0; 50238106Sdes} 51238106Sdes 52238106Sdesprofile:::profile-1000hz 53238106Sdes/pid/ 54238106Sdes{ 55238106Sdes @sample[pid, execname] = lquantize(cpu, 0, MAXCPUID, 1); 56238106Sdes} 57238106Sdes 58238106Sdesprofile:::tick-1sec 59238106Sdes{ 60238106Sdes seconds++; 61238106Sdes} 62238106Sdes 63238106Sdesprofile:::tick-1sec 64291767Sdes/seconds == $1/ 65291767Sdes{ 66291767Sdes exit(0); 67294190Sdes} 68291767Sdes 69291767Sdesdtrace:::END 70238106Sdes{ 71238106Sdes printa("\n PID: %-8d CMD: %s\n%@d", @sample); 72238106Sdes} 73238106Sdes