-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added source code of the application
- Loading branch information
0 parents
commit 481b773
Showing
7 changed files
with
592 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.tblf</groupId> | ||
<artifactId>EnergyModel</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>EnergyModel</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>oss-sonatype</id> | ||
<name>oss-sonatype</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.tblf</groupId> | ||
<artifactId>management</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>emf-smm</artifactId> | ||
<groupId>org.atlanmod.zoo</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.20.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.tblf; | ||
|
||
import com.tblf.behavior.EnergyBehavior; | ||
import com.tblf.business.AnalysisLauncher; | ||
import com.tblf.instrumentation.InstrumentationType; | ||
import com.tblf.junitrunner.MavenRunner; | ||
import com.tblf.parsing.TraceType; | ||
import com.tblf.parsing.parsers.Parser; | ||
import com.tblf.parsing.traceReaders.TraceFileReader; | ||
import com.tblf.processors.ClassProcessor; | ||
import com.tblf.utils.Configuration; | ||
import com.tblf.utils.ModelUtils; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.omg.smm.CollectiveMeasurement; | ||
import org.omg.smm.DimensionalMeasurement; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
public class App { | ||
private static CollectiveMeasurement root; | ||
|
||
public static void main(String[] args) throws URISyntaxException { | ||
if (args.length == 0) | ||
System.exit(1); | ||
|
||
File file = new File(args[0]); | ||
|
||
new MavenRunner(new File(file, "pom.xml")).compilePom(); | ||
|
||
AnalysisLauncher analysisLauncher = new AnalysisLauncher(file); | ||
analysisLauncher.setInstrumentationType(InstrumentationType.BYTECODE); | ||
|
||
analysisLauncher.setTraceType(TraceType.FILE); | ||
|
||
analysisLauncher.registerDependencies(Collections.singletonList(new File("pom.xml"))); | ||
|
||
analysisLauncher.registerProcessor(new ClassProcessor()); | ||
|
||
analysisLauncher.applyAfter(file1 -> { | ||
File trace = new File(file1, Configuration.getProperty("traceFile")); | ||
ResourceSet resourceSet = ModelUtils.buildResourceSet(file1); | ||
new Parser(new TraceFileReader(trace), new EnergyBehavior(resourceSet)).parse(); | ||
Resource resource = resourceSet.getResources().get(resourceSet.getResources().size() - 1); | ||
try { | ||
resource.save(Collections.EMPTY_MAP); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
resource.getAllContents().forEachRemaining(eObject -> { | ||
//get the root method calls | ||
if (eObject instanceof CollectiveMeasurement && ((CollectiveMeasurement) eObject).getBaseMeasurementFrom().isEmpty()) { | ||
displayCallGraph((CollectiveMeasurement) eObject); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
analysisLauncher.run(); | ||
} | ||
|
||
private static void displayCallGraph(CollectiveMeasurement root) { | ||
|
||
//System.out.println(root.getName()+": Raw Energy: "+getEnergy(root)+ " : individual energy "+getIndividualMethodEnergy(root)); | ||
System.out.println(root.getName() + " : " + getEnergy(root) + " : " + getIndividualMethodEnergy(root)); | ||
|
||
root.getBaseMeasurementTo().forEach(baseNMeasurementRelationship -> { | ||
System.out.print("\t -"); | ||
displayCallGraph((CollectiveMeasurement) baseNMeasurementRelationship.getTo()); | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* Get the energy of a Measurement, (Excludes all the sub-measurement energy) | ||
* | ||
* @param root | ||
* @return | ||
*/ | ||
private static double getIndividualMethodEnergy(CollectiveMeasurement root) { | ||
return getEnergy(root) - root | ||
.getBaseMeasurementTo().stream() | ||
.map(baseNMeasurementRelationship -> getEnergy((CollectiveMeasurement) baseNMeasurementRelationship.getTo())) | ||
.mapToDouble(Double::doubleValue).sum(); | ||
} | ||
|
||
/** | ||
* Get the Energy of a measurement (Includes all the sub-measurement energy) | ||
* | ||
* @param measurement | ||
* @return | ||
*/ | ||
private static double getEnergy(CollectiveMeasurement measurement) { | ||
return ((DimensionalMeasurement) | ||
measurement.getMeasurementRelationships() | ||
.stream() | ||
.filter(measurementRelationshipPredicate -> measurementRelationshipPredicate.getName() != null | ||
&& measurementRelationshipPredicate.getName().equals("energy")) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("No energy measurement found")) | ||
.getTo()).getValue(); | ||
} | ||
} |
Oops, something went wrong.