]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/json/tst.usdt.c
MFC r277912,r278738,r279418,r280835,r288416:
[FreeBSD/stable/10.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / json / tst.usdt.c
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 <stdio.h>
18 #include <stdlib.h>
19 #include "usdt.h"
20
21 #define FMT     "{" \
22                 "  \"sizes\": [ \"first\", 2, %f ]," \
23                 "  \"index\": %d," \
24                 "  \"facts\": {" \
25                 "    \"odd\": \"%s\"," \
26                 "    \"even\": \"%s\"" \
27                 "  }," \
28                 "  \"action\": \"%s\"" \
29                 "}\n"
30
31 int
32 waiting(volatile int *a)
33 {
34         return (*a);
35 }
36
37 int
38 main(int argc, char **argv)
39 {
40         volatile int a = 0;
41         int idx;
42         double size = 250.5;
43
44         while (waiting(&a) == 0)
45                 continue;
46
47         for (idx = 0; idx < 10; idx++) {
48                 char *odd, *even, *json, *action;
49
50                 size *= 1.78;
51                 odd = idx % 2 == 1 ? "true" : "false";
52                 even = idx % 2 == 0 ? "true" : "false";
53                 action = idx == 7 ? "ignore" : "print";
54
55                 asprintf(&json, FMT, size, idx, odd, even, action);
56                 BUNYAN_FAKE_LOG_DEBUG(json);
57                 free(json);
58         }
59
60         BUNYAN_FAKE_LOG_DEBUG("{\"finished\": true}");
61
62         return (0);
63 }