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 @@ ...@@ -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.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: 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: 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> </component>
</module> </module>
\ No newline at end of file
...@@ -31,6 +31,12 @@ ...@@ -31,6 +31,12 @@
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.5</version> <version>2.5</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -19,8 +19,7 @@ public class Main { ...@@ -19,8 +19,7 @@ public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
String symbolName = args[0]; String symbolName = args[0];
PATHNAME = "my-symbols/_nicola_test/idcm_" + symbolName + "_" + RANDOMNUMBER + ".bin"; PATHNAME = "my-symbols/_nicola_test/idcm_" + symbolName + "_" + RANDOMNUMBER + ".bin";
int numOfSamples = Integer.parseInt(args[1]); TestClassToSerialize myObject = new TestClassToSerialize(symbolName);
TestClassToSerialize myObject = new TestClassToSerialize(symbolName, numOfSamples);
createBinaryFile(myObject); createBinaryFile(myObject);
} }
...@@ -55,12 +54,10 @@ public class Main { ...@@ -55,12 +54,10 @@ public class Main {
fos.write(longToByteArray(sample.getMinorPageFaults())); fos.write(longToByteArray(sample.getMinorPageFaults()));
fos.write(longToByteArray(sample.getMajorPageFaults())); fos.write(longToByteArray(sample.getMajorPageFaults()));
fos.write(intToByteArray(sample.getNumOfFeatures())); fos.write(intToByteArray(sample.getNumOfFeatures()));
int i = 0; for (FreudFeature feature: sample.getFeatureList()) {
for (FreudFeature feature: sample.getFeatures()) {
fos.write(longToByteArray(20)); fos.write(longToByteArray(20));
fos.write(longToByteArray(feature.getTypeOffset())); fos.write(longToByteArray(feature.getTypeOffset()));
fos.write(longToByteArray(feature.getValue())); fos.write(longToByteArray(feature.getValue()));
i++;
} }
fos.write(intToByteArray(sample.getNumOfBranches())); fos.write(intToByteArray(sample.getNumOfBranches()));
fos.write(intToByteArray(sample.getNumOfChildren())); fos.write(intToByteArray(sample.getNumOfChildren()));
......
...@@ -2,20 +2,21 @@ import java.util.LinkedList; ...@@ -2,20 +2,21 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
public class Sample { public class Sample {
private int uidR; private final int uidR;
private long time; private final long time;
private long mem; private final long mem;
private long lockHoldingTime; private final long lockHoldingTime;
private long waitingTime; private final long waitingTime;
private long minorPageFaults; private final long minorPageFaults;
private long majorPageFaults; private final long majorPageFaults;
private int numOfFeatures; private final int numOfFeatures;
private int numOfBranches; private final int numOfBranches;
private int numOfChildren; private final int numOfChildren;
private List<FreudFeature> features; private final List<FreudFeature> featureList; // currently this list is always of one element
public Sample(long time) { // featureVal will become a list once freud-java will support multiple features
this.time = time * time; public Sample(Long featureVal, long time) {
this.time = time;
uidR = (int) time; uidR = (int) time;
mem = 0; mem = 0;
lockHoldingTime = 0; lockHoldingTime = 0;
...@@ -25,9 +26,8 @@ public class Sample { ...@@ -25,9 +26,8 @@ public class Sample {
numOfFeatures = 1; numOfFeatures = 1;
numOfBranches = 0; numOfBranches = 0;
numOfChildren = 0; numOfChildren = 0;
features = new LinkedList<>(); featureList = new LinkedList<>();
long value = time / 2; featureList.add(new FreudFeature(featureVal));
features.add(new FreudFeature(value));
} }
public int getUidR() { public int getUidR() {
...@@ -62,8 +62,8 @@ public class Sample { ...@@ -62,8 +62,8 @@ public class Sample {
return numOfFeatures; return numOfFeatures;
} }
public List<FreudFeature> getFeatures() { public List<FreudFeature> getFeatureList() {
return features; return featureList;
} }
public int getNumOfBranches() { public int getNumOfBranches() {
......
import java.io.Serializable; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals;
public class TestClassToSerialize implements Serializable { public class TestClassToSerialize implements Serializable {
String instrumentationDir = "/home/nicolaamadio/Documents/tesi/freud-java-instrumentation/";
// FILE NAME // FILE NAME
private int symbolNameLen; private int symbolNameLen;
private String symbolName; private String symbolName;
...@@ -17,39 +22,51 @@ public class TestClassToSerialize implements Serializable { ...@@ -17,39 +22,51 @@ public class TestClassToSerialize implements Serializable {
List<Sample> sampleList; List<Sample> sampleList;
/* CONSTRUCTOR */ /* CONSTRUCTOR */
public TestClassToSerialize(String symbolName, int samplesCount) { public TestClassToSerialize(String symbolName) throws IOException {
this.symbolNameLen = symbolName.length(); this.symbolNameLen = symbolName.length();
this.symbolName = symbolName; this.symbolName = symbolName;
// feature names // feature names
this.featureNamesCount = 1; this.featureNamesCount = 1;
String myVar = "my var"; String myVar = "_my_var";
featureNames = new LinkedList<>(); featureNames = new LinkedList<>();
featureNames.add(new FreudFeatureName((short) myVar.length(), myVar)); featureNames.add(new FreudFeatureName((short) myVar.length(), myVar));
this.typeNamesCount = 0; 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++) { 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 */ /* GETTERS & SETTERS */
// FILE NAME // FILE NAME
public void setSymbolNameLen(int symbolNameLen) {
this.symbolNameLen = symbolNameLen;
}
public int getSymbolNameLen() { public int getSymbolNameLen() {
return symbolNameLen; return symbolNameLen;
} }
public void setSymbolName(String symbolName) {
this.symbolName = symbolName;
}
public String getSymbolName() { public String getSymbolName() {
return symbolName; return symbolName;
} }
...@@ -59,10 +76,6 @@ public class TestClassToSerialize implements Serializable { ...@@ -59,10 +76,6 @@ public class TestClassToSerialize implements Serializable {
return featureNamesCount; return featureNamesCount;
} }
public void setFeatureNamesCount(int featureNamesCount) {
this.featureNamesCount = featureNamesCount;
}
public List<FreudFeatureName> getFeatureNamesList() { public List<FreudFeatureName> getFeatureNamesList() {
return featureNames; return featureNames;
} }
...@@ -72,25 +85,13 @@ public class TestClassToSerialize implements Serializable { ...@@ -72,25 +85,13 @@ public class TestClassToSerialize implements Serializable {
return typeNamesCount; return typeNamesCount;
} }
public void setTypeNamesCount(int typeNamesCount) {
this.typeNamesCount = typeNamesCount;
}
// SAMPLES // SAMPLES
public int getSamplesCount() { public int getSamplesCount() {
return samplesCount; return samplesCount;
} }
public void setSamplesCount(int samplesCount) {
this.samplesCount = samplesCount;
}
public List<Sample> getSampleList() { public List<Sample> getSampleList() {
return sampleList; return sampleList;
} }
public void setSampleList(ArrayList<Sample> sampleList) {
this.sampleList = sampleList;
}
} }
Supports Markdown
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