1266987Smarkj/*
2266987Smarkj * This file and its contents are supplied under the terms of the
3266987Smarkj * Common Development and Distribution License ("CDDL"), version 1.0.
4266987Smarkj * You may only use this file in accordance with the terms of version
5266987Smarkj * 1.0 of the CDDL.
6266987Smarkj *
7266987Smarkj * A full copy of the text of the CDDL should have accompanied this
8266987Smarkj * source.  A copy of the CDDL is also available via the Internet at
9266987Smarkj * http://www.illumos.org/license/CDDL.
10266987Smarkj */
11266987Smarkj
12266987Smarkj/*
13266987Smarkj * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
14266987Smarkj */
15266987Smarkj
16266987Smarkj#pragma D option strsize=4k
17266987Smarkj#pragma D option quiet
18266987Smarkj#pragma D option destructive
19266987Smarkj
20266987Smarkj/*
21266987Smarkj * This test reads a JSON string from a USDT probe, roughly simulating the
22266987Smarkj * primary motivating use case for the json() subroutine: filtering
23266987Smarkj * JSON-formatted log messages from a logging subsystem like node-bunyan.
24266987Smarkj */
25266987Smarkj
26266987Smarkjpid$1:a.out:waiting:entry
27266987Smarkj{
28266987Smarkj	this->value = (int *)alloca(sizeof (int));
29266987Smarkj	*this->value = 1;
30266987Smarkj	copyout(this->value, arg0, sizeof (int));
31266987Smarkj}
32266987Smarkj
33266987Smarkjbunyan*$1:::log-*
34266987Smarkj{
35266987Smarkj	this->j = copyinstr(arg0);
36266987Smarkj}
37266987Smarkj
38266987Smarkjbunyan*$1:::log-*
39266987Smarkj/json(this->j, "finished") == NULL && json(this->j, "action") != "ignore"/
40266987Smarkj{
41266987Smarkj	this->index = strtoll(json(this->j, "index"));
42266987Smarkj	this->size = json(this->j, "sizes[2]");
43266987Smarkj	this->odd = json(this->j, "facts.odd");
44266987Smarkj	this->even = json(this->j, "facts.even");
45266987Smarkj	printf("[%d] sz %s odd %s even %s\n", this->index, this->size,
46266987Smarkj	    this->odd, this->even);
47266987Smarkj}
48266987Smarkj
49266987Smarkjbunyan*$1:::log-*
50266987Smarkj/json(this->j, "finished") != NULL/
51266987Smarkj{
52266987Smarkj	printf("FINISHED!\n");
53266987Smarkj	exit(0);
54266987Smarkj}
55266987Smarkj
56266987Smarkjtick-10s
57266987Smarkj{
58266987Smarkj	printf("ERROR: Timed out before finish message!\n");
59266987Smarkj	exit(1);
60266987Smarkj}
61266987Smarkj
62266987SmarkjERROR
63266987Smarkj{
64266987Smarkj	exit(1);
65266987Smarkj}
66