MangoHud/src/logging.h

69 lines
1.9 KiB
C
Raw Normal View History

#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;
int gpuLoadLog = 0, cpuLoadLog = 0, log_period = 0, elapsedLog;
struct logData{
double fps;
int cpu;
int gpu;
int previous;
};
double fps;
std::vector<logData> logArray;
ofstream out;
const char* log_period_env = std::getenv("LOG_PERIOD");
int num;
bool loggingOn;
uint64_t log_start;
void writeFile(string filename){
out.open(filename, ios::out | ios::app);
2020-02-05 06:07:23 +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-05-01 21:55:21 +00:00
void logging(void *params_void){
overlay_params *params = reinterpret_cast<overlay_params *>(params_void);
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);
log_start = os_time_get();
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;
out.close();
2020-04-03 20:28:45 +00:00
while (loggingOn){
uint64_t now = os_time_get();
elapsedLog = now - log_start;
logArray.push_back({fps, cpuLoadLog, gpuLoadLog, elapsedLog});
if (params->log_duration && (elapsedLog) >= params->log_duration * 1000000)
loggingOn = false;
2020-04-08 14:55:28 +00:00
else
this_thread::sleep_for(chrono::milliseconds(log_period));
}
writeFile(params->output_file + date);
2020-04-03 20:28:45 +00:00
}