Package org.jamesii.core.util

Examples of org.jamesii.core.util.StopWatch


    // execute the garbage collector
    System.gc();
    try {
      println("Memory (): " + Runtime.getRuntime().totalMemory() + " : "
          + Runtime.getRuntime().freeMemory());
      StopWatch sw = new StopWatch();
      sw.start();
      IModel model = createModel();
      sw.stop();
      result.modelCreation = sw.elapsedSeconds();
      println("Seconds needed for creating the model: " + sw.elapsedSeconds());
      println("Memory (model - [total:free]): "
          + Runtime.getRuntime().totalMemory() + " : "
          + Runtime.getRuntime().freeMemory());

      println("Simulation started at "
          + new SimpleDateFormat().format(new Date()));
      ISimulationRun simulation = null;
      sw.reset();
      sw.start();
      if (parameters.useMasterServer()) {
        // TODO master server deactivated, January, 2009 - model should be
        // created on the exec. host, not here!
        // System.out.println("The simulation will be executed on the server: "
        // + parameters.getMasterServerName());
        // simulation = parameters.getMasterServer().createSimulation(
        // model,
        // new SimulationConfiguration(1, null, null, parameters
        // .getParameterBlock())).getSimulation();

      } else { // if we don't use a server we create a simulation on our own
        TaskConfiguration config =
            new TaskConfiguration(1, null, null, parameters.getParameterBlock());
        SimulationRunConfiguration srConfig =
            (SimulationRunConfiguration) config
                .newComputationTaskConfiguration(new ComputationTaskIDObject());
        simulation = new SimulationRun("SimRun", model, srConfig, null);
      }
      if (simulation == null) {
        SimSystem.report(Level.SEVERE, "Simulation creation failed!!!");
      }
      sw.stop();
      result.simulationCreation = sw.elapsedSeconds();
      println("Seconds needed for creating the simulation: "
          + sw.elapsedSeconds());
      println("Memory (model + simulation - [total:free]): "
          + Runtime.getRuntime().totalMemory() + " : "
          + Runtime.getRuntime().freeMemory());
      sw.reset();
      sw.start();
      if (parameters.useMasterServer()) {
        int tries = 0;
        boolean retry = true;
        while (retry) {
          retry = false;
          try {
            parameters.getMasterServer().execute(
                simulation.getUniqueIdentifier(), null);
          } catch (Exception e) {
            SimSystem.report(Level.SEVERE,
                "Error occured while trying to launch the model on the server");
            tries++;
            if (tries == 3) {
              SimSystem.report(Level.SEVERE,
                  " - stop retrying ... something seems to be wrong with the server "
                      + parameters.getMasterServerName());
              throw e; // rethrow exception
            }

            retry = true;
            SimSystem.report(Level.INFO,
                " - now retrying ... waiting some seconds ...");
            // parameters.findServer(name); refind the server????
            Thread.sleep(2000); // wait two seconds
            SimSystem.report(Level.INFO,
                "   resetting stopwatch ... restarting simulation ...");
            sw.reset();
            sw.start();
          }
        }
      } else { // if we don't use a server we create a simlation on our own
        simulation.start();
      }
      sw.stop();
      result.simulationRun = sw.elapsedSeconds();
      println("Seconds needed for running the simulation: "
          + sw.elapsedSeconds());
      // simulation.stop();
    } catch (Exception e) {
      SimSystem.report(e);
      throw new RuntimeException(e.getMessage(), e);
    }
View Full Code Here


      out = new PrintStream(fsgen);

      // print information about the system
      println(SimSystem.getVMInfo());

      StopWatch sw = new StopWatch();

      results = new ArrayList<>();

      int counter = 0;

      sw.start();

      while (moreExperimentsToDo()) {

        println("@@@@@@@@@@@@@@@@ experiment (#" + ++counter
            + ") starting @@@@@@@@@@@@@@@@");

        List<RunResult> currentResults = new ArrayList<>();
        results.add(currentResults);
        Parameters parameters = setupExperiment();
        for (int i = 0; i < repeatEachExperiment; i++) {
          println("---------------- sim run (#" + counter + "." + (i + 1)
              + ") starting ----------------");
          currentResults.add(run(parameters));
        }

        experimentDone(currentResults);

        if (filename != null) {
          try {
            FileOutputStream fs = new FileOutputStream(filename, true);
            try (PrintStream p = new PrintStream(fs)) {
              p.println(getResultsAsString(currentResults));
            }
          } catch (Exception e) {
            SimSystem.report(e);
          }

        }

      }

      sw.stop();
      println("Seconds needed for all experiments " + sw.elapsedSeconds());

    } catch (Exception e) {
      SimSystem.report(e);
    }
  }
View Full Code Here

    String command;

    /**
     * Stopwatch for measuring execution time
     */
    StopWatch stopwatch = new StopWatch();

    /**
     * This slot holds the string tonkenizer used to break the data, typed by
     * the user into the stream System.in, into tokens.
     */
    ConsoleTokenizer tokenizer;

    // slots indicating chosen command
    // CommandAction action = null; whatever I wanted to do with this ...

    String param = null;

    lastCommands.add(commandLine);

    tokenizer = new ConsoleTokenizer(commandLine);

    if (tokenizer.hasMoreTokens()) {

      // read first command (must be a word)
      command = tokenizer.nextToken();

      /*
       * if ((command.compareTo("") == 0) && (tokenizer.hasMoreTokens())) {
       * command = parseExpression(c) }
       */

      Command com = commands.get(command);

      if (com == null) {
        try {
          out.println(parseExpression(commandLine));
        } catch (RuntimeException e) {
          out.println("Invalid expression and unknown command '" + command
              + "' Type help for getting more information about valid commands");
        }

      } else {

        Command subCom = com;
        while ((subCom.hasSubCommand() || subCom.takesParameter())
            && tokenizer.hasMoreTokens()) {

          // System.err.println(command + " with sub part");

          // read next token and skip first token
          command = tokenizer.nextToken();

          // System.err.println(command + " is next part");

          if (subCom.hasSubCommand(command)) {
            subCom = subCom.getSubCommand(command);
            // System.err.println(subCom);
          } else {
            if (param == null) {
              param = parseExpression(command);
            } else {
              param += " " + command;
            }

          }

        } // end of while

        stopwatch.start();

        // execute the command
        subCom.action.execute(param);

        stopwatch.stop();

        if (measureTime) {
          out.println("Execution of the command " + command + " ("
              + commandLine + ") took " + stopwatch.elapsedSeconds()
              + " seconds");
        }

      }
    } // if at least one token
View Full Code Here

      }

      it.absolute(101);
      assertEquals(100, it.index());

      StopWatch sw = new StopWatch();
      sw.start();
      for (int i = 0; i < 100001; i++) {
        it.write("This is an additonal line " + i);
      }
      sw.stop();
      System.out.println(sw.elapsedSeconds());
      it.next();
      assertEquals(101, it.index());

    } catch (SQLException e) {
View Full Code Here

TOP

Related Classes of org.jamesii.core.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.