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 (c) 2012, Joyent, Inc. All rights reserved. 14 */ 15 16 #pragma D option strsize=4k 17 #pragma D option quiet 18 #pragma D option destructive 19 20 /* 21 * This test reads a JSON string from a USDT probe, roughly simulating the 22 * primary motivating use case for the json() subroutine: filtering 23 * JSON-formatted log messages from a logging subsystem like node-bunyan. 24 */ 25 26 pid$1:a.out:waiting:entry 27 { 28 this->value = (int *)alloca(sizeof (int)); 29 *this->value = 1; 30 copyout(this->value, arg0, sizeof (int)); 31 } 32 33 bunyan*$1:::log-* 34 { 35 this->j = copyinstr(arg0); 36 } 37 38 bunyan*$1:::log-* 39 /json(this->j, "finished") == NULL && json(this->j, "action") != "ignore"/ 40 { 41 this->index = strtoll(json(this->j, "index")); 42 this->size = json(this->j, "sizes[2]"); 43 this->odd = json(this->j, "facts.odd"); 44 this->even = json(this->j, "facts.even"); 45 printf("[%d] sz %s odd %s even %s\n", this->index, this->size, 46 this->odd, this->even); 47 } 48 49 bunyan*$1:::log-* 50 /json(this->j, "finished") != NULL/ 51 { 52 printf("FINISHED!\n"); 53 exit(0); 54 } 55 56 tick-10s 57 { 58 printf("ERROR: Timed out before finish message!\n"); 59 exit(1); 60 } 61 62 ERROR 63 { 64 exit(1); 65 }