Skip to content

Commit

Permalink
Added source code of the application
Browse files Browse the repository at this point in the history
  • Loading branch information
orichalque committed Jul 11, 2018
0 parents commit 481b773
Show file tree
Hide file tree
Showing 7 changed files with 592 additions and 0 deletions.
96 changes: 96 additions & 0 deletions pom.xml
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>
110 changes: 110 additions & 0 deletions src/main/java/com/tblf/App.java
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();
}
}
Loading

0 comments on commit 481b773

Please sign in to comment.