Commit 941c0528 authored by Nicola Amadio's avatar Nicola Amadio
Browse files

add system that creates several samples to serialize; tested with...

add system that creates several samples to serialize; tested with freud-statistics and it seems to work.
parent 8ef805e5
...@@ -3,15 +3,18 @@ import org.apache.commons.lang.ArrayUtils; ...@@ -3,15 +3,18 @@ import org.apache.commons.lang.ArrayUtils;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.List;
public class Main { public class Main {
public static final String PATHNAME = "my-symbols/_nicola_test/idcm__nicola_test_12493.bin"; static String PATHNAME = "";
static String RANDOMNUMBER = "12493";
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
TestClassToSerialize myObject = new TestClassToSerialize(); String symbolName = args[0];
fillObject(myObject); PATHNAME = "my-symbols/_nicola_test/idcm_" + symbolName + "_" + RANDOMNUMBER + ".bin";
int numOfSamples = Integer.parseInt(args[1]);
TestClassToSerialize myObject = new TestClassToSerialize(symbolName, numOfSamples);
createBinaryFile(myObject); createBinaryFile(myObject);
} }
...@@ -22,21 +25,24 @@ public class Main { ...@@ -22,21 +25,24 @@ public class Main {
} }
private static void writeObjectToFile(FileOutputStream fos, TestClassToSerialize myObject) throws IOException { private static void writeObjectToFile(FileOutputStream fos, TestClassToSerialize myObject) throws IOException {
fos.write(intToByteArray(myObject.getNameLen())); fos.write(intToByteArray(myObject.getSymbolNameLen()));
fos.write(myObject.getFname().getBytes()); fos.write(myObject.getSymbolName().getBytes());
fos.write(intToByteArray(myObject.getFeatureNamesCount())); fos.write(intToByteArray(myObject.getFeatureNamesCount()));
fos.write(intToByteArray(myObject.getTypeNamesCount())); fos.write(intToByteArray(myObject.getTypeNamesCount()));
fos.write(intToByteArray(myObject.getSamplesCount())); fos.write(intToByteArray(myObject.getSamplesCount()));
fos.write(intToByteArray(myObject.getUidR())); List<Sample> samples = myObject.getSampleList();
fos.write(longToBytes(myObject.getTime())); for (Sample sample: samples) {
fos.write(longToBytes(myObject.getMem())); fos.write(intToByteArray(sample.getUidR()));
fos.write(longToBytes(myObject.getLockHoldingTime())); fos.write(longToBytes(sample.getTime()));
fos.write(longToBytes(myObject.getWaitingTime())); fos.write(longToBytes(sample.getMem()));
fos.write(longToBytes(myObject.getMinorPageFaults())); fos.write(longToBytes(sample.getLockHoldingTime()));
fos.write(longToBytes(myObject.getMajorPageFaults())); fos.write(longToBytes(sample.getWaitingTime()));
fos.write(intToByteArray(myObject.getNumOfFeatures())); fos.write(longToBytes(sample.getMinorPageFaults()));
fos.write(intToByteArray(myObject.getNumOfBranches())); fos.write(longToBytes(sample.getMajorPageFaults()));
fos.write(intToByteArray(myObject.getNumOfChildren())); fos.write(intToByteArray(sample.getNumOfFeatures()));
fos.write(intToByteArray(sample.getNumOfBranches()));
fos.write(intToByteArray(sample.getNumOfChildren()));
}
fos.close(); fos.close();
} }
...@@ -54,31 +60,4 @@ public class Main { ...@@ -54,31 +60,4 @@ public class Main {
return array; return array;
} }
private static void fillObject(TestClassToSerialize myObject) {
// file name
myObject.setNameLen(12);
myObject.setFname("_nicola_test");
// feature names
myObject.setFeatureNamesCount(0);
// type names
myObject.setTypeNamesCount(0);
// ..
// samples
myObject.setSamplesCount(1);
// sample
myObject.setUidR(0);
myObject.setTime(1240);
myObject.setMem(0);
myObject.setLockHoldingTime(0);
myObject.setWaitingTime(0);
myObject.setMinorPageFaults(0);
myObject.setMajorPageFaults(0);
// features
myObject.setNumOfFeatures(0);
// branches
myObject.setNumOfBranches(0);
// children
myObject.setNumOfChildren(0);
}
} }
public class Sample {
int uidR;
long time; // so far, this is the only sample variable to be set to a value, the others get set to 0
long mem;
long lockHoldingTime;
long waitingTime;
long minorPageFaults;
long majorPageFaults;
int numOfFeatures;
int numOfBranches;
int numOfChildren;
public Sample(long time) {
this.time = time;
uidR = (int) time;
mem = 0;
lockHoldingTime = 0;
waitingTime = 0;
minorPageFaults = 0;
majorPageFaults = 0;
numOfFeatures = 0;
numOfBranches = 0;
numOfChildren = 0;
}
public int getUidR() {
return uidR;
}
public long getTime() {
return time;
}
public long getMem() {
return mem;
}
public long getLockHoldingTime() {
return lockHoldingTime;
}
public long getWaitingTime() {
return waitingTime;
}
public long getMinorPageFaults() {
return minorPageFaults;
}
public long getMajorPageFaults() {
return majorPageFaults;
}
public int getNumOfFeatures() {
return numOfFeatures;
}
public int getNumOfBranches() {
return numOfBranches;
}
public int getNumOfChildren() {
return numOfChildren;
}
}
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class TestClassToSerialize implements Serializable { public class TestClassToSerialize implements Serializable {
private int nameLen; // FILE NAME
private String fname; private int symbolNameLen;
private String symbolName;
// FEATURE NAMES // FEATURE NAMES
private int featureNamesCount; private int featureNamesCount;
private long vnlen; // TYPE NAMES
private String vname; int typeNamesCount;
// SAMPLES
public void setNameLen(int nameLen) { int samplesCount;
this.nameLen = nameLen; List<Sample> sampleList;
}
/* CONSTRUCTOR */
public void setFname(String fname) { public TestClassToSerialize(String symbolName, int samplesCount) {
this.fname = fname; this.symbolNameLen = symbolName.length();
this.symbolName = symbolName;
this.featureNamesCount = 0;
this.typeNamesCount = 0;
this.samplesCount = samplesCount;
this.sampleList = new ArrayList<>();
for (int i = 0; i < samplesCount; i++) {
sampleList.add(new Sample(i));
}
} }
public void setFeatureNamesCount(int featureNamesCount) {
this.featureNamesCount = featureNamesCount;
}
public void setVnlen(long vnlen) { /* GETTERS & SETTERS */
this.vnlen = vnlen; // FILE NAME
public void setSymbolNameLen(int symbolNameLen) {
this.symbolNameLen = symbolNameLen;
} }
public void setVname(String vname) { public int getSymbolNameLen() {
this.vname = vname; return symbolNameLen;
} }
public int getNameLen() { public void setSymbolName(String symbolName) {
return nameLen; this.symbolName = symbolName;
} }
public String getFname() { public String getSymbolName() {
return fname; return symbolName;
} }
// FEATURE NAMES
public int getFeatureNamesCount() { public int getFeatureNamesCount() {
return featureNamesCount; return featureNamesCount;
} }
public long getVnlen() { public void setFeatureNamesCount(int featureNamesCount) {
return vnlen; this.featureNamesCount = featureNamesCount;
}
public String getVname() {
return vname;
} }
// TYPE NAMES
public int getTypeNamesCount() { public int getTypeNamesCount() {
return typeNamesCount; return typeNamesCount;
} }
...@@ -57,11 +64,7 @@ public class TestClassToSerialize implements Serializable { ...@@ -57,11 +64,7 @@ public class TestClassToSerialize implements Serializable {
this.typeNamesCount = typeNamesCount; this.typeNamesCount = typeNamesCount;
} }
// TYPE NAMES // SAMPLES
int typeNamesCount;
int tnlen;
String tname;
public int getSamplesCount() { public int getSamplesCount() {
return samplesCount; return samplesCount;
} }
...@@ -70,167 +73,12 @@ public class TestClassToSerialize implements Serializable { ...@@ -70,167 +73,12 @@ public class TestClassToSerialize implements Serializable {
this.samplesCount = samplesCount; this.samplesCount = samplesCount;
} }
// SAMPLES public List<Sample> getSampleList() {
int samplesCount; return sampleList;
int uidR;
public int getUidR() {
return uidR;
}
public void setUidR(int uidR) {
this.uidR = uidR;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public long getMem() {
return mem;
}
public void setMem(long mem) {
this.mem = mem;
}
public long getLockHoldingTime() {
return lockHoldingTime;
}
public void setLockHoldingTime(long lockHoldingTime) {
this.lockHoldingTime = lockHoldingTime;
}
public long getWaitingTime() {
return waitingTime;
}
public void setWaitingTime(long waitingTime) {
this.waitingTime = waitingTime;
}
public long getMinorPageFaults() {
return minorPageFaults;
}
public void setMinorPageFaults(long minorPageFaults) {
this.minorPageFaults = minorPageFaults;
} }
public long getMajorPageFaults() { public void setSampleList(ArrayList<Sample> sampleList) {
return majorPageFaults; this.sampleList = sampleList;
} }
public void setMajorPageFaults(long majorPageFaults) {
this.majorPageFaults = majorPageFaults;
}
long time;
long mem;
long lockHoldingTime;
long waitingTime;
long minorPageFaults;
long majorPageFaults;
public int getNumOfFeatures() {
return numOfFeatures;
}
public void setNumOfFeatures(int numOfFeatures) {
this.numOfFeatures = numOfFeatures;
}
public long getNameOffset() {
return nameOffset;
}
public void setNameOffset(long nameOffset) {
this.nameOffset = nameOffset;
}
public long getTypeOffset() {
return typeOffset;
}
public void setTypeOffset(long typeOffset) {
this.typeOffset = typeOffset;
}
public long getValue() {
return value;
}
public void setValue(long value) {
this.value = value;
}
// NUM OF FEATURES
int numOfFeatures;
long nameOffset;
long typeOffset;
long value;
public int getNumOfBranches() {
return numOfBranches;
}
public void setNumOfBranches(int numOfBranches) {
this.numOfBranches = numOfBranches;
}
public int getBranchId() {
return branchId;
}
public void setBranchId(int branchId) {
this.branchId = branchId;
}
public int getNumOfExecutions() {
return numOfExecutions;
}
public void setNumOfExecutions(int numOfExecutions) {
this.numOfExecutions = numOfExecutions;
}
public boolean isTaken() {
return taken;
}
public void setTaken(boolean taken) {
this.taken = taken;
}
public int getNumOfChildren() {
return numOfChildren;
}
public void setNumOfChildren(int numOfChildren) {
this.numOfChildren = numOfChildren;
}
public int getcId() {
return cId;
}
public void setcId(int cId) {
this.cId = cId;
}
// BRANCHES
int numOfBranches;
int branchId;
int numOfExecutions;
boolean taken;
// CHILDREN
int numOfChildren;
int cId;
} }
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