#include "log.hh" #include "time_io.hh" #include #include Log::Log() { log_file = "./tick_times.log"; opened = false; } Log::~Log() { if (opened) { close_log_file(); } } void Log::open_log_file() { log = fopen(log_file, "w"); if (!log) { std::cerr << "Couldn't create or open file: " << log_file << std::endl; exit(EXIT_FAILURE); } else { opened = true; } } void Log::close_log_file() { fclose(log); } long long unsigned int Log::now_in_ns() { std::chrono::time_point now = std::chrono::system_clock::now(); time_t tnow = std::chrono::system_clock::to_time_t(now); tm *date = std::localtime(&tnow); date->tm_hour = 0; date->tm_min = 0; date->tm_sec = 0; tp_t midnight = std::chrono::system_clock::from_time_t(std::mktime(date)); return std::chrono::duration_cast(now - midnight).count(); } void Log::print_time_to_file() { fprintf(log, "%llu\n", now_in_ns()); }