2020-01-28 04:11:05 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <fstream>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "mesa/util/os_time.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2020-02-04 08:39:27 +00:00
|
|
|
string os, cpu, gpu, ram, kernel, driver;
|
|
|
|
bool sysInfoFetched = false;
|
2020-04-08 14:53:34 +00:00
|
|
|
int gpuLoadLog = 0, cpuLoadLog = 0, log_period = 0, elapsedLog;
|
2020-01-28 04:11:05 +00:00
|
|
|
|
|
|
|
struct logData{
|
|
|
|
double fps;
|
2020-04-08 14:53:34 +00:00
|
|
|
int cpu;
|
|
|
|
int gpu;
|
|
|
|
int previous;
|
2020-01-28 04:11:05 +00:00
|
|
|
};
|
|
|
|
|
2020-04-08 14:53:34 +00:00
|
|
|
double fps;
|
2020-01-28 04:11:05 +00:00
|
|
|
std::vector<logData> logArray;
|
|
|
|
ofstream out;
|
|
|
|
const char* log_period_env = std::getenv("LOG_PERIOD");
|
2020-03-13 15:27:45 +00:00
|
|
|
int num;
|
2020-01-28 04:11:05 +00:00
|
|
|
bool loggingOn;
|
|
|
|
uint64_t log_start;
|
|
|
|
|
2020-04-08 14:53:34 +00:00
|
|
|
void writeFile(string filename){
|
|
|
|
out.open(filename, ios::out | ios::app);
|
2020-02-05 06:07:23 +00:00
|
|
|
|
2020-04-08 14:53:34 +00:00
|
|
|
for (size_t i = 0; i < logArray.size(); i++)
|
|
|
|
out << logArray[i].fps << "," << logArray[i].cpu << "," << logArray[i].gpu << "," << logArray[i].previous << endl;
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
logArray.clear();
|
|
|
|
}
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2020-05-01 21:55:21 +00:00
|
|
|
void logging(void *params_void){
|
2020-03-13 15:27:45 +00:00
|
|
|
overlay_params *params = reinterpret_cast<overlay_params *>(params_void);
|
2020-01-28 04:11:05 +00:00
|
|
|
time_t now_log = time(0);
|
|
|
|
tm *log_time = localtime(&now_log);
|
2020-04-03 20:28:45 +00:00
|
|
|
string date = to_string(log_time->tm_year + 1900) + "-" +
|
|
|
|
to_string(1 + log_time->tm_mon) + "-" +
|
|
|
|
to_string(log_time->tm_mday) + "_" +
|
|
|
|
to_string(1 + log_time->tm_hour) + "-" +
|
|
|
|
to_string(1 + log_time->tm_min) + "-" +
|
|
|
|
to_string(1 + log_time->tm_sec);
|
2020-01-28 04:11:05 +00:00
|
|
|
log_start = os_time_get();
|
2020-03-13 15:06:57 +00:00
|
|
|
out.open(params->output_file + date, ios::out | ios::app);
|
2020-02-05 06:07:23 +00:00
|
|
|
out << "os," << "cpu," << "gpu," << "ram," << "kernel," << "driver" << endl;
|
|
|
|
out << os << "," << cpu << "," << gpu << "," << ram << "," << kernel << "," << driver << endl;
|
2020-04-08 14:53:34 +00:00
|
|
|
out.close();
|
|
|
|
|
2020-04-03 20:28:45 +00:00
|
|
|
while (loggingOn){
|
2020-01-28 04:11:05 +00:00
|
|
|
uint64_t now = os_time_get();
|
2020-04-08 14:53:34 +00:00
|
|
|
elapsedLog = now - log_start;
|
|
|
|
logArray.push_back({fps, cpuLoadLog, gpuLoadLog, elapsedLog});
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2020-04-09 18:58:05 +00:00
|
|
|
if (params->log_duration && (elapsedLog) >= params->log_duration * 1000000)
|
2020-01-28 04:11:05 +00:00
|
|
|
loggingOn = false;
|
2020-04-08 14:55:28 +00:00
|
|
|
else
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(log_period));
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
2020-04-08 14:53:34 +00:00
|
|
|
|
|
|
|
writeFile(params->output_file + date);
|
2020-04-03 20:28:45 +00:00
|
|
|
}
|