1235368Sgnn#!/usr/sbin/dtrace -s 2235368Sgnn/* 3235368Sgnn * cpuwalk.d - Measure which CPUs a process runs on. 4235368Sgnn * Written using DTrace (Solaris 10 3/05) 5235368Sgnn * 6235368Sgnn * This program is for multi-CPU servers, and can help identify if a process 7235368Sgnn * is running on multiple CPUs concurrently or not. 8235368Sgnn * 9235368Sgnn * $Id: cpuwalk.d 3 2007-08-01 10:50:08Z brendan $ 10235368Sgnn * 11235368Sgnn * USAGE: cpuwalk.d [duration] 12235368Sgnn * eg, 13235368Sgnn * cpuwalk.d 10 # sample for 10 seconds 14235368Sgnn * cpuwalk.d # sample until Ctrl-C is hit 15235368Sgnn * 16235368Sgnn * FIELDS: 17235368Sgnn * value CPU id 18235368Sgnn * count Number of 1000 hz samples on this CPU 19235368Sgnn * 20235368Sgnn * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 21235368Sgnn * 22235368Sgnn * CDDL HEADER START 23235368Sgnn * 24235368Sgnn * The contents of this file are subject to the terms of the 25235368Sgnn * Common Development and Distribution License, Version 1.0 only 26235368Sgnn * (the "License"). You may not use this file except in compliance 27235368Sgnn * with the License. 28235368Sgnn * 29235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 30235368Sgnn * or http://www.opensolaris.org/os/licensing. 31235368Sgnn * See the License for the specific language governing permissions 32235368Sgnn * and limitations under the License. 33235368Sgnn * 34235368Sgnn * CDDL HEADER END 35235368Sgnn * 36235368Sgnn * 22-Sep-2005 Brendan Gregg Created this. 37235368Sgnn * 14-Feb-2006 " " Last update. 38235368Sgnn */ 39235368Sgnn 40235368Sgnn#pragma D option quiet 41235368Sgnn#pragma D option defaultargs 42235368Sgnn 43235368Sgnninline int MAXCPUID = 1024; 44235368Sgnn 45235368Sgnndtrace:::BEGIN 46235368Sgnn{ 47235368Sgnn $1 ? printf("Sampling...\n") : 48235368Sgnn printf("Sampling... Hit Ctrl-C to end.\n"); 49235368Sgnn seconds = 0; 50235368Sgnn} 51235368Sgnn 52235368Sgnnprofile:::profile-1000hz 53235368Sgnn/pid/ 54235368Sgnn{ 55235368Sgnn @sample[pid, execname] = lquantize(cpu, 0, MAXCPUID, 1); 56235368Sgnn} 57235368Sgnn 58235368Sgnnprofile:::tick-1sec 59235368Sgnn{ 60235368Sgnn seconds++; 61235368Sgnn} 62235368Sgnn 63235368Sgnnprofile:::tick-1sec 64235368Sgnn/seconds == $1/ 65235368Sgnn{ 66235368Sgnn exit(0); 67235368Sgnn} 68235368Sgnn 69235368Sgnndtrace:::END 70235368Sgnn{ 71235368Sgnn printa("\n PID: %-8d CMD: %s\n%@d", @sample); 72235368Sgnn} 73