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