001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixcore.testsuite.util;
020:
021: import java.io.File;
022: import java.util.Properties;
023:
024: import org.apache.log4j.PropertyConfigurator;
025:
026: import de.schlund.pfixxml.config.GlobalConfigurator;
027:
028: /**
029: * Command-line utitlity that test the performance of a TargetGenerator.
030: *
031: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
032: */
033: public class TargetGeneratorBenchmarkUtil {
034:
035: public static void main(String[] args) {
036: if (args.length != 3) {
037: System.out
038: .println("Usage: <tool> <depend.xml> <number of threads> <requests per thread>");
039: return;
040: }
041:
042: String dependxml = args[0];
043: String numberofthreads = args[1];
044: String requestsperthread = args[2];
045:
046: //BasicConfigurator.configure(new NullAppender());
047: Properties log4jprops = new Properties();
048: log4jprops.setProperty("log4j.threshold", "OFF");
049: PropertyConfigurator.configure(log4jprops);
050: GlobalConfigurator.setDocroot((new File("projects"))
051: .getAbsolutePath());
052:
053: Properties props = new Properties();
054: props.setProperty("tgenbench.dependxml", dependxml);
055: props.setProperty("tgenbench.numthreads", numberofthreads);
056: props.setProperty("tgenbench.requestsperthread",
057: requestsperthread);
058: try {
059: TargetGeneratorBenchmarkFactory.getInstance().init(props);
060: } catch (Exception e) {
061: e.printStackTrace();
062: return;
063: }
064:
065: TargetGeneratorBenchmarkFactory instance = TargetGeneratorBenchmarkFactory
066: .getInstance();
067:
068: while (true) {
069: int running = 0;
070: for (int i = 0; i < instance.finished.length; i++) {
071: if (!instance.finished[i]) {
072: running++;
073: }
074: }
075: if (running == 0) {
076: break;
077: }
078: System.out.println("Still " + running + " threads running");
079: try {
080: Thread.sleep(5000);
081: } catch (InterruptedException e) {
082: // Ignore
083: }
084: }
085:
086: long sum = 0;
087: for (int i = 0; i < instance.times.length; i++) {
088: sum += instance.times[i];
089: System.out.println("Thread " + (i + 1) + ": "
090: + instance.times[i] + " ms");
091: }
092: for (int i = 0; i < instance.messages.length; i++) {
093: if (instance.messages[i].length() > 0) {
094: System.out
095: .println("Messages in Thread" + (i + 1) + ":");
096: System.out.print(instance.messages[i]);
097: }
098: System.out.println("Thread " + (i + 1) + ": "
099: + instance.times[i] + " ms");
100: }
101: System.out.println("Average time per thread: "
102: + ((double) sum / (double) instance.times.length)
103: + "ms");
104: System.out.println("Total time: " + instance.maxTime + "ms");
105: }
106:
107: }
|