Created
January 30, 2014 19:54
-
-
Save vorburger/8717472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.vorburger.xtext.utils; | |
import java.io.File; | |
import java.util.Collection; | |
import org.apache.commons.io.FileUtils; | |
import org.eclipse.emf.common.util.URI; | |
import org.eclipse.emf.ecore.resource.Resource; | |
import org.eclipse.emf.ecore.resource.ResourceSet; | |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import com.odcgroup.workbench.core.helper.Timer; | |
public class LoadAllModelsTest { | |
private static final Logger logger = LoggerFactory.getLogger(LoadAllModelsTest.class); | |
public static void main(String[] args) { | |
logMemory(); | |
Timer t = new Timer(); | |
t.start(); | |
File modelsRootDir = new File("...directory where your models are..."); | |
Collection<File> allModelFiles = FileUtils.listFiles(modelsRootDir, new String[] { "domain", "version", "enquiry", "rim", "eson", "menu" }, true); | |
logger.info(allModelFiles.size() + " models found in " + modelsRootDir.toString()); | |
logger.info("Scanning directory took " + t.stopAndText()); | |
t.start(); | |
// .... | |
// HERE YOU MUST DO THE *StandaloneSetup() of your respective Xtext-based language(s) | |
// .... | |
logger.info("*StandaloneSetup took " + t.stopAndText()); | |
logMemory(); | |
// TODO look into IResourceLoader.. ParallelResourceLoader? :) | |
t.start(); | |
ResourceSet rs = new ResourceSetImpl(); | |
int i = 1; | |
for (File file : allModelFiles) { | |
logger.info(i++ + ". loading " + file.toString()); | |
URI uri = URI.createFileURI(file.getAbsolutePath()); | |
Resource resource = rs.getResource(uri, true); | |
if (resource == null || !resource.isLoaded() && resource.getContents().isEmpty()) | |
logger.warn("oups, resource == null or !loaded or isEmpty for URI: " + uri.toString()); | |
new NodesZapper().removeNodeModel(resource); | |
} | |
logger.info("Total getResource() took " + t.stopAndText()); | |
logMemory(); | |
logger.info("System.gc() ..."); | |
System.gc(); | |
logMemory(); | |
} | |
private static void logMemory() { | |
Timer gcTime = new Timer().start(); | |
System.gc(); | |
gcTime.stop(); | |
final int mb = 1024*1024; | |
Runtime runtime = Runtime.getRuntime(); | |
long used = (runtime.totalMemory() - runtime.freeMemory()) / mb; | |
long free = runtime.freeMemory() / mb; | |
long total = runtime.totalMemory() / mb; | |
long max = runtime.maxMemory() / mb; | |
logger.info("After GC (which took {}), used: {} MB, free: {} MB, total: {} MB, max: {} MB", new Object[] { gcTime.text(), used, free, total, max }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment