1210753Srpaulo#!/bin/ksh
2210753Srpaulo#
3210753Srpaulo# CDDL HEADER START
4210753Srpaulo#
5210753Srpaulo# The contents of this file are subject to the terms of the
6210753Srpaulo# Common Development and Distribution License (the "License").
7210753Srpaulo# You may not use this file except in compliance with the License.
8210753Srpaulo#
9210753Srpaulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10210753Srpaulo# or http://www.opensolaris.org/os/licensing.
11210753Srpaulo# See the License for the specific language governing permissions
12210753Srpaulo# and limitations under the License.
13210753Srpaulo#
14210753Srpaulo# When distributing Covered Code, include this CDDL HEADER in each
15210753Srpaulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16210753Srpaulo# If applicable, add the following below this CDDL HEADER, with the
17210753Srpaulo# fields enclosed by brackets "[]" replaced with your own identifying
18210753Srpaulo# information: Portions Copyright [yyyy] [name of copyright owner]
19210753Srpaulo#
20210753Srpaulo# CDDL HEADER END
21210753Srpaulo#
22210753Srpaulo
23210753Srpaulo#
24210753Srpaulo# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25210753Srpaulo# Use is subject to license terms.
26210753Srpaulo#
27210753Srpaulo
28210753Srpaulo#
29210753Srpaulo# This script ensures that we can enable a probe which specifies a platform
30210753Srpaulo# specific event.
31210753Srpaulo#
32210753Srpaulo
33210753Srpauloif [ $# != 1 ]; then
34210753Srpaulo        print -u2 "expected one argument: <dtrace-path>"
35210753Srpaulo        exit 2
36210753Srpaulofi
37210753Srpaulo
38210753Srpaulodtrace=$1
39210753Srpaulo
40210753Srpauloget_event()
41210753Srpaulo{
42210753Srpaulo        perl /dev/stdin /dev/stdout << EOF
43210753Srpaulo        open CPUSTAT, '/usr/sbin/cpustat -h |'
44210753Srpaulo            or die  "Couldn't run cpustat: \$!\n";
45210753Srpaulo        while (<CPUSTAT>) {
46210753Srpaulo                if (/(\s+)event\[*[0-9]-*[0-9]*\]*:/ && !/PAPI/) {
47210753Srpaulo                        @a = split(/ /, \$_);
48210753Srpaulo                        \$event = \$a[\$#a-1];
49210753Srpaulo                }
50210753Srpaulo        }
51210753Srpaulo
52210753Srpaulo        close CPUSTAT;
53210753Srpaulo        print "\$event\n";
54210753SrpauloEOF
55210753Srpaulo}
56210753Srpaulo
57210753Srpauloscript()
58210753Srpaulo{
59210753Srpaulo        $dtrace -s /dev/stdin << EOD
60210753Srpaulo        #pragma D option quiet
61210753Srpaulo        #pragma D option bufsize=128k
62210753Srpaulo
63210753Srpaulo        cpc:::$1-all-10000
64210753Srpaulo        {
65210753Srpaulo                @[probename] = count();
66210753Srpaulo        }
67210753Srpaulo
68210753Srpaulo        tick-1s
69210753Srpaulo        /n++ > 5/
70210753Srpaulo        {
71210753Srpaulo                exit(0);
72210753Srpaulo        }
73210753SrpauloEOD
74210753Srpaulo}
75210753Srpaulo
76210753Srpauloevent=$(get_event)
77210753Srpauloscript $event
78210753Srpaulo
79210753Srpaulostatus=$?
80210753Srpaulo
81210753Srpauloexit $status
82