1*e137d3e0Schristos #!/usr/sbin/dtrace -s 2*e137d3e0Schristos /* 3*e137d3e0Schristos * threaded.d - sample multi-threaded CPU usage. 4*e137d3e0Schristos * Written using DTrace (Solaris 10 3/05). 5*e137d3e0Schristos * 6*e137d3e0Schristos * This measures thread IDs as a process runs across multiple CPUs. 7*e137d3e0Schristos * It is a simple script that can help determine if a multi-threaded 8*e137d3e0Schristos * application is effectively using it's threads, or if the threads have 9*e137d3e0Schristos * serialised. See the example file in Docs/Examples/threaded_example.txt 10*e137d3e0Schristos * for a demonstration. 11*e137d3e0Schristos * 12*e137d3e0Schristos * $Id: threaded.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 13*e137d3e0Schristos * 14*e137d3e0Schristos * USAGE: threaded.d 15*e137d3e0Schristos * 16*e137d3e0Schristos * FIELDS: 17*e137d3e0Schristos * PID process ID 18*e137d3e0Schristos * CMD process name 19*e137d3e0Schristos * value thread ID 20*e137d3e0Schristos * count number of samples 21*e137d3e0Schristos * 22*e137d3e0Schristos * SEE ALSO: prstat -L 23*e137d3e0Schristos * 24*e137d3e0Schristos * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 25*e137d3e0Schristos * 26*e137d3e0Schristos * CDDL HEADER START 27*e137d3e0Schristos * 28*e137d3e0Schristos * The contents of this file are subject to the terms of the 29*e137d3e0Schristos * Common Development and Distribution License, Version 1.0 only 30*e137d3e0Schristos * (the "License"). You may not use this file except in compliance 31*e137d3e0Schristos * with the License. 32*e137d3e0Schristos * 33*e137d3e0Schristos * You can obtain a copy of the license at Docs/cddl1.txt 34*e137d3e0Schristos * or http://www.opensolaris.org/os/licensing. 35*e137d3e0Schristos * See the License for the specific language governing permissions 36*e137d3e0Schristos * and limitations under the License. 37*e137d3e0Schristos * 38*e137d3e0Schristos * CDDL HEADER END 39*e137d3e0Schristos * 40*e137d3e0Schristos * Author: Brendan Gregg [Sydney, Australia] 41*e137d3e0Schristos * 42*e137d3e0Schristos * 25-Jul-2005 Brendan Gregg Created this. 43*e137d3e0Schristos * 25-Jul-2005 " " Last update. 44*e137d3e0Schristos */ 45*e137d3e0Schristos 46*e137d3e0Schristos #pragma D option quiet 47*e137d3e0Schristos 48*e137d3e0Schristos /* 49*e137d3e0Schristos * Sample at 100 Hertz 50*e137d3e0Schristos */ 51*e137d3e0Schristos profile:::profile-100 52*e137d3e0Schristos /pid != 0/ 53*e137d3e0Schristos { 54*e137d3e0Schristos @sample[pid, execname] = lquantize(tid, 0, 128, 1); 55*e137d3e0Schristos } 56*e137d3e0Schristos 57*e137d3e0Schristos /* 58*e137d3e0Schristos * Print output every 1 second 59*e137d3e0Schristos */ 60*e137d3e0Schristos profile:::tick-1sec 61*e137d3e0Schristos { 62*e137d3e0Schristos printf("%Y,\n", walltimestamp); 63*e137d3e0Schristos printa("\n PID: %-8d CMD: %s\n%@d", @sample); 64*e137d3e0Schristos printf("\n"); 65*e137d3e0Schristos trunc(@sample); 66*e137d3e0Schristos } 67