Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for adding a performance profiler for the IR Interpreter #19252

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,8 @@ list(APPEND NativeAppSource
UI/CwCheatScreen.cpp
UI/InstallZipScreen.h
UI/InstallZipScreen.cpp
UI/JitCompareScreen.h
UI/JitCompareScreen.cpp
UI/MemStickScreen.h
UI/MemStickScreen.cpp
UI/ProfilerDraw.h
Expand Down
2 changes: 1 addition & 1 deletion Common/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void LogManager::Log(LogLevel level, LogType type, const char *file, int line, c
file = fileshort + 1;
}

GetTimeFormatted(message.timestamp);
GetCurrentTimeFormatted(message.timestamp);

if (hleCurrentThreadName) {
snprintf(message.header, sizeof(message.header), "%-12.12s %c[%s]: %s:%d",
Expand Down
21 changes: 14 additions & 7 deletions Common/Render/Text/draw_text_uwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class TextDrawerFontContext {
Destroy();
}

if (factory == nullptr) return;
if (!factory) {
return;
}

HRESULT hr = factory->CreateTextFormat(
fname.c_str(),
Expand All @@ -45,24 +47,29 @@ class TextDrawerFontContext {
L"",
&textFmt
);
if (FAILED(hr)) {
ERROR_LOG(G3D, "Failed creating font %s", fname.c_str());
}
}
void Destroy() {
textFmt->Release();
if (textFmt) {
textFmt->Release();
}
textFmt = nullptr;
}

IDWriteFactory4* factory = nullptr;
IDWriteFontCollection1* fontCollection = nullptr;
IDWriteTextFormat* textFmt = nullptr;
IDWriteFactory4 *factory = nullptr;
IDWriteFontCollection1 *fontCollection = nullptr;
IDWriteTextFormat *textFmt = nullptr;
std::wstring fname;
int height;
DWRITE_FONT_WEIGHT weight;
float dpiScale;
};

struct TextDrawerContext {
ID2D1Bitmap1* bitmap;
ID2D1Bitmap1* mirror_bmp;
ID2D1Bitmap1 *bitmap;
ID2D1Bitmap1 *mirror_bmp;
};

TextDrawerUWP::TextDrawerUWP(Draw::DrawContext *draw) : TextDrawer(draw), ctx_(nullptr) {
Expand Down
80 changes: 74 additions & 6 deletions Common/TimeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdint>

#include "Common/TimeUtil.h"
#include "Common/Log.h"

#ifdef HAVE_LIBNX
#include <switch.h>
Expand Down Expand Up @@ -31,21 +32,25 @@

// TODO: https://github.com/floooh/sokol/blob/9a6237fcdf213e6da48e4f9201f144bcb2dcb46f/sokol_time.h#L229-L248

static const double micros = 1000000.0;
static const double nanos = 1000000000.0;
constexpr double micros = 1000000.0;
constexpr double nanos = 1000000000.0;

#if PPSSPP_PLATFORM(WINDOWS)

static LARGE_INTEGER frequency;
static double frequencyMult;
static LARGE_INTEGER startTime;

double time_now_d() {
static inline void InitTime() {
if (frequency.QuadPart == 0) {
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&startTime);
frequencyMult = 1.0 / static_cast<double>(frequency.QuadPart);
}
}

double time_now_d() {
InitTime();
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
double elapsed = static_cast<double>(time.QuadPart - startTime.QuadPart);
Expand Down Expand Up @@ -86,6 +91,22 @@ void yield() {
YieldProcessor();
}

TimeSpan::TimeSpan() {
_dbg_assert_(frequencyMult != 0.0);
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&nativeStart_));
}

double TimeSpan::ElapsedSeconds() const {
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
double elapsed = static_cast<double>(time.QuadPart - nativeStart_);
return elapsed * frequencyMult;
}

int64_t TimeSpan::ElapsedNanos() const {
return (int64_t)(ElapsedSeconds() * 1000000000.0);
}

#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(LINUX) || PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS)

// The only intended use is to match the timings in VK_GOOGLE_display_timing
Expand Down Expand Up @@ -128,10 +149,34 @@ void yield() {
#endif
}

TimeSpan::TimeSpan() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
nativeStart_ = ts.tv_sec;
nsecs_ = ts.tv_nsec;
}

int64_t TimeSpan::ElapsedNanos() const {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
int64_t secs = ts.tv_sec - nativeStart_;
int64_t nsecs = ts.tv_nsec - nsecs_;
if (nsecs < 0) {
secs--;
nsecs += 1000000000;
}
return secs * 1000000000ULL + nsecs;
}

double TimeSpan::ElapsedSeconds() const {
return (double)ElapsedNanos() * (1.0 / nanos);
}

#else

static time_t start;

double time_now_d() {
static time_t start;
struct timeval tv;
gettimeofday(&tv, nullptr);
if (start == 0) {
Expand All @@ -141,7 +186,6 @@ double time_now_d() {
}

uint64_t time_now_raw() {
static time_t start;
struct timeval tv;
gettimeofday(&tv, nullptr);
if (start == 0) {
Expand All @@ -164,6 +208,30 @@ double time_now_unix_utc() {
return time_now_raw();
}

TimeSpan::TimeSpan() {
struct timeval tv;
gettimeofday(&tv, nullptr);
nativeStart_ = tv.tv_sec;
nsecs_ = tv.tv_usec;
}

int64_t TimeSpan::ElapsedNanos() const {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);

int64_t secs = ts.tv_sec - nativeStart_;
int64_t usecs = ts.tv_nsec - nsecs_;
if (usecs < 0) {
secs--;
usecs += 1000000;
}
return secs * 1000000000 + usecs * 1000;
}

double TimeSpan::ElapsedSeconds() const {
return (double)ElapsedNanos() * (1.0 / 1000000000);
}

#endif

void sleep_ms(int ms) {
Expand All @@ -180,7 +248,7 @@ void sleep_ms(int ms) {

// Return the current time formatted as Minutes:Seconds:Milliseconds
// in the form 00:00:000.
void GetTimeFormatted(char formattedTime[13]) {
void GetCurrentTimeFormatted(char formattedTime[13]) {
time_t sysTime;
time(&sysTime);

Expand Down
18 changes: 15 additions & 3 deletions Common/TimeUtil.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include <cstdint>

// Seconds.
Expand All @@ -22,18 +21,31 @@ void sleep_ms(int ms);
// Yield. Signals that this thread is busy-waiting but wants to allow other hyperthreads to run.
void yield();

void GetTimeFormatted(char formattedTime[13]);
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 Elapsed() const {
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
};
4 changes: 2 additions & 2 deletions Core/HW/Atrac3Standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Atrac3Audio : public AudioDecoder {
if (at3pCtx_) {
codecOpen_ = true;
} else {
ERROR_LOG(ME, "Failed to open atrac3+ context! (channels=%d blockAlign=%d ed=%d)", channels, blockAlign, extraDataSize);
ERROR_LOG(ME, "Failed to open atrac3+ context! (channels=%d blockAlign=%d ed=%d)", channels, (int)blockAlign, (int)extraDataSize);
}
} else if (audioType_ == PSP_CODEC_AT3) {
at3Ctx_ = atrac3_alloc(channels, &blockAlign_, extraData, (int)extraDataSize);
if (at3Ctx_) {
codecOpen_ = true;
} else {
ERROR_LOG(ME, "Failed to open atrac3 context! !channels=%d blockAlign=%d ed=%d)", channels, blockAlign, extraDataSize);
ERROR_LOG(ME, "Failed to open atrac3 context! !channels=%d blockAlign=%d ed=%d)", channels, (int)blockAlign, (int)extraDataSize);
}
}
for (int i = 0; i < 2; i++) {
Expand Down
Loading
Loading