|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /*
- * main.cpp
- *
- * Created on: Dec 4, 2020
- * Author: hoo2
- */
- #include <sstream>
- #include <fstream>
- #include <iostream>
- #include <algorithm>
-
- #define SIZE 20
-
- std::ifstream file;
-
- /*!
- * Calculates and return the median of an array of measurements
- * \param t Pointer to measurements
- * \param n Size of measurements array
- * \return The average
- */
- int median (int *t, int n) {
- std::sort (t, &t[n]);
- return (n % 2) ? t[n/2] : (t[n/2] + t[n/2 -1]) /2;
- }
-
- /*
- * A small post processing...
- */
- int main(int argc, char* argv[]) {
- file = std::ifstream(argv[1]);
- std::string line, token, exec, mtx, times, dt, units, dyn1, dyn2;
- std::string t1, t2, t3, t4;
- enum state_en {RUNNING, LOAD, DATA, SUM} state = RUNNING;
- int cnt =0, med =0;
- int delta_t[SIZE];
-
- while (std::getline (file, line, '\n')) {
- std::stringstream ss(line);
-
- switch (state) {
- case RUNNING:
- ss >> token;
- if (token == "running") {
- ss >> exec >> t1 >> mtx >> t2 >> times >> t3 >> t4 >> dyn1 >> dyn2;
- cnt =0;
- state = LOAD;
- }
- break;
-
- case LOAD: state = DATA; break;
-
- case DATA:
- ss >> t1 >> t2 >> t3 >> dt >> units;
- if (units == "[usec]") delta_t[cnt] = std::atoi(dt.c_str());
- else if (units == "[msec]") delta_t[cnt] = std::atoi(dt.c_str()) * 1000;
- else if (units == "[sec]") delta_t[cnt] = std::atoi(dt.c_str()) * 1000000;
- if (++cnt == std::atoi(times.c_str())) {
- med = median (delta_t, cnt);
- cnt =0;
- state = SUM;
- }
- break;
-
- case SUM:
- ss >> token;
- if (token == "running") {
- std::cout << exec << ',' << mtx << ',' << med << ", ," <<
- (((dyn1 == "--dynamic") || (dyn2 == "--dynamic")) ? "dyn\n" : " \n");
- dyn1 = "";
- dyn2 = "";
- ss >> exec >> t1 >> mtx >> t2 >> times >> t3 >> t4 >> dyn1 >> dyn2;
- cnt =0;
- state = LOAD;
- }
- else if (token == "[Timing]:") {
- ss >> t1 >> t2 >> dt >> units;
- if (units == "[usec]") med += std::atoi(dt.c_str());
- else if (units == "[msec]") med += std::atoi(dt.c_str()) * 1000;
- else if (units == "[sec]") med += std::atoi(dt.c_str()) * 1000000;
- state = RUNNING;
- std::cout << exec << ',' << mtx << ',' << med << ",sum," <<
- (((dyn1 == "--dynamic") || (dyn2 == "--dynamic")) ? "dyn\n" : " \n");
- dyn1 = "";
- dyn2 = "";
- }
- break;
- }
-
- }
-
- return 0;
- }
|