2012-03-24 22:39:19 +00:00
|
|
|
#pragma once
|
2023-08-02 21:52:46 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
2012-03-24 22:39:19 +00:00
|
|
|
// Seconds.
|
|
|
|
double time_now_d();
|
|
|
|
|
2023-08-02 21:52:46 +00:00
|
|
|
// Raw time in nanoseconds.
|
|
|
|
// The only intended use is to match the timings from VK_GOOGLE_display_timing.
|
|
|
|
uint64_t time_now_raw();
|
|
|
|
|
2023-08-03 09:11:16 +00:00
|
|
|
// This is only interesting for Linux, in relation to VK_GOOGLE_display_timing.
|
|
|
|
double from_time_raw(uint64_t raw_time);
|
2023-08-03 10:59:25 +00:00
|
|
|
double from_time_raw_relative(uint64_t raw_time);
|
2023-08-03 09:11:16 +00:00
|
|
|
|
2023-11-20 10:46:36 +00:00
|
|
|
// Seconds, Unix UTC time
|
|
|
|
double time_now_unix_utc();
|
|
|
|
|
2012-03-31 09:16:13 +00:00
|
|
|
// Sleep. Does not necessarily have millisecond granularity, especially on Windows.
|
2012-03-24 22:39:19 +00:00
|
|
|
void sleep_ms(int ms);
|
2020-10-05 18:58:33 +00:00
|
|
|
|
2023-08-07 19:38:03 +00:00
|
|
|
// Yield. Signals that this thread is busy-waiting but wants to allow other hyperthreads to run.
|
|
|
|
void yield();
|
|
|
|
|
2024-06-05 08:28:49 +00:00
|
|
|
void GetCurrentTimeFormatted(char formattedTime[13]);
|
2022-04-08 09:55:49 +00:00
|
|
|
|
|
|
|
// Rust-style Instant for clear and easy timing.
|
|
|
|
class Instant {
|
|
|
|
public:
|
|
|
|
static Instant Now() {
|
|
|
|
return Instant(time_now_d());
|
|
|
|
}
|
2024-06-05 08:29:04 +00:00
|
|
|
double ElapsedSeconds() const {
|
2022-04-08 09:55:49 +00:00
|
|
|
return time_now_d() - instantTime_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
explicit Instant(double initTime) : instantTime_(initTime) {}
|
|
|
|
double instantTime_;
|
|
|
|
};
|
2024-06-05 08:29:04 +00:00
|
|
|
|
|
|
|
// Most accurate timer possible - no extra double conversions. Only for spans.
|
|
|
|
class TimeSpan {
|
|
|
|
public:
|
|
|
|
TimeSpan();
|
|
|
|
double ElapsedSeconds() const;
|
|
|
|
int64_t ElapsedNanos() const;
|
|
|
|
private:
|
|
|
|
uint64_t nativeStart_;
|
|
|
|
#ifndef _WIN32
|
|
|
|
int64_t nsecs_;
|
|
|
|
#endif
|
|
|
|
};
|
2023-12-21 10:04:28 +00:00
|
|
|
|
|
|
|
class LogScopeIfSlowMs {
|
|
|
|
public:
|
|
|
|
LogScopeIfSlowMs(const char *title, int limitMs) {
|
|
|
|
title_ = title;
|
|
|
|
endTime_ = time_now_d() + 0.001 * limitMs;
|
|
|
|
}
|
|
|
|
~LogScopeIfSlowMs();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *title_;
|
|
|
|
double endTime_;
|
|
|
|
};
|