4477 DTrace should speak JSON
[illumos-gate.git] / usr / src / cmd / dtrace / test / tst / common / json / tst.usdt.c
blob307106d903b5eee020869d6f5036a8b5fcc38def
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.
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.
13 * Copyright 2012 (c), Joyent, Inc. All rights reserved.
16 #include <sys/sdt.h>
17 #include "usdt.h"
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"
29 int
30 waiting(volatile int *a)
32 return (*a);
35 int
36 main(int argc, char **argv)
38 volatile int a = 0;
39 int idx;
40 double size = 250.5;
42 while (waiting(&a) == 0)
43 continue;
45 for (idx = 0; idx < 10; idx++) {
46 char *odd, *even, *json, *action;
48 size *= 1.78;
49 odd = idx % 2 == 1 ? "true" : "false";
50 even = idx % 2 == 0 ? "true" : "false";
51 action = idx == 7 ? "ignore" : "print";
53 asprintf(&json, FMT, size, idx, odd, even, action);
54 BUNYAN_FAKE_LOG_DEBUG(json);
55 free(json);
58 BUNYAN_FAKE_LOG_DEBUG("{\"finished\": true}");
60 return (0);