Commit abb01f02 authored by Nicola Amadio's avatar Nicola Amadio
Browse files

make serialization read from log files generated by freud-java-instrumentation

parent 93cc5561
<component name="libraryTable">
<library name="Maven: junit:junit:4.12">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
......@@ -18,5 +18,7 @@
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.4" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -31,6 +31,12 @@
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -19,8 +19,7 @@ public class Main {
public static void main(String[] args) throws IOException {
String symbolName = args[0];
PATHNAME = "my-symbols/_nicola_test/idcm_" + symbolName + "_" + RANDOMNUMBER + ".bin";
int numOfSamples = Integer.parseInt(args[1]);
TestClassToSerialize myObject = new TestClassToSerialize(symbolName, numOfSamples);
TestClassToSerialize myObject = new TestClassToSerialize(symbolName);
createBinaryFile(myObject);
}
......@@ -55,12 +54,10 @@ public class Main {
fos.write(longToByteArray(sample.getMinorPageFaults()));
fos.write(longToByteArray(sample.getMajorPageFaults()));
fos.write(intToByteArray(sample.getNumOfFeatures()));
int i = 0;
for (FreudFeature feature: sample.getFeatures()) {
for (FreudFeature feature: sample.getFeatureList()) {
fos.write(longToByteArray(20));
fos.write(longToByteArray(feature.getTypeOffset()));
fos.write(longToByteArray(feature.getValue()));
i++;
}
fos.write(intToByteArray(sample.getNumOfBranches()));
fos.write(intToByteArray(sample.getNumOfChildren()));
......
......@@ -2,20 +2,21 @@ import java.util.LinkedList;
import java.util.List;
public class Sample {
private int uidR;
private long time;
private long mem;
private long lockHoldingTime;
private long waitingTime;
private long minorPageFaults;
private long majorPageFaults;
private int numOfFeatures;
private int numOfBranches;
private int numOfChildren;
private List<FreudFeature> features;
private final int uidR;
private final long time;
private final long mem;
private final long lockHoldingTime;
private final long waitingTime;
private final long minorPageFaults;
private final long majorPageFaults;
private final int numOfFeatures;
private final int numOfBranches;
private final int numOfChildren;
private final List<FreudFeature> featureList; // currently this list is always of one element
public Sample(long time) {
this.time = time * time;
// featureVal will become a list once freud-java will support multiple features
public Sample(Long featureVal, long time) {
this.time = time;
uidR = (int) time;
mem = 0;
lockHoldingTime = 0;
......@@ -25,9 +26,8 @@ public class Sample {
numOfFeatures = 1;
numOfBranches = 0;
numOfChildren = 0;
features = new LinkedList<>();
long value = time / 2;
features.add(new FreudFeature(value));
featureList = new LinkedList<>();
featureList.add(new FreudFeature(featureVal));
}
public int getUidR() {
......@@ -62,8 +62,8 @@ public class Sample {
return numOfFeatures;
}
public List<FreudFeature> getFeatures() {
return features;
public List<FreudFeature> getFeatureList() {
return featureList;
}
public int getNumOfBranches() {
......
import java.io.Serializable;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class TestClassToSerialize implements Serializable {
String instrumentationDir = "/home/nicolaamadio/Documents/tesi/freud-java-instrumentation/";
// FILE NAME
private int symbolNameLen;
private String symbolName;
......@@ -17,39 +22,51 @@ public class TestClassToSerialize implements Serializable {
List<Sample> sampleList;
/* CONSTRUCTOR */
public TestClassToSerialize(String symbolName, int samplesCount) {
public TestClassToSerialize(String symbolName) throws IOException {
this.symbolNameLen = symbolName.length();
this.symbolName = symbolName;
// feature names
this.featureNamesCount = 1;
String myVar = "my var";
String myVar = "_my_var";
featureNames = new LinkedList<>();
featureNames.add(new FreudFeatureName((short) myVar.length(), myVar));
this.typeNamesCount = 0;
this.samplesCount = samplesCount;
this.sampleList = new ArrayList<>();
BufferedReader logsReader = new BufferedReader(new FileReader(
instrumentationDir + "param-logs.txt"));
this.samplesCount = Integer.parseInt(logsReader.readLine());
Long[] featureArray = new Long[samplesCount];
String feature = logsReader.readLine();
for (int i = 0; i < samplesCount; i++) {
sampleList.add(new Sample(i));
featureArray[i] = Long.valueOf(feature);
feature = logsReader.readLine();
}
logsReader.close();
this.sampleList = new ArrayList<>();
BufferedReader tsReader = new BufferedReader(new FileReader(
instrumentationDir + "time-logs.txt"));
String line = tsReader.readLine();
int i = 0;
while (line != null) {
sampleList.add(new Sample(featureArray[i], Long.parseLong(line)));
line = tsReader.readLine();
i++;
}
assertEquals(i, samplesCount);
tsReader.close();
}
/* GETTERS & SETTERS */
// FILE NAME
public void setSymbolNameLen(int symbolNameLen) {
this.symbolNameLen = symbolNameLen;
}
public int getSymbolNameLen() {
return symbolNameLen;
}
public void setSymbolName(String symbolName) {
this.symbolName = symbolName;
}
public String getSymbolName() {
return symbolName;
}
......@@ -59,10 +76,6 @@ public class TestClassToSerialize implements Serializable {
return featureNamesCount;
}
public void setFeatureNamesCount(int featureNamesCount) {
this.featureNamesCount = featureNamesCount;
}
public List<FreudFeatureName> getFeatureNamesList() {
return featureNames;
}
......@@ -72,25 +85,13 @@ public class TestClassToSerialize implements Serializable {
return typeNamesCount;
}
public void setTypeNamesCount(int typeNamesCount) {
this.typeNamesCount = typeNamesCount;
}
// SAMPLES
public int getSamplesCount() {
return samplesCount;
}
public void setSamplesCount(int samplesCount) {
this.samplesCount = samplesCount;
}
public List<Sample> getSampleList() {
return sampleList;
}
public void setSampleList(ArrayList<Sample> sampleList) {
this.sampleList = sampleList;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment