Skip to content

Commit 19b6690

Browse files
authored
special handling of All filter for calib tasks
special handling of All filter for calib tasks
2 parents 57ef540 + 1cd2968 commit 19b6690

File tree

1 file changed

+81
-16
lines changed

1 file changed

+81
-16
lines changed

examples/15-ODC.cxx

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,89 @@ void httpServer(tcp::acceptor& acceptor, tcp::socket& socket) {
9898
std::string calib = std::string(request.target().substr(request.target().find("WHERE+calib+%3D+") + 16));
9999
std::string calibTasksJson;
100100
const std::lock_guard<std::mutex> lock(gMapAccess);
101-
calibTasksJson += "[" + std::to_string(0);
101+
calibTasksJson += "[";
102102
int countOk = 0;
103+
bool keepAll = 0;
104+
if (!calib.compare(0,3, "All")) {
105+
keepAll = 1;
106+
}
103107
for (const auto& run : gStats) {
104-
if (run.second.TasksPerCalib.find(calib) != run.second.TasksPerCalib.end()) {
105-
calibTasksJson += ", \"";
106-
if (run.second.CalibNames.find(calib) != run.second.CalibNames.end()) {
107-
calibTasksJson += run.second.CalibNames.at(calib) + "\",";
108-
} else {
109-
calibTasksJson += "<None>\",";
110-
}
111-
calibTasksJson += std::to_string(run.second.TasksPerCalib.at(calib));
112-
if (run.second.FailedTasksPerCalib.find(calib) != run.second.FailedTasksPerCalib.end()) {
113-
calibTasksJson += "," + std::to_string(run.second.FailedTasksPerCalib.at(calib));
114-
} else {
115-
calibTasksJson += ",0";
116-
}
117-
countOk++;
118-
}
108+
/*
109+
// test code to dump content of gStats items
110+
// based on runtime tests, here are the findings:
111+
// run.first is the partition Id
112+
// run.second is an OdcStats struct
113+
// example output with 2 tasks in 2 partitions
114+
// iterating 2tCTU23Be7j
115+
// tasks per calib = 1
116+
// failed tasks per calib = 0
117+
// calib names = 1
118+
// task calib4 = 5
119+
// name calib4 = barrel_tf
120+
// iterating 2tCWsyiDYm7
121+
// tasks per calib = 1
122+
// failed tasks per calib = 0
123+
// calib names = 0
124+
// task calib2 = 14
125+
//
126+
std::cout << "iterating " << run.first << std::endl;
127+
std::cout << "tasks per calib = " << run.second.TasksPerCalib.size() << std::endl;
128+
std::cout << "failed tasks per calib = " << run.second.FailedTasksPerCalib.size() << std::endl;
129+
std::cout << "calib names = " << run.second.CalibNames.size() << std::endl;
130+
for (const auto& p : run.second.TasksPerCalib) {
131+
std::cout << "task " << p.first << " = " << p.second << std::endl;
132+
}
133+
for (const auto& p : run.second.FailedTasksPerCalib) {
134+
std::cout << "failed " << p.first << " = " << p.second << std::endl;
135+
}
136+
for (const auto& p : run.second.CalibNames) {
137+
std::cout << "name " << p.first << " = " << p.second << std::endl;
138+
}
139+
*/
140+
// iterate over defined calib names, not the ones
141+
142+
for(const auto &t: run.second.TasksPerCalib) {
143+
unsigned int timestamp = 0;
144+
std::string name = "<None>";
145+
unsigned int tasksPerCalib = 0;
146+
unsigned int failedTasks = 0;
147+
148+
std::string theCalib = t.first;
149+
if (!keepAll && (calib != theCalib)) {
150+
// filter out this element, it does not match queried calib name
151+
continue;
152+
}
153+
154+
tasksPerCalib = t.second;
155+
156+
// find matching calib name
157+
auto nameIt = run.second.CalibNames.find(theCalib);
158+
if (nameIt != run.second.CalibNames.end()) {
159+
name = (*nameIt).second;
160+
}
161+
162+
// find matching calib failedTasks
163+
auto failedIt = run.second.FailedTasksPerCalib.find(theCalib);
164+
if (failedIt != run.second.FailedTasksPerCalib.end()) {
165+
failedTasks = (*failedIt).second;
166+
}
167+
168+
// insert task in JSON
169+
if (countOk) {
170+
// next vector
171+
calibTasksJson += "], [";
172+
}
173+
calibTasksJson +=
174+
std::to_string(timestamp)
175+
+ ", \""
176+
+ name
177+
+ "\", "
178+
+ std::to_string(tasksPerCalib)
179+
+ ", "
180+
+ std::to_string(failedTasks);
181+
182+
countOk++;
183+
}
119184
}
120185
calibTasksJson += "]";
121186
// workaround to set valid reply if nothing to report

0 commit comments

Comments
 (0)