@@ -134,7 +134,10 @@ std::string getStackTrace(); | |||||
/** Returns the number of seconds since application launch. | /** Returns the number of seconds since application launch. | ||||
The goal of this function is to give the most precise (fine-grained) time differences available on the OS for benchmarking purposes, while being fast to compute. | The goal of this function is to give the most precise (fine-grained) time differences available on the OS for benchmarking purposes, while being fast to compute. | ||||
*/ | */ | ||||
double getTime(); | |||||
double getRuntime(); | |||||
/** Returns time since 1970-01-01 00:00:00 UTC in seconds. | |||||
*/ | |||||
double getUnixTime(); | |||||
std::string getOperatingSystemInfo(); | std::string getOperatingSystemInfo(); | ||||
// Applications | // Applications | ||||
@@ -340,7 +340,7 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) { | |||||
// Start CPU timer | // Start CPU timer | ||||
double startTime; | double startTime; | ||||
if (cpuMeter) { | if (cpuMeter) { | ||||
startTime = system::getTime(); | |||||
startTime = system::getRuntime(); | |||||
} | } | ||||
// Step module | // Step module | ||||
@@ -351,7 +351,7 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) { | |||||
// Stop CPU timer | // Stop CPU timer | ||||
if (cpuMeter) { | if (cpuMeter) { | ||||
double endTime = system::getTime(); | |||||
double endTime = system::getRuntime(); | |||||
float duration = endTime - startTime; | float duration = endTime - startTime; | ||||
// Smooth CPU time | // Smooth CPU time | ||||
@@ -564,7 +564,7 @@ void Engine::step(int frames) { | |||||
random::init(); | random::init(); | ||||
internal->stepFrame = internal->frame; | internal->stepFrame = internal->frame; | ||||
internal->stepTime = system::getTime(); | |||||
internal->stepTime = system::getRuntime(); | |||||
internal->stepFrames = frames; | internal->stepFrames = frames; | ||||
// Set sample rate | // Set sample rate | ||||
@@ -596,7 +596,7 @@ void Engine::step(int frames) { | |||||
yieldWorkers(); | yieldWorkers(); | ||||
double endTime = system::getTime(); | |||||
double endTime = system::getRuntime(); | |||||
float duration = endTime - internal->stepTime; | float duration = endTime - internal->stepTime; | ||||
float stepDuration = internal->stepFrames * internal->sampleTime; | float stepDuration = internal->stepFrames * internal->sampleTime; | ||||
// DEBUG("%d %f / %f = %f%%", internal->stepFrames, duration, stepDuration, duration / stepDuration * 100.f); | // DEBUG("%d %f / %f = %f%%", internal->stepFrames, duration, stepDuration, duration / stepDuration * 100.f); | ||||
@@ -17,7 +17,7 @@ static std::mutex logMutex; | |||||
void init() { | void init() { | ||||
startTime = system::getTime(); | |||||
startTime = system::getRuntime(); | |||||
// Don't open a file in development mode. | // Don't open a file in development mode. | ||||
if (settings::devMode) { | if (settings::devMode) { | ||||
outputFile = stderr; | outputFile = stderr; | ||||
@@ -64,7 +64,7 @@ static void logVa(Level level, const char* filename, int line, const char* func, | |||||
if (!outputFile) | if (!outputFile) | ||||
return; | return; | ||||
double nowTime = system::getTime(); | |||||
double nowTime = system::getRuntime(); | |||||
double duration = nowTime - startTime; | double duration = nowTime - startTime; | ||||
if (outputFile == stderr) | if (outputFile == stderr) | ||||
std::fprintf(outputFile, "\x1B[%dm", levelColors[level]); | std::fprintf(outputFile, "\x1B[%dm", levelColors[level]); | ||||
@@ -31,7 +31,7 @@ void InputDevice::onMessage(const Message &message) { | |||||
// Set timestamp to now if unset | // Set timestamp to now if unset | ||||
Message msg = message; | Message msg = message; | ||||
if (msg.timestamp == 0.0) | if (msg.timestamp == 0.0) | ||||
msg.timestamp = system::getTime(); | |||||
msg.timestamp = system::getRuntime(); | |||||
for (Input* input : subscribed) { | for (Input* input : subscribed) { | ||||
// We're probably in the MIDI driver's thread, so set the Rack context. | // We're probably in the MIDI driver's thread, so set the Rack context. | ||||
@@ -69,10 +69,10 @@ void PatchManager::save(std::string path) { | |||||
// Take screenshot (disabled because there is currently no way to quickly view them on any OS or website.) | // Take screenshot (disabled because there is currently no way to quickly view them on any OS or website.) | ||||
// APP->window->screenshot(system::join(asset::autosavePath, "screenshot.png")); | // APP->window->screenshot(system::join(asset::autosavePath, "screenshot.png")); | ||||
double startTime = system::getTime(); | |||||
double startTime = system::getRuntime(); | |||||
// Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked | // Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked | ||||
system::archiveFolder(path, asset::autosavePath, 1); | system::archiveFolder(path, asset::autosavePath, 1); | ||||
double endTime = system::getTime(); | |||||
double endTime = system::getRuntime(); | |||||
INFO("Archived patch in %lf seconds", (endTime - startTime)); | INFO("Archived patch in %lf seconds", (endTime - startTime)); | ||||
} | } | ||||
@@ -222,9 +222,9 @@ void PatchManager::load(std::string path) { | |||||
} | } | ||||
else { | else { | ||||
// Extract the .vcv file as a .tar.zst archive. | // Extract the .vcv file as a .tar.zst archive. | ||||
double startTime = system::getTime(); | |||||
double startTime = system::getRuntime(); | |||||
system::unarchiveToFolder(path, asset::autosavePath); | system::unarchiveToFolder(path, asset::autosavePath); | ||||
double endTime = system::getTime(); | |||||
double endTime = system::getRuntime(); | |||||
INFO("Unarchived patch in %lf seconds", (endTime - startTime)); | INFO("Unarchived patch in %lf seconds", (endTime - startTime)); | ||||
} | } | ||||
@@ -148,7 +148,7 @@ struct RtMidiOutputDevice : midi::OutputDevice { | |||||
else { | else { | ||||
// Get earliest message | // Get earliest message | ||||
const midi::Message& message = messageQueue.top(); | const midi::Message& message = messageQueue.top(); | ||||
double duration = message.timestamp - system::getTime(); | |||||
double duration = message.timestamp - system::getRuntime(); | |||||
// If we need to wait, release the lock and wait for the timeout, or if the CV is notified. | // If we need to wait, release the lock and wait for the timeout, or if the CV is notified. | ||||
// This correctly handles MIDI messages with no timestamp, because duration will be NAN. | // This correctly handles MIDI messages with no timestamp, because duration will be NAN. | ||||
@@ -536,7 +536,7 @@ std::string getStackTrace() { | |||||
static int64_t startTime = 0; | static int64_t startTime = 0; | ||||
#endif | #endif | ||||
static void initTime() { | |||||
static void initRuntime() { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
assert(startCounter == 0); | assert(startCounter == 0); | ||||
LARGE_INTEGER counter; | LARGE_INTEGER counter; | ||||
@@ -564,7 +564,7 @@ static void initTime() { | |||||
#endif | #endif | ||||
} | } | ||||
double getTime() { | |||||
double getRuntime() { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
LARGE_INTEGER counter; | LARGE_INTEGER counter; | ||||
QueryPerformanceCounter(&counter); | QueryPerformanceCounter(&counter); | ||||
@@ -588,6 +588,12 @@ double getTime() { | |||||
} | } | ||||
double getUnixTime() { | |||||
auto duration = std::chrono::system_clock::now().time_since_epoch(); | |||||
return std::chrono::duration<double>(duration).count(); | |||||
} | |||||
std::string getOperatingSystemInfo() { | std::string getOperatingSystemInfo() { | ||||
#if defined ARCH_LIN || defined ARCH_MAC | #if defined ARCH_LIN || defined ARCH_MAC | ||||
struct utsname u; | struct utsname u; | ||||
@@ -656,7 +662,7 @@ void runProcessDetached(const std::string& path) { | |||||
void init() { | void init() { | ||||
initTime(); | |||||
initRuntime(); | |||||
} | } | ||||