Commit f13d3fbb authored by Erwan Bousse's avatar Erwan Bousse
Browse files

Fixed regression that appeared with the strategy reorganisation.

parent 1da19274
*.class
*.jar
*~
.metadata
......@@ -14,18 +14,24 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.zeroturnaround.zip.ZipUtil;
import fr.inria.diverse.cloning.benchmark.common.BenchmarkMaterial;
import fr.inria.diverse.cloning.materialgenerator.util.CodeGeneration;
@SuppressWarnings("restriction")
public class OsgiBundleGenerator {
private static final String generatedBenchmarkMaterialPackageName = "cloningbenchmark";
private static final String generatedBenchmarkMaterialClassName = "BenchmarkMaterialImpl";
private static final String clonerPluginId = "fr.inria.diverse.cloning.runtime";
private static final String benchmarkCommonPluginId = "fr.inria.diverse.cloning.benchmark.common";
private static final String bundleName = "CloningBenchmark";
private static final String eclipseRuntimePluginId = "org.eclipse.core.runtime";
private static final String ecoreRuntimePluginId = "org.eclipse.emf.ecore";
public static void generateActivator(File outputFolder) {
......@@ -40,21 +46,18 @@ public class OsgiBundleGenerator {
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
String content = "package "
+ packageFullName
+ ";"
String content = "package " + packageFullName + ";"
+ "import org.osgi.framework.BundleActivator;"
+ "import org.osgi.framework.BundleContext;"
+ "import "+BenchmarkMaterial.class.getCanonicalName()+";"
+ "public class "
+ className
+ " implements BundleActivator { "
+ "import org.osgi.framework.BundleContext;" + "import "
+ BenchmarkMaterial.class.getCanonicalName() + ";" + "public class "
+ className + " implements BundleActivator { "
+ "private static BundleContext context; "
+ "static BundleContext getContext() {return context;} "
+ "public void start(BundleContext bundleContext) throws Exception {"
+ " Activator.context = bundleContext;"
+ " context.registerService(\""+BenchmarkMaterial.class.getCanonicalName()+"\", new "+generatedBenchmarkMaterialClassName+"(), null);"
+ " } " + "public void stop(BundleContext bundleContext) throws Exception {"
+ " Activator.context = bundleContext;" + " context.registerService(\""
+ BenchmarkMaterial.class.getCanonicalName() + "\", new "
+ generatedBenchmarkMaterialClassName + "(), null);" + " } "
+ "public void stop(BundleContext bundleContext) throws Exception {"
+ " Activator.context = null;" + " }" + "}";
printer.print(CodeGeneration.formatJavaCode(content));
......@@ -76,10 +79,12 @@ public class OsgiBundleGenerator {
PrintStream printer = new PrintStream(outputFile);
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+ "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.1.0\" name=\""+bundleName+"\"> "
+ "<implementation class=\""+generatedBenchmarkMaterialPackageName+"."+generatedBenchmarkMaterialClassName+"\"/> " + "<service>"
+ " <provide interface=\""+BenchmarkMaterial.class.getCanonicalName()+"\"/> "
+ "</service>" + " </scr:component>";
+ "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.1.0\" name=\""
+ bundleName + "\"> " + "<implementation class=\""
+ generatedBenchmarkMaterialPackageName + "."
+ generatedBenchmarkMaterialClassName + "\"/> " + "<service>"
+ " <provide interface=\"" + BenchmarkMaterial.class.getCanonicalName()
+ "\"/> " + "</service>" + " </scr:component>";
printer.print(content);
printer.close();
} catch (IOException e) {
......@@ -88,7 +93,21 @@ public class OsgiBundleGenerator {
}
}
@SuppressWarnings("restriction")
private static String findVersionOfBundle(String bundleName) {
BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(bundleName)) {
int major = b.getVersion().getMajor();
int minor = b.getVersion().getMinor();
// int micro = b.getVersion().getMicro();
return major + "." + minor;// + "." + micro;
// return b.getVersion().toString();
}
}
return "";
}
public static void generateManifest(File outputFolder) {
// Preparing the output file and the printer
......@@ -99,15 +118,34 @@ public class OsgiBundleGenerator {
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
String content = "Manifest-Version: 1.0\n"
+ "Service-Component: component.xml\n"
+ "Require-Bundle: org.eclipse.core.runtime;bundle-version=\"3.9.0\", org.eclipse.emf.ecore;bundle-version=\"2.9.1\","+clonerPluginId+";bundle-version=\"0.1.0\","+benchmarkCommonPluginId+";bundle-version=\"1.0.0\",org.eclipse.emf.ecore.xmi\n"
String content = "Manifest-Version: 1.0\n" + "Service-Component: component.xml\n"
+ "Require-Bundle: "
+ eclipseRuntimePluginId
+ ";bundle-version=\""
+ findVersionOfBundle(eclipseRuntimePluginId)
+ "\", "
+ ecoreRuntimePluginId
+ ";bundle-version=\""
+ findVersionOfBundle(ecoreRuntimePluginId)
+ "\","
+ clonerPluginId
+ ";bundle-version=\""
+ findVersionOfBundle(clonerPluginId)
+ "\","
+ benchmarkCommonPluginId
+ ";bundle-version=\""
+ findVersionOfBundle(benchmarkCommonPluginId)
+ "\",org.eclipse.emf.ecore.xmi\n"
+ "Bundle-ActivationPolicy: lazy\n"
+ "Bundle-Version: 1\n"
+ "Bundle-Name: "+bundleName+"\n"
+ "Bundle-Activator: cloningbenchmark.Activator\n"
+ "Bundle-Version: 1\n"
+ "Bundle-Name: "
+ bundleName
+ "\n"
+ "Bundle-Activator: cloningbenchmark.Activator\n"
+ "Bundle-ManifestVersion: 2\n"
+ "Bundle-SymbolicName: "+bundleName+"\n"
+ "Bundle-SymbolicName: "
+ bundleName
+ "\n"
+ "Bundle-RequiredExecutionEnvironment: JavaSE-1.7\n";
printer.print(content);
printer.close();
......@@ -119,8 +157,9 @@ public class OsgiBundleGenerator {
}
public static void createJar(File inputFolder, File outputFile) {
//ZipHelper.zipDir(inputFolder.getAbsolutePath(), outputFile.getAbsolutePath());
ZipUtil.pack(inputFolder, outputFile);
// ZipHelper.zipDir(inputFolder.getAbsolutePath(),
// outputFile.getAbsolutePath());
ZipUtil.pack(inputFolder, outputFile);
}
......
......@@ -98,8 +98,10 @@ public class Benchmark {
Log.info("OriginalPerformance: " + originalModelPerformance);
}
// Echauffement
for (int i = 0; i < 1000; i++)
// Warmup
// NOTE : only works because our benchmark do not contain mutable containments
// If it did, the gc coudln't destroy the clones because of the additional containers of some objects
for (int i = 0; i < 1337; i++)
cloner.clone(model, tmpFolder);//, light);
// Cloning "numberOfClones" times and computing time
......
......@@ -38,32 +38,49 @@ import fr.inria.diverse.cloning.runtime.util.Log;
*/
public class Application implements IApplication {
public static void realMain(String[] args) throws IOException, BundleException {
public static void realMain(String[] args) throws IOException,
BundleException {
// Specifying arguments
OptionParser parser = new OptionParser();
OptionSpec<File> benchmarkMetamodelsOption = parser
.accepts("benchmarkMetamodels", "OSGI bundles with all metamodels, created with the generator.")
.withRequiredArg().required().describedAs("path1,path2,...").ofType(File.class)
.withValuesSeparatedBy(",").required();
OptionSpec<File> outputFileOption = parser.accepts("outputFile", "The CSV file to write.").withRequiredArg()
.required().describedAs("path").ofType(File.class).required();
OptionSpec<?> keepDumpsOption = parser.accepts("keepDumps", "To keep memory dumps.");
.accepts("benchmarkMetamodels",
"OSGI bundles with all metamodels, created with the generator.")
.withRequiredArg().required().describedAs("path1,path2,...")
.ofType(File.class).withValuesSeparatedBy(",").required();
OptionSpec<File> outputFileOption = parser
.accepts("outputFile", "The CSV file to write.")
.withRequiredArg().required().describedAs("path")
.ofType(File.class).required();
OptionSpec<?> keepDumpsOption = parser.accepts("keepDumps",
"To keep memory dumps.");
OptionSpec<File> dumpsFolderOption = parser
.accepts("dumpsFolder", "A folder in which memory dumps will be written.").withRequiredArg()
.describedAs("path").ofType(File.class);
.accepts("dumpsFolder",
"A folder in which memory dumps will be written.")
.withRequiredArg().describedAs("path").ofType(File.class);
OptionSpec<Integer> nbtriesOption = parser
.accepts("nbtries", "The number of tries, for better time/performance results").withRequiredArg()
.required().ofType(Integer.class).required();
OptionSpec<Integer> nbClonesOption = parser.accepts("nbClones", "Series of numbers of clones to create.")
.withRequiredArg().required().describedAs("1,10,100...").ofType(Integer.class)
.withValuesSeparatedBy(",").required();
OptionSpec<String> metamodelsOption = parser.accepts("metamodels", "Specific metamodels to use.")
.withRequiredArg().ofType(String.class).withValuesSeparatedBy(",");
OptionSpec<Boolean> shareFieldsOption = parser.accepts("shareFields", "Enforces shareFields.")
.withRequiredArg().ofType(Boolean.class);
OptionSpec<Boolean> shareObjectsOption = parser.accepts("shareObjects", "Enforces shareObjects.")
.withRequiredArg().ofType(Boolean.class);
.accepts("nbtries",
"The number of tries, for better time/performance results")
.withRequiredArg().required().ofType(Integer.class).required();
OptionSpec<Integer> nbClonesOption = parser
.accepts("nbClones", "Series of numbers of clones to create.")
.withRequiredArg().required().describedAs("1,10,100...")
.ofType(Integer.class).withValuesSeparatedBy(",").required();
OptionSpec<String> metamodelsOption = parser
.accepts("metamodels", "Specific metamodels to use.")
.withRequiredArg().ofType(String.class)
.withValuesSeparatedBy(",");
OptionSpec<String> operatorsOption = parser
.accepts("cloningOperators", "Cloning operators to use.")
.withRequiredArg().ofType(String.class)
.withValuesSeparatedBy(",");
/*
* OptionSpec<Boolean> shareFieldsOption = parser.accepts("shareFields",
* "Enforces shareFields.") .withRequiredArg().ofType(Boolean.class);
* OptionSpec<Boolean> shareObjectsOption =
* parser.accepts("shareObjects", "Enforces shareObjects.")
* .withRequiredArg().ofType(Boolean.class);
*/
try {
......@@ -80,15 +97,20 @@ public class Application implements IApplication {
if (enforceMetamodels)
enforcedMetamodels = options.valuesOf(metamodelsOption);
boolean enforceShareFields = options.has(shareFieldsOption);
boolean shareFields = true;
if (enforceShareFields)
shareFields = options.valueOf(shareFieldsOption);
boolean enforceShareObjects = options.has(shareObjectsOption);
boolean shareObjects = true;
if (enforceShareObjects)
shareObjects = options.valueOf(shareObjectsOption);
boolean enforceOperators = options.has(operatorsOption);
List<String> enforcedOperators = null;
if (enforceOperators)
enforcedOperators = options.valuesOf(operatorsOption);
/*
* boolean enforceShareFields = options.has(shareFieldsOption);
* boolean shareFields = true; if (enforceShareFields) shareFields =
* options.valueOf(shareFieldsOption);
*
* boolean enforceShareObjects = options.has(shareObjectsOption);
* boolean shareObjects = true; if (enforceShareObjects)
* shareObjects = options.valueOf(shareObjectsOption);
*/
File dumpsFolder;
if (options.has(dumpsFolderOption)) {
......@@ -105,12 +127,13 @@ public class Application implements IApplication {
CSVFile csv = new CSVFile(outputFile);
boolean[] lightNot = { false, true }; // ne pas toucher à l'ordre pour le plot R
// boolean[] lightNot = { false, true }; // ne pas toucher à l'ordre
// pour le plot R
if (enforceShareFields) {
lightNot = new boolean[1];
lightNot[0] = shareFields;
}
/*
* if (enforceShareFields) { lightNot = new boolean[1]; lightNot[0]
* = shareFields; }
*/
// To display numbers consistently with CSV line numbers
int counter = 2;
......@@ -124,8 +147,9 @@ public class Application implements IApplication {
// Total amount of runs, to compute progress
if (!progressSetUp) {
int total = material.getMetamodelsName().size() * material.getCloningNames().size()
* nbClones.size() * lightNot.length;
int total = material.getMetamodelsName().size()
* material.getCloningNames().size()
* nbClones.size();// * lightNot.length;
Log.enableProgress(total * bundles.size());
progressSetUp = true;
}
......@@ -138,23 +162,33 @@ public class Application implements IApplication {
for (String name : metamodels) {
Benchmark benchmark = new Benchmark(material.getModelCreator(name), dumpsFolder, keepDumps);
benchmark.computeOriginalModelPerformance(material.getCloningMaterial(name, "Deep"), nbtries);
Benchmark benchmark = new Benchmark(
material.getModelCreator(name), dumpsFolder,
keepDumps);
benchmark.computeOriginalModelPerformance(
material.getCloningMaterial(name, "Deep"), nbtries);
// Processing argument that enforces specific clonings (shareobject)
// Processing argument that enforces specific clonings
// (shareobject)
List<String> clonings = new ArrayList<String>();
clonings.addAll(material.getCloningNames());
if (enforceShareObjects) {
clonings.clear();
if (shareObjects)
clonings.add("MutClassOnly");
else
clonings.add("Deep");
}
/*
* if (enforceShareObjects) { clonings.clear(); if
* (shareObjects) clonings.add("MutClassOnly"); else
* clonings.add("Deep"); }
*/
if (enforceOperators)
clonings.retainAll(enforcedOperators);
for (String cloning : clonings) {
// for (boolean light : lightNot) {
CloningMaterial cloningMaterial = material
.getCloningMaterial(name, cloning);
boolean computePerformance = true;
for (int number : nbClones) {
......@@ -166,39 +200,54 @@ public class Application implements IApplication {
Collection<BenchmarkResults> multipleResults = new ArrayList<BenchmarkResults>();
CloningMaterial cloningMaterial = material.getCloningMaterial(name, cloning);
// First attempt, to get memory measure at least
BenchmarkResults result = benchmark.run(cloningMaterial, number, true, computePerformance);
BenchmarkResults result = benchmark.run(
cloningMaterial, number, true,
computePerformance);
multipleResults.add(result);
// Remaining attempts, without memory computing
for (int i = 0; i < nbtries - 1; i++) {
BenchmarkResults result2 = benchmark.run(material.getCloningMaterial(name, cloning),
number, false, computePerformance);
BenchmarkResults result2 = benchmark.run(
material.getCloningMaterial(name,
cloning), number, false,
computePerformance);
multipleResults.add(result2);
}
computePerformance = false;
// Then we combine all results (mean of time, mainly)
BenchmarkResults results = BenchmarkResults.combineResults(multipleResults);
// Then we combine all results (mean of time,
// mainly)
BenchmarkResults results = BenchmarkResults
.combineResults(multipleResults);
Log.info(results.toString());
cloningMaterial = material.getCloningMaterial(name, "ShareAll");
CloningMaterial cloningMaterial2 = material.getCloningMaterial(name, "ShareFieldsOnly");
cloningMaterial = material.getCloningMaterial(name,
"ShareAll");
CloningMaterial cloningMaterial2 = material
.getCloningMaterial(name, "ShareFieldsOnly");
MetamodelTags tags = cloningMaterial.getTags();
MetamodelTags tags2 = cloningMaterial2.getTags();
csv.addLine(number, "bundle" + bundleCounter + "-" + name, results.getUsedMemory(),
results.getTimeSpent(), cloning, "default", results.getOriginalModelPerformance(),
results.getCloneModelPerformance(), tags.getShareableClassesRatio(),
tags.getPartShareableClassesRatio(), tags.getIsolatedShareablePropertiesRatio(),
csv.addLine(
number,
"bundle" + bundleCounter + "-" + name,
results.getUsedMemory(),
results.getTimeSpent(),
cloning,
"default",
results.getOriginalModelPerformance(),
results.getCloneModelPerformance(),
tags.getShareableClassesRatio(),
tags.getPartShareableClassesRatio(),
tags.getIsolatedShareablePropertiesRatio(),
tags.getShareablePropertiesInPartShareableClassesDensity(),
tags.getShareablePropertiesInShareableClassesDensity(),
tags2.getShareableClassesRatio(), tags2.getPartShareableClassesRatio(),
tags2.getShareableClassesRatio(),
tags2.getPartShareableClassesRatio(),
tags2.getIsolatedShareablePropertiesRatio(),
tags2.getShareablePropertiesInPartShareableClassesDensity(),
tags2.getShareablePropertiesInShareableClassesDensity());
......@@ -209,9 +258,10 @@ public class Application implements IApplication {
}
}
bundleCounter++;
BundleLoader.uninstallBundle();
}
bundleCounter++;
BundleLoader.uninstallBundle();
// }
// csv.writeToFile(outputFile);
Log.info("Exiting benchmark tool");
......@@ -227,10 +277,12 @@ public class Application implements IApplication {
/*
* (non-Javadoc)
*
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.
* IApplicationContext)
*/
public Object start(IApplicationContext context) throws Exception {
String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
String[] args = (String[]) context.getArguments().get(
IApplicationContext.APPLICATION_ARGS);
realMain(args);
return IApplication.EXIT_OK;
}
......
......@@ -3,6 +3,7 @@
<product name="Benchmark tool" uid="fr.inria.diverse.cloning.benchmark.tool.product" id="fr.inria.diverse.cloning.benchmark.tool.BenchmarkToolSuite" application="fr.inria.diverse.cloning.benchmark.tool.application" version="0.1.0.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default">
</configIni>
......@@ -14,6 +15,7 @@
<windowImages/>
<launcher name="cloning-benchmark">
<solaris/>
<win useIco="false">
......@@ -21,9 +23,11 @@
</win>
</launcher>
<vm>
</vm>
<plugins>
<plugin id="fr.inria.diverse.cloning.benchmark.tool" version="0.1.0.qualifier"/>
<plugin id="org.eclipse.core.runtime"/>
......@@ -33,6 +37,7 @@
<configurations>
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
<property name="osgi.instance.area.default" value="benchmarktool-workingdir" />
</configurations>
</product>
......@@ -15,7 +15,7 @@ import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.materialgenerator.util.CodeGeneration;
......@@ -56,7 +56,7 @@ public class CloningMaterialClassGenerator {
imports += "import " + CloningMaterial.class.getCanonicalName() + ";\n";
//imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
imports += "import " + MetamodelTags.class.getCanonicalName() + ";\n";
imports += "import " + Copier.class.getCanonicalName() + ";\n";
imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
// Class declaration
String classdef = "public class " + className + " implements " + CloningMaterial.class.getSimpleName()
......@@ -80,17 +80,17 @@ public class CloningMaterialClassGenerator {
// getTags method declaration
classdef += "public " + MetamodelTags.class.getSimpleName() + " getTags() {\n";
classdef += "return tags;";
// end getTags method declaration
// end getTags method declarationCopier
classdef += "}\n";
// createLightCopier method declaration
String copierClassName = CodeGeneration.firstCharUp(tagger.getMetamodelName() + tagger.getCloningName()
+ Constants.COPIER_SUFFIX);
classdef += "public " + Copier.class.getSimpleName() + " createCopier() {\n";
classdef += "public " + LooseCopier.class.getSimpleName() + " createCopier() {\n";
if (tagger.mayTagClassesPartShareable())
classdef += "return new " + copierClassName + "();";
else
classdef += "return new Copier ();";
classdef += "return new LooseCopier ();";
// end createLightCopier method declaration
classdef += "}\n";
......
......@@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.util.EcoreHelper;
import fr.inria.diverse.cloning.runtime.util.Log;
public abstract class AbstractTagger implements Tagger {
......@@ -69,7 +70,8 @@ public abstract class AbstractTagger implements Tagger {
}
protected static boolean isPropertyDesignedMutable(EStructuralFeature f) {
return f.getName().endsWith("_m");
//return f.getName().endsWith("_m");
return EcoreHelper.isPropertyDesignedMutable(f);
}
......
......@@ -18,13 +18,13 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import fr.inria.diverse.cloning.runtime.cloner.Cloner;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.common.CloningMaterial;
import fr.inria.diverse.cloning.runtime.common.MetamodelTags;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseResource;
/**
......@@ -54,7 +54,7 @@ public class ClonerImpl implements Cloner {
copier = cloningMaterial.createCopier();