001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.benchmark;
022:
023: /**
024: * <tt>Stats</tt> is used to run a benchmark using an instrumented Java
025: * Virtual machine that counts the number of each kind of bytecodes executed.
026: * The counts are maintained in two C variables, <tt>instruction_count</tt>
027: * and <tt>redundant_count</tt>.
028: */
029: public class Stats {
030:
031: static {
032: System.loadLibrary("stats");
033: }
034:
035: public static native void run(Class main, String[] args);
036:
037: public static void main(final String[] args) throws Exception {
038: int runs = 1;
039: int eat = 0;
040:
041: if (args.length <= 1) {
042: Stats.usage();
043: }
044:
045: for (eat = 0; eat < args.length; eat++) {
046: if (args[eat].equals("-run")) {
047: if (++eat >= args.length) {
048: Stats.usage();
049: }
050:
051: runs = Integer.parseInt(args[eat]);
052:
053: if (runs <= 0) {
054: Stats.usage();
055: }
056:
057: } else {
058: // The main class
059: eat++;
060: break;
061: }
062: }
063:
064: /* Got all the args. */
065: if (eat > args.length) {
066: Stats.usage();
067: }
068:
069: final BenchmarkSecurityManager sec = new BenchmarkSecurityManager();
070: System.setSecurityManager(sec);
071:
072: final String mainClassName = args[eat - 1];
073: final String[] a = new String[args.length - eat];
074:
075: System.err.println("Running " + mainClassName);
076:
077: for (int i = 0; i < runs; i++) {
078: try {
079: final Class mainClass = Class.forName(mainClassName);
080:
081: System.arraycopy(args, eat, a, 0, a.length);
082:
083: Stats.run(mainClass, a);
084:
085: } catch (final SecurityException e) {
086: continue;
087:
088: } catch (final Exception e) {
089: e.printStackTrace(System.err);
090: sec.allowExit = true;
091: System.exit(1);
092: }
093: }
094:
095: sec.allowExit = true;
096: }
097:
098: private static void usage() {
099: System.err.print("usage: java EDU.purdue.cs.bloat.Stats ");
100: System.err.println("options class args...");
101: System.err.println("where options are one of:");
102: System.err.println(" -run n time n runs of the program");
103: System.exit(1);
104: }
105: }
|