-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexperiment.cpp
109 lines (97 loc) · 2.92 KB
/
experiment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "experiment.h"
#include "odroidreader.h"
#include "environments.h"
#include <QJsonArray>
Experiment::Experiment(const QJsonObject &jo, const QVector<DataSeries *> &descs, const Environments& envs)
: wasRun(false), data(descs)
{
title = jo["title"].toString();
prepare = jo["prepare"].toString();
cleanup = jo["cleanup"].toString();
command = jo["command"].toString();
for (QJsonValueRef o : jo["environment_sets"].toArray()) {
EnvironmentSet* s = envs.findSet(o.toString());
if (s == nullptr) {
qWarning() << "Unknown environment set for Experiment " << title << "Broken file?";
} else {
envSets.append(envs.findSet(o.toString()));
}
}
for (QJsonValueRef v : jo["environments"].toArray()) {
const QJsonObject& o = v.toObject();
Environment* e = new Environment(o);
if (o.contains("runs")) {
for (QJsonValueRef vr : o["runs"].toArray()) {
QJsonObject ro = vr.toObject();
QPair<double,double> v(ro["from"].toDouble(),ro["to"].toDouble());
runs[e].push_back(v);
}
wasRun = true;
}
}
cooldown_time = jo["cooldown_time"].toInt();
tail_time = jo["tail_time"].toInt();
}
void Experiment::write(QJsonObject& jo, bool withRuns) const {
jo["title"] = title;
jo["prepare"] = prepare;
jo["cleanup"] = cleanup;
jo["command"] = command;
QJsonArray sets;
for (const EnvironmentSet* s : envSets) {
sets.push_back(s->name());
}
QJsonArray envs;
for (const Environment* e : runs.keys()) {
QJsonObject o;
o["big"] = e->big;
o["little"] = e->big;
o["label"] = e->label;
o["frequency"] = static_cast<qint64>(e->freq);
o["frequency_max"] = static_cast<qint64>(e->freq_max);
o["frequency_min"] = static_cast<qint64>(e->freq_min);
o["governor"] = e->governor;
if (withRuns) {
QJsonArray runArray;
for (QPair<double,double> run : runs[e]) {
QJsonObject jr;
jr["from"] = run.first;
jr["to"] = run.second;
runArray.push_back(jr);
}
o["runs"] = runArray;
}
envs.append(o);
}
jo["environment_sets"] = sets;
jo["environments"] = envs;
jo["cooldown_time"] = static_cast<qint64>(cooldown_time);
jo["tail_time"] = static_cast<qint64>(tail_time);
}
QString Experiment::prepareMeasurement() {
return prepare;
}
QString Experiment::startMeasurement(double time,const Environment* env) {
lastEnvironment = env;
runs[lastEnvironment].push_back(QPair<double,double>(time,time));
return command;
}
QString Experiment::cleanupMeasurement(float time) {
runs[lastEnvironment].back().second = time;
wasRun = true;
return cleanup;
}
bool Experiment::hasData() const { return wasRun; }
void Experiment::finishedCleanup(float) {}
StatisticalSet Experiment::aggregate(int unit, const Experiment* e) const {
StatisticalSet s(e->data.at(unit)->descriptor);
for (const Environment* env : runs.keys())
s.extend(env->aggregate(unit,e));
return s;
}
unsigned Experiment::executions() const {
unsigned i = 0;
for (EnvironmentSet* s : envSets)
i += s->environments().size();
return i;
}