xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/pragma/tst.temporal2.ksh (revision 5e989a96186a37eb528fb7bb4d28a150874ec799)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2012 by Delphix. All rights reserved.
19#
20
21############################################################################
22# ASSERTION:
23#	temporal option causes output to be sorted, even when some
24#	buffers are empty
25#
26# SECTION: Pragma
27#
28# NOTES: The temporal option has no effect on a single-CPU system, so
29#    this needs to be run on a multi-CPU system to effectively test the
30#    temporal option.
31#
32############################################################################
33
34if [ $# != 1 ]; then
35	echo expected one argument: '<'dtrace-path'>'
36	exit 2
37fi
38
39dtrace=$1
40file=/tmp/out.$$
41
42rm -f $file
43
44$dtrace -o $file -s /dev/stdin <<EOF
45	#pragma D option quiet
46	#pragma D option destructive
47	#pragma D option temporal
48	#pragma D option switchrate=1000hz
49
50	/*
51	 * Use two enablings of the same probe, so that cpu 0 will always
52	 * record its data just a little bit before the other cpus.
53	 * We don't want to use the chill() action in the same enabling
54	 * that we record the timestamp, because chill() causes the
55	 * timestamp to be re-read, and thus not match the timestamp
56	 * which libdtrace uses to sort the records.
57	 */
58
59	profile-401
60	/cpu == 0/
61	{
62		printf("%d\n", timestamp);
63	}
64
65	profile-401
66	/cpu != 0/
67	{
68		chill(1000); /* one microsecond */
69	}
70
71	profile-401
72	/cpu != 0/
73	{
74		printf("%d\n", timestamp);
75	}
76
77	tick-1s
78	/k++ == 10/
79	{
80		printf("%d\n", timestamp);
81		exit(0);
82	}
83EOF
84
85status=$?
86if [ "$status" -ne 0 ]; then
87	echo $tst: dtrace failed
88	exit $status
89fi
90
91# dtrace outputs a blank line at the end, which will sort to the beginning,
92# so use grep to remove the blank line.
93head -n -1 $file > $file.2
94
95sort -n $file.2 | diff $file.2 -
96status=$?
97if [ "$status" -ne 0 ]; then
98	echo $tst: output is not sorted
99	exit $status
100fi
101
102exit $status
103