xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/json/tst.usdt.c (revision 97a9db610324e7db4393415018e0e737485a94cd)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2012 (c), Joyent, Inc.  All rights reserved.
14  */
15 
16 #include <sys/sdt.h>
17 #include "usdt.h"
18 
19 #define	FMT	"{" \
20 		"  \"sizes\": [ \"first\", 2, %f ]," \
21 		"  \"index\": %d," \
22 		"  \"facts\": {" \
23 		"    \"odd\": \"%s\"," \
24 		"    \"even\": \"%s\"" \
25 		"  }," \
26 		"  \"action\": \"%s\"" \
27 		"}\n"
28 
29 int
30 waiting(volatile int *a)
31 {
32 	return (*a);
33 }
34 
35 int
36 main(int argc, char **argv)
37 {
38 	volatile int a = 0;
39 	int idx;
40 	double size = 250.5;
41 
42 	while (waiting(&a) == 0)
43 		continue;
44 
45 	for (idx = 0; idx < 10; idx++) {
46 		char *odd, *even, *json, *action;
47 
48 		size *= 1.78;
49 		odd = idx % 2 == 1 ? "true" : "false";
50 		even = idx % 2 == 0 ? "true" : "false";
51 		action = idx == 7 ? "ignore" : "print";
52 
53 		asprintf(&json, FMT, size, idx, odd, even, action);
54 		BUNYAN_FAKE_LOG_DEBUG(json);
55 		free(json);
56 	}
57 
58 	BUNYAN_FAKE_LOG_DEBUG("{\"finished\": true}");
59 
60 	return (0);
61 }
62