@Override public void setFocus() { super.setFocus(); MoMLParser.purgeAllModelRecords(); if (actor == null && momlPath != null) { final MoMLParser parser = new MoMLParser(new Workspace()); try { final IResource moml = ResourcesPlugin.getWorkspace().getRoot().findMember(momlPath); CompositeActor toplevel = (CompositeActor) parser.parse(null, new File(moml.getLocation().toString()).toURL()); toplevel.workspace().setName(moml.getProject().getName()); ComponentEntity entity = PasserelleProjectUtils.findEntityByName(toplevel, actorName); if (entity != null && entity.getName().equals(actorName)) { this.actor = (SubstitutionParticipant) entity; } } catch (Exception e) { logger.error("Cannot parse " + momlPath, e); } } if (actor != null) { viewer.setContentProvider(createActorContentProvider()); viewer.setInput(new Object()); } }
/** * 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); }