Beispiel #1
0
  /**
   * Compile the given model with the given name. This method invokes other methods of this class to
   * actually perform the compilation.
   */
  public void compile(String modelName, CompositeActor toplevel, GeneratorAttribute attribute)
      throws Exception {
    //  try {
    long startTime = System.currentTimeMillis();

    // Create instance classes for the actors.
    try {
      initialize(toplevel);
    } catch (Throwable ex) {
      System.out.println("initialize() failed: " + ex);
    }

    if (attribute.getParameter("outputDirectory").indexOf(" ") != -1) {
      throw new Exception(
          "The outputDirectory contains one or more "
              + "spaces.  Unfortunately, the Soot option passing "
              + "mechanism does not handle spaces.  The value of "
              + "the outputDirectory parameter was: \""
              + attribute.getParameter("outputDirectory")
              + "\"");
    }

    // Parse any copernicus args.
    String[] sootArgs = _parseArgs(attribute);

    if (sootArgs == null) {
      throw new NullPointerException(
          "Failed to parse args for " + attribute + ", resulting arg array was null");
    }

    // Add Transforms to the Scene.
    addTransforms();

    // Execute the transforms.
    generateCode(sootArgs);

    // Reset the state of the manager.  We haven't actually done
    // anything, but the state of the manager must be reset.
    try {
      _toplevel.getManager().wrapup();
    } catch (Exception exception) {
      // This could be a problem with NonStrictTest.
      throw new KernelRuntimeException(exception, "Could not wrapup composite actor");
    }

    // Print out memory usage info
    System.out.println(modelName + " " + ptolemy.actor.Manager.timeAndMemory(startTime));

    //         } catch (Exception ex) {
    //             System.err.println("Code generation of '" + modelName
    //                     + "' failed:");
    // //             ex.printStackTrace(System.err);
    // //             System.err.flush();
    // //             System.exit(2);
    //         }
  }
Beispiel #2
0
  /**
   * Parse the xml file and run it. If a parameter named "copernicus_iterations" is present, then
   * the value of that parameter is used to set the iterations parameter. If there is no
   * "copernicus_iterations" parameter, then then the number of iterations is set to 100000.
   */
  public TestApplication(String xmlFilename) throws Exception {
    MoMLParser parser = new MoMLParser();

    // The test suite calls MoMLSimpleApplication multiple times,
    // and the list of filters is static, so we reset it each time
    // so as to avoid adding filters every time we run an auto test.
    // We set the list of MoMLFilters to handle Backward Compatibility.
    MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());

    // Filter out any graphical classes.
    // We should filter out graphical classes or the
    // treeShakeWithoutCodegen rule will fail when we run it on
    // actor/lib/test/auto/ComplexDivide.
    MoMLParser.addMoMLFilter(new RemoveGraphicalClasses());

    // parser.setErrorHandler(new StreamErrorHandler());
    // We use parse(URL, URL) here instead of parseFile(String)
    // because parseFile() works best on relative pathnames and
    // has problems finding resources like files specified in
    // parameters if the xml file was specified as an absolute path.
    CompositeActor toplevel = null;

    // First, we gc and then print the memory stats
    // BTW to get more info about gc,
    // use java -verbose:gc -Xloggc:filename . . .
    System.gc();
    Thread.sleep(1000);

    Runtime runtime = Runtime.getRuntime();

    try {
      URL url = new URL(null, xmlFilename);
      toplevel = (CompositeActor) parser.parse(url, url.openStream());
    } catch (Exception ex) {
      File f = new File(xmlFilename);
      URL url = f.toURL();
      System.err.println("Warning: Parsing '" + xmlFilename + "' failed: ");
      ex.printStackTrace();
      System.err.println(" Trying '" + url + "'");

      toplevel = (CompositeActor) parser.parse(null, url);
    }

    // FIXME: nearly duplicate code in kernel/KernelMain.java
    SDFDirector director = (SDFDirector) toplevel.getDirector();

    if (director != null) {
      Parameter iterations = (Parameter) director.getAttribute("iterations");
      Parameter copernicus_iterations = (Parameter) director.getAttribute("copernicus_iterations");

      // Set to be a large number of iterations, unless
      // copernicus_iterations is set.
      if (copernicus_iterations != null) {
        iterations.setToken(copernicus_iterations.getToken());
      } else {
        iterations.setToken(new IntToken(100000));
      }

      System.out.println("TestApplication: Setting Iterations to " + iterations.getToken());
    }

    Manager manager = new Manager(toplevel.workspace(), "TestApplication");
    toplevel.setManager(manager);
    toplevel.addChangeListener(this);

    String modelName = toplevel.getName();

    long startTime = System.currentTimeMillis();
    long totalMemory1 = runtime.totalMemory() / 1024;
    long freeMemory1 = runtime.freeMemory() / 1024;
    System.out.println("Spent " + (startTime - _parseStartTime) + " ms. creating the model.");
    System.out.println(
        modelName
            + ": Stats before execution:    "
            + Manager.timeAndMemory(startTime, totalMemory1, freeMemory1));

    // Second, we run and print memory stats.
    manager.execute();

    long totalMemory2 = runtime.totalMemory() / 1024;
    long freeMemory2 = runtime.freeMemory() / 1024;
    String standardStats = Manager.timeAndMemory(startTime, totalMemory2, freeMemory2);

    System.out.println(modelName + ": Execution stats:           " + standardStats);

    // Third, we gc and print memory stats.
    System.gc();
    Thread.sleep(1000);

    long totalMemory3 = runtime.totalMemory() / 1024;
    long freeMemory3 = runtime.freeMemory() / 1024;
    System.out.println(
        modelName
            + ": After Garbage Collection:  "
            + Manager.timeAndMemory(startTime, totalMemory3, freeMemory3));

    // Print out the standard stats at the end
    // so as not to break too many scripts
    System.out.println(standardStats);
  }