...
 
Commits (3)
......@@ -6,12 +6,10 @@ import java.util.stream.Collectors;
public class AppRunData {
private List<Double> samples;
protected Application<?> application;
private Integer numberSamples;
public AppRunData(Application<?> application, List<Double> samples) {
this.application = application;
this.samples = samples;
this.numberSamples = samples.size();
}
public List<Double> getSamples() {
......@@ -26,52 +24,12 @@ public class AppRunData {
return UtilsKt.variance(samples);
}
public Double getStandardDeviation() {
return Math.sqrt(getVariance());
}
public Application<?> getApplication() {
return application;
}
public Integer getNumberSamples() {
return numberSamples;
}
public Double getMedian() {
return UtilsKt.median(samples);
}
public List<Double> cleanSamples() {
List<Double> sorted = samples.stream().sorted().collect(Collectors.toList());
Boolean even = numberSamples % 2 == 0;
Double q1, q3, iqr, k;
int i, j, h, l;
i = numberSamples / 10;
h = 9 * numberSamples / 10;
if (even) {
j = i + 1;
l = h + 1;
q1 = 0.5 * sorted.get(i) + sorted.get(j);
q3 = 0.5 * sorted.get(h) + sorted.get(l);
} else {
q1 = sorted.get(i);
q3 = sorted.get(h);
}
iqr = q3 - q1;
k = 10.0;
return samples.stream().filter(
x -> x >= (q1) && x <= (q3)
).collect(Collectors.toList());
}
public List<Double> cleanSamples2() {
Double average = getAverage();
Double up = average + 2 * getStandardDeviation();
Double down = average - 2 * getStandardDeviation();
return samples.stream().filter(
x -> x >= down && x <= up
).collect(Collectors.toList());
}
}
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
import java.util.*;
public class RandomList<T> implements List<T> {
List<T> implementation;
public RandomList(List impl) {
implementation = impl;
}
@Override
public int size() {
return implementation.size();
}
@Override
public boolean isEmpty() {
return implementation.isEmpty();
}
@Override
public boolean contains(Object o) {
return implementation.contains(o);
}
@NotNull
@Override
public Iterator<T> iterator() {
return implementation.iterator();
}
@NotNull
@Override
public Object[] toArray() {
return implementation.toArray();
}
@NotNull
@Override
public <T1> T1[] toArray(@NotNull T1[] t1s) {
return implementation.toArray(t1s);
}
@Override
public boolean add(T t) {
return implementation.add(t);
}
@Override
public boolean remove(Object o) { return implementation.remove(o); }
@Override
public boolean containsAll(@NotNull Collection<?> collection) {
return implementation.containsAll(collection);
}
@Override
public boolean addAll(@NotNull Collection<? extends T> collection) {
return implementation.addAll(collection);
}
@Override
public boolean addAll(int i, @NotNull Collection<? extends T> collection) {
return implementation.addAll(i, collection);
}
@Override
public boolean removeAll(@NotNull Collection<?> collection) {
return removeAll(collection);
}
@Override
public boolean retainAll(@NotNull Collection<?> collection) {
return retainAll(collection);
}
@Override
public void clear() {
implementation.clear();
}
@Override
public T get(int i) {
return implementation.get(i);
}
@Override
public T set(int i, T t) {
return implementation.set(i, t);
}
@Override
public void add(int i, T t) {
implementation.add(i, t);
}
@Override
public T remove(int i) {
return implementation.remove(i);
}
@Override
public int indexOf(Object o) {
return implementation.indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
return implementation.lastIndexOf(o);
}
@NotNull
@Override
public ListIterator<T> listIterator() {
return implementation.listIterator();
}
@NotNull
@Override
public ListIterator<T> listIterator(int i) {
return implementation.listIterator(i);
}
@NotNull
@Override
public List<T> subList(int i, int i1) {
return implementation.subList(i, i1);
}
}
package se.lth.cs.Random;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
public class RandomListMethodSequence extends RandomMethodSequence<List<Integer>>{
public RandomListMethodSequence(Long seed, Integer applicationSize, List targetObject) {
super(seed, applicationSize, targetObject);
}
@Override
public Object generateArgument(Class expectedClass) {
if (expectedClass == java.lang.Integer.class) {
return generateIndex();
}
if (expectedClass == java.util.Comparator.class) {
return Comparator.comparingInt(x -> (int) x);
}
if (expectedClass == java.util.Collection.class) {
return generateCollection();
}
return generateValue();
}
@Override
public int generateIndex() {
return generator.nextInt(targetObject.size());
}
@Override
public Collection<Integer> generateCollection() {
ArrayList l = new ArrayList();
generator.ints(targetObject.size() / 2).forEach(
x -> l.add(x)
);
return l;
}
}
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class RandomMap<K, V> implements Map<K, V> {
Map<K, V> implemetation;
@Override
public int size() {
return implemetation.size();
}
@Override
public boolean isEmpty() {
return implemetation.isEmpty();
}
@Override
public boolean containsKey(Object o) {
return implemetation.containsKey(o);
}
@Override
public boolean containsValue(Object o) {
return implemetation.containsValue(o);
}
@Override
public V get(Object o) {
return get(o);
}
@Nullable
@Override
public V put(K k, V v) {
return implemetation.put(k, v);
}
@Override
public V remove(Object o) {
return implemetation.remove(o);
}
@Override
public void putAll(@NotNull Map<? extends K, ? extends V> map) {
implemetation.putAll(map);
}
@Override
public void clear() {
implemetation.clear();
}
@NotNull
@Override
public Set<K> keySet() {
return implemetation.keySet();
}
@NotNull
@Override
public Collection<V> values() {
return implemetation.values();
}
@NotNull
@Override
public Set<Entry<K, V>> entrySet() {
return implemetation.entrySet();
}
}
package se.lth.cs.Random;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
public abstract class RandomMethodSequence<T> {
Random generator;
Method[] methodSequence;
int currentMethodIndex = 0;
Object[][] arguments;
T targetObject;
boolean methodMatch(Method m, Method m1) {
return m.getName() == m1.getName()
&& m.getParameterTypes().equals(m.getParameterTypes())
&& m.getReturnType().equals(m.getReturnType());
}
RandomMethodSequence(Long seed, Integer applicationSize, T targetObject) {
generator = new Random(seed);
methodSequence = new Method[applicationSize];
arguments = new Object[applicationSize][0];
this.targetObject = targetObject;
// We get the methods to run on our object
List<Method> methodsSelected = Arrays.stream(targetObject.getClass().getMethods())
.sorted(Comparator.comparing(Method::getName))
.filter(m -> !m.isDefault()) // No Default methods!
.collect(Collectors.toList());
for (int i = 0; i < applicationSize; i++) {
int index = generator.nextInt(methodsSelected.size());
methodSequence[i] = methodsSelected.get(index);
arguments[i] = generateArguments(methodSequence[i]);
}
}
public Object generateArgument(Class toGenerate) {
if (toGenerate.equals(java.lang.Integer.class)) {
return generateIndex();
} else {
return generateValue();
}
}
public Object[] generateArguments(Method m) {
Object[] args = new Object[m.getParameterCount()];
Class[] argTypes = m.getParameterTypes();
for (int i = 0; i < m.getParameterCount(); ++i) {
Class toGenerate = argTypes[i];
args[i] = generateArgument(toGenerate);
}
return args;
}
public abstract int generateIndex();
public Integer generateValue() {
return generator.nextInt();
}
public abstract Collection<Integer> generateCollection();
public Object runCurrentMethod() throws InvocationTargetException, IllegalAccessException {
return methodSequence[currentMethodIndex].invoke(targetObject,
arguments[currentMethodIndex]);
}
public void tick() {
currentMethodIndex++;
}
public boolean isFinished() {
return currentMethodIndex == methodSequence.length - 1;
}
}
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
public class RandomSet<T> implements Set<T> {
Set<T> implementation;
@Override
public int size() {
return implementation.size();
}
@Override
public boolean isEmpty() {
return implementation.isEmpty();
}
@Override
public boolean contains(Object o) {
return implementation.contains(o);
}
@NotNull
@Override
public Iterator<T> iterator() {
return implementation.iterator();
}
@NotNull
@Override
public Object[] toArray() {
return implementation.toArray();
}
@NotNull
@Override
public <T1> T1[] toArray(@NotNull T1[] t1s) {
return implementation.toArray(t1s);
}
@Override
public boolean add(T t) {
return implementation.add(t);
}
@Override
public boolean remove(Object o) {
return implementation.remove(o);
}
@Override
public boolean containsAll(@NotNull Collection<?> collection) {
return implementation.containsAll(collection);
}
@Override
public boolean addAll(@NotNull Collection<? extends T> collection) {
return implementation.addAll(collection);
}
@Override
public boolean retainAll(@NotNull Collection<?> collection) {
return implementation.retainAll(collection);
}
@Override
public boolean removeAll(@NotNull Collection<?> collection) {
return implementation.removeAll(collection);
}
@Override
public void clear() {
implementation.clear();
}
}
package se.lth.cs
import papi.EventSet
/**
* Runs functions and gathers the performance counters, in Interleaved mode
* (For each counter, run the full benchmark)
*/
@Deprecated("Use PapiRunner instead")
class PapiInterleavedRunner(counterSpecification: CounterSpecification) : PapiRunner(counterSpecification) {
/**
* Runs a list of applications in "interleaved mode"
* (that is, choose the counter first and run all application with this counter,
* then pick another counter)
*/
override fun runApplications(numRuns: Int, applications: Sequence<Application<*>>)
: List<MutableMap<String, List<Long>>> {
var data : MutableList<MutableMap<String, List<Long>>> = mutableListOf()
for (app in applications) {
data.add(mutableMapOf())
}
for (kvp in counterSpec.currentSpec) {
val evset = EventSet.create(kvp.value)
println("Interleaved mode: " + "'" + kvp.key + "'")
// For each run-number
for (run in 0..numRuns) {
// We run each program
var appIndex = 0
for (app in applications) {
// We do the measurements
evset.start()
while (app.hasNext()) {
val r = app.invokeCurrentMethod();
app.tick();
}
evset.stop()
val result = app.getDataStructure()
//println(result)
// We record the data
val counterdata = evset.counters
data.get(appIndex).put(kvp.key, counterdata.toList())
appIndex++
}
}
}
return data
}
}