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