1 1449 tomee /* 2 1449 tomee * CDDL HEADER START 3 1449 tomee * 4 1449 tomee * The contents of this file are subject to the terms of the 5 1449 tomee * Common Development and Distribution License (the "License"). 6 1449 tomee * You may not use this file except in compliance with the License. 7 1449 tomee * 8 1449 tomee * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 1449 tomee * or http://www.opensolaris.org/os/licensing. 10 1449 tomee * See the License for the specific language governing permissions 11 1449 tomee * and limitations under the License. 12 1449 tomee * 13 1449 tomee * When distributing Covered Code, include this CDDL HEADER in each 14 1449 tomee * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 1449 tomee * If applicable, add the following below this CDDL HEADER, with the 16 1449 tomee * fields enclosed by brackets "[]" replaced with your own identifying 17 1449 tomee * information: Portions Copyright [yyyy] [name of copyright owner] 18 1449 tomee * 19 1449 tomee * CDDL HEADER END 20 1449 tomee */ 21 1449 tomee 22 1449 tomee /* 23 1449 tomee * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 1449 tomee * Use is subject to license terms. 25 1449 tomee * 26 1449 tomee * ident "%Z%%M% %I% %E% SMI" 27 1449 tomee */ 28 1449 tomee 29 1449 tomee import org.opensolaris.os.dtrace.*; 30 1449 tomee import java.io.File; 31 1449 tomee 32 1449 tomee public class TestAPI2 { 33 1449 tomee public static void 34 1449 tomee main(String[] args) 35 1449 tomee { 36 1449 tomee if (args.length < 1) { 37 1449 tomee System.err.println("Usage: java TestAPI2 <script> " + 38 1449 tomee "[ macroargs... ]"); 39 1449 tomee System.exit(2); 40 1449 tomee } 41 1449 tomee 42 1449 tomee File file = new File(args[0]); 43 1449 tomee String[] macroArgs = new String[args.length - 1]; 44 1449 tomee System.arraycopy(args, 1, macroArgs, 0, (args.length - 1)); 45 1449 tomee 46 1449 tomee Consumer consumer = new LocalConsumer(); 47 1449 tomee consumer.addConsumerListener(new ConsumerAdapter() { 48 1449 tomee public void dataReceived(DataEvent e) { 49 1449 tomee // System.out.println(e.getProbeData()); 50 1449 tomee ProbeData data = e.getProbeData(); 51 1449 tomee java.util.List < Record > records = data.getRecords(); 52 1449 tomee for (Record r : records) { 53 1449 tomee if (r instanceof ExitRecord) { 54 1449 tomee } else { 55 1449 tomee System.out.println(r); 56 1449 tomee } 57 1449 tomee } 58 1449 tomee } 59 1449 tomee }); 60 1449 tomee 61 1449 tomee try { 62 1449 tomee consumer.open(); 63 1449 tomee consumer.compile(file, macroArgs); 64 1449 tomee consumer.enable(); 65 1449 tomee consumer.go(); 66 1449 tomee 67 1449 tomee Aggregate a; 68 1449 tomee do { 69 1449 tomee Thread.sleep(1000); 70 1449 tomee a = consumer.getAggregate(); 71 1449 tomee if (!a.asMap().isEmpty()) { 72 1449 tomee System.out.println(a); 73 1449 tomee } 74 1449 tomee } while (consumer.isRunning()); 75 1449 tomee } catch (Exception e) { 76 1449 tomee e.printStackTrace(); 77 1449 tomee System.exit(1); 78 1449 tomee } 79 1449 tomee } 80 1449 tomee } 81