Browse Source

Rename system::getTime() to getRuntime(). Add system::getUnixTime().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
790e1053cc
7 changed files with 25 additions and 16 deletions
  1. +4
    -1
      include/system.hpp
  2. +4
    -4
      src/engine/Engine.cpp
  3. +2
    -2
      src/logger.cpp
  4. +1
    -1
      src/midi.cpp
  5. +4
    -4
      src/patch.cpp
  6. +1
    -1
      src/rtmidi.cpp
  7. +9
    -3
      src/system.cpp

+ 4
- 1
include/system.hpp View File

@@ -134,7 +134,10 @@ std::string getStackTrace();
/** 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.
*/
double getTime();
double getRuntime();
/** Returns time since 1970-01-01 00:00:00 UTC in seconds.
*/
double getUnixTime();
std::string getOperatingSystemInfo();

// Applications


+ 4
- 4
src/engine/Engine.cpp View File

@@ -340,7 +340,7 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) {
// Start CPU timer
double startTime;
if (cpuMeter) {
startTime = system::getTime();
startTime = system::getRuntime();
}

// Step module
@@ -351,7 +351,7 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) {

// Stop CPU timer
if (cpuMeter) {
double endTime = system::getTime();
double endTime = system::getRuntime();
float duration = endTime - startTime;

// Smooth CPU time
@@ -564,7 +564,7 @@ void Engine::step(int frames) {
random::init();

internal->stepFrame = internal->frame;
internal->stepTime = system::getTime();
internal->stepTime = system::getRuntime();
internal->stepFrames = frames;

// Set sample rate
@@ -596,7 +596,7 @@ void Engine::step(int frames) {

yieldWorkers();

double endTime = system::getTime();
double endTime = system::getRuntime();
float duration = endTime - internal->stepTime;
float stepDuration = internal->stepFrames * internal->sampleTime;
// DEBUG("%d %f / %f = %f%%", internal->stepFrames, duration, stepDuration, duration / stepDuration * 100.f);


+ 2
- 2
src/logger.cpp View File

@@ -17,7 +17,7 @@ static std::mutex logMutex;


void init() {
startTime = system::getTime();
startTime = system::getRuntime();
// Don't open a file in development mode.
if (settings::devMode) {
outputFile = stderr;
@@ -64,7 +64,7 @@ static void logVa(Level level, const char* filename, int line, const char* func,
if (!outputFile)
return;

double nowTime = system::getTime();
double nowTime = system::getRuntime();
double duration = nowTime - startTime;
if (outputFile == stderr)
std::fprintf(outputFile, "\x1B[%dm", levelColors[level]);


+ 1
- 1
src/midi.cpp View File

@@ -31,7 +31,7 @@ void InputDevice::onMessage(const Message &message) {
// Set timestamp to now if unset
Message msg = message;
if (msg.timestamp == 0.0)
msg.timestamp = system::getTime();
msg.timestamp = system::getRuntime();

for (Input* input : subscribed) {
// We're probably in the MIDI driver's thread, so set the Rack context.


+ 4
- 4
src/patch.cpp View File

@@ -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.)
// 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
system::archiveFolder(path, asset::autosavePath, 1);
double endTime = system::getTime();
double endTime = system::getRuntime();
INFO("Archived patch in %lf seconds", (endTime - startTime));
}

@@ -222,9 +222,9 @@ void PatchManager::load(std::string path) {
}
else {
// Extract the .vcv file as a .tar.zst archive.
double startTime = system::getTime();
double startTime = system::getRuntime();
system::unarchiveToFolder(path, asset::autosavePath);
double endTime = system::getTime();
double endTime = system::getRuntime();
INFO("Unarchived patch in %lf seconds", (endTime - startTime));
}



+ 1
- 1
src/rtmidi.cpp View File

@@ -148,7 +148,7 @@ struct RtMidiOutputDevice : midi::OutputDevice {
else {
// Get earliest message
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.
// This correctly handles MIDI messages with no timestamp, because duration will be NAN.


+ 9
- 3
src/system.cpp View File

@@ -536,7 +536,7 @@ std::string getStackTrace() {
static int64_t startTime = 0;
#endif

static void initTime() {
static void initRuntime() {
#if defined ARCH_WIN
assert(startCounter == 0);
LARGE_INTEGER counter;
@@ -564,7 +564,7 @@ static void initTime() {
#endif
}

double getTime() {
double getRuntime() {
#if defined ARCH_WIN
LARGE_INTEGER 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() {
#if defined ARCH_LIN || defined ARCH_MAC
struct utsname u;
@@ -656,7 +662,7 @@ void runProcessDetached(const std::string& path) {


void init() {
initTime();
initRuntime();
}




Loading…
Cancel
Save