xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/misc/tst.dofmax.ksh (revision 5422785d352a2bb398daceab3d1898a8aa64d006)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24#
25
26let j=8
27
28enable()
29{
30	prog=/var/tmp/dtest.$$.d
31	err=/var/tmp/dtest.$$.err
32
33	nawk -v nprobes=$1 'BEGIN { \
34		for (i = 0; i < nprobes - 1; i++) { 		\
35			printf("dtrace:::BEGIN,\n");		\
36		}						\
37								\
38		printf("dtrace:::BEGIN { exit(0); }\n");	\
39	}' /dev/null > $prog
40
41	dtrace -qs $prog > /dev/null 2> $err
42
43	if [[ "$?" -eq 0 ]]; then
44		return 0
45	else
46		if ! grep "DIF program exceeds maximum program size" $err \
47		    1> /dev/null 2>&1 ; then
48			echo "failed to enable $prog: `cat $err`"
49			exit 1
50		fi
51
52		return 1
53	fi
54}
55
56#
57# First, establish an upper bound
58#
59let upper=1
60
61while enable $upper ; do
62	let lower=upper
63	let upper=upper+upper
64	echo success at $lower, raised to $upper
65done
66
67#
68# Now search for the highest value that can be enabled
69#
70while [[ "$lower" -lt "$upper" ]]; do
71	let guess=$(((lower + upper) / 2))
72	echo "lower is $lower; upper is $upper; guess is $guess\c"
73
74	if enable $guess ; then
75		if [[ $((upper - lower)) -le 2 ]]; then
76			let upper=guess
77		fi
78
79		echo " (success)"
80		let lower=guess
81	else
82		echo " (failure)"
83		let upper=guess
84	fi
85done
86
87let expected=10000
88
89if [[ "$lower" -lt "$expected" ]]; then
90	echo "expected support for enablings of at least $expected probes; \c"
91	echo "found $lower"
92	exit 1
93fi
94
95echo "maximum supported enabled probes found to be $lower"
96exit 0
97
98