mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
65 lines
1.5 KiB
C++
65 lines
1.5 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
|
|
// Seconds.
|
|
double time_now_d();
|
|
|
|
// Raw time in nanoseconds.
|
|
// The only intended use is to match the timings from VK_GOOGLE_display_timing.
|
|
uint64_t time_now_raw();
|
|
|
|
// This is only interesting for Linux, in relation to VK_GOOGLE_display_timing.
|
|
double from_time_raw(uint64_t raw_time);
|
|
double from_time_raw_relative(uint64_t raw_time);
|
|
|
|
// Seconds, Unix UTC time
|
|
double time_now_unix_utc();
|
|
|
|
// Sleep. Does not necessarily have millisecond granularity, especially on Windows.
|
|
void sleep_ms(int ms);
|
|
|
|
// Yield. Signals that this thread is busy-waiting but wants to allow other hyperthreads to run.
|
|
void yield();
|
|
|
|
void GetCurrentTimeFormatted(char formattedTime[13]);
|
|
|
|
// Rust-style Instant for clear and easy timing.
|
|
class Instant {
|
|
public:
|
|
static Instant Now() {
|
|
return Instant(time_now_d());
|
|
}
|
|
double ElapsedSeconds() const {
|
|
return time_now_d() - instantTime_;
|
|
}
|
|
private:
|
|
explicit Instant(double initTime) : instantTime_(initTime) {}
|
|
double instantTime_;
|
|
};
|
|
|
|
// 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
|
|
};
|
|
|
|
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_;
|
|
};
|