Home | History | Annotate | Download | only in examples
      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 TestTarget {
     33  1449  tomee     public static void
     34  1449  tomee     main(String[] args)
     35  1449  tomee     {
     36  1449  tomee 	if (args.length != 2) {
     37  1449  tomee 	    System.err.println("Usage: java TestTarget <script> <command>");
     38  1449  tomee 	    System.exit(2);
     39  1449  tomee 	}
     40  1449  tomee 
     41  1449  tomee 	File file = new File(args[0]);
     42  1449  tomee 	String command = args[1];
     43  1449  tomee 
     44  1449  tomee 	final Consumer consumer = new LocalConsumer();
     45  1449  tomee 	consumer.addConsumerListener(new ConsumerAdapter() {
     46  1449  tomee 	    public void dataReceived(DataEvent e) {
     47  1449  tomee 		System.out.println(e.getProbeData());
     48  1449  tomee 	    }
     49  1449  tomee 	    public void consumerStopped(ConsumerEvent e) {
     50  1449  tomee 		try {
     51  1449  tomee 		    Aggregate a = consumer.getAggregate();
     52  1449  tomee 		    for (Aggregation agg : a.asMap().values()) {
     53  1449  tomee 			for (AggregationRecord rec : agg.asMap().values()) {
     54  1449  tomee 			    System.out.println(rec.getTuple() + " " +
     55  1449  tomee 				    rec.getValue());
     56  1449  tomee 			}
     57  1449  tomee 		    }
     58  1449  tomee 		} catch (Exception x) {
     59  1449  tomee 		    x.printStackTrace();
     60  1449  tomee 		    System.exit(1);
     61  1449  tomee 		}
     62  1449  tomee 		consumer.close();
     63  1449  tomee 	    }
     64  1449  tomee 	    public void processStateChanged(ProcessEvent e) {
     65  1449  tomee 		System.out.println(e.getProcessState());
     66  1449  tomee 	    }
     67  1449  tomee 	});
     68  1449  tomee 
     69  1449  tomee 	try {
     70  1449  tomee 	    consumer.open();
     71  1449  tomee 	    // pid replaces $target variable in D script
     72  1449  tomee 	    consumer.createProcess(command);
     73  1449  tomee 	    consumer.compile(file);
     74  1449  tomee 	    consumer.enable();
     75  1449  tomee 	    consumer.go();
     76  1449  tomee 	} catch (Exception e) {
     77  1449  tomee 	    e.printStackTrace();
     78  1449  tomee 	    System.exit(1);
     79  1449  tomee 	}
     80  1449  tomee     }
     81  1449  tomee }
     82