mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 03:16:54 +02:00
feat: add an in-game performance panel (#1090)
Add in-game performance panel Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
committed by
GitHub
parent
415387f00d
commit
6aa3846fb2
@@ -4,6 +4,7 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/common.h"
|
||||
#include "common/dateTime.h"
|
||||
#include "common/debugCounters.h"
|
||||
#include "common/emulatorConfig.h"
|
||||
#include "common/file.h"
|
||||
#include "common/hash.h"
|
||||
@@ -669,6 +670,7 @@ int64_t KYTY_SYSV_ABI KernelRead(int d, void* buf, size_t nbytes) {
|
||||
std::min<uint64_t>(nbytes, remaining));
|
||||
uint32_t bytes_read = 0;
|
||||
file->f.Read(buf, static_cast<uint32_t>(nbytes), &bytes_read);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileReadBytes, bytes_read);
|
||||
|
||||
file->mutex.Unlock();
|
||||
|
||||
@@ -731,6 +733,7 @@ int64_t KYTY_SYSV_ABI KernelWrite(int d, const void* buf, size_t nbytes) {
|
||||
file->f.Seek(file->f.Size());
|
||||
}
|
||||
file->f.Write(buf, static_cast<uint32_t>(nbytes), &bytes_written);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileWriteBytes, bytes_written);
|
||||
if (file->sync_writes) {
|
||||
file->f.Flush();
|
||||
}
|
||||
@@ -795,6 +798,7 @@ int64_t KYTY_SYSV_ABI KernelPread(int d, void* buf, size_t nbytes, int64_t offse
|
||||
uint32_t bytes_read = 0;
|
||||
file->f.Seek(offset);
|
||||
file->f.Read(buf, static_cast<uint32_t>(nbytes), &bytes_read);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileReadBytes, bytes_read);
|
||||
file->f.Seek(pos);
|
||||
|
||||
file->mutex.Unlock();
|
||||
@@ -896,6 +900,7 @@ int64_t KYTY_SYSV_ABI KernelPreadv(int d, const KernelIovec* iov, int iovcnt, in
|
||||
Memory::InvalidateMemory(reinterpret_cast<uint64_t>(buffer.iov_base), count);
|
||||
uint32_t bytes = 0;
|
||||
file->f.Read(buffer.iov_base, count, &bytes);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileReadBytes, bytes);
|
||||
bytes_read += bytes;
|
||||
remaining -= bytes;
|
||||
if (bytes < count) {
|
||||
@@ -945,6 +950,7 @@ int64_t KYTY_SYSV_ABI KernelPwrite(int d, const void* buf, size_t nbytes, int64_
|
||||
uint32_t bytes_written = 0;
|
||||
file->f.Seek(file->append ? file->f.Size() : static_cast<uint64_t>(offset));
|
||||
file->f.Write(buf, static_cast<uint32_t>(nbytes), &bytes_written);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileWriteBytes, bytes_written);
|
||||
if (file->sync_writes) {
|
||||
file->f.Flush();
|
||||
}
|
||||
@@ -1016,6 +1022,7 @@ static int64_t Writev(int d, const KernelIovec* iov, int iovcnt, std::optional<i
|
||||
}
|
||||
uint32_t bytes = 0;
|
||||
file->f.Write(buffer.iov_base, static_cast<uint32_t>(buffer.iov_len), &bytes);
|
||||
Common::DebugCounters::Add(Common::DebugCounters::Counter::GuestFileWriteBytes, bytes);
|
||||
bytes_written += bytes;
|
||||
if (bytes < buffer.iov_len) {
|
||||
break;
|
||||
|
||||
@@ -4414,4 +4414,39 @@ int KYTY_SYSV_ABI KernelMemoryPoolGetBlockStats(KernelMemoryPoolBlockStats* outp
|
||||
return OK;
|
||||
}
|
||||
|
||||
DebugStats GetDebugStats() {
|
||||
DebugStats stats;
|
||||
stats.direct_total = PhysicalMemory::Size();
|
||||
stats.flexible_total = FlexibleMemory::Size();
|
||||
stats.pool_committed = g_memory_pool_committed.load(std::memory_order_relaxed);
|
||||
stats.page_entries_total = PAGE_TABLE_POOL_ENTRIES;
|
||||
if (g_physical_memory != nullptr) {
|
||||
Common::LockGuard lock(g_physical_memory->GetMutex());
|
||||
for (const auto& [start, block]: g_physical_memory->GetPhysicalBlocks()) {
|
||||
switch (block.kind) {
|
||||
case PhysicalMemory::AllocationKind::Direct:
|
||||
stats.direct_allocated += block.size;
|
||||
break;
|
||||
case PhysicalMemory::AllocationKind::Pooled:
|
||||
stats.pooled_allocated += block.size;
|
||||
break;
|
||||
case PhysicalMemory::AllocationKind::Automatic:
|
||||
stats.automatic_allocated += block.size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (const auto& mapping: g_physical_memory->GetMappings()) {
|
||||
stats.direct_mapped += mapping.map_size;
|
||||
}
|
||||
}
|
||||
if (g_flexible_memory != nullptr) {
|
||||
stats.flexible_used = stats.flexible_total - g_flexible_memory->Available();
|
||||
}
|
||||
if (g_virtual_ranges != nullptr) {
|
||||
stats.cpu_page_entries = g_virtual_ranges->CountPageTableEntries(false);
|
||||
stats.gpu_page_entries = g_virtual_ranges->CountPageTableEntries(true);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
} // namespace Libs::LibKernel::Memory
|
||||
|
||||
@@ -15,6 +15,23 @@ namespace Libs::LibKernel::Memory {
|
||||
void Initialize();
|
||||
void Shutdown();
|
||||
|
||||
// Guest memory usage for the performance panel. Takes only bookkeeping locks, so it never
|
||||
// waits on the GPU; call it only while the memory subsystem is initialized.
|
||||
struct DebugStats {
|
||||
uint64_t direct_total = 0;
|
||||
uint64_t direct_allocated = 0; // sceKernelAllocateDirectMemory.
|
||||
uint64_t pooled_allocated = 0; // Memory pool expansions.
|
||||
uint64_t automatic_allocated = 0; // Extended memory.
|
||||
uint64_t direct_mapped = 0;
|
||||
uint64_t flexible_total = 0;
|
||||
uint64_t flexible_used = 0;
|
||||
uint64_t pool_committed = 0;
|
||||
uint64_t cpu_page_entries = 0; // 2 MiB page-table entries in use.
|
||||
uint64_t gpu_page_entries = 0;
|
||||
uint64_t page_entries_total = 0; // Per side.
|
||||
};
|
||||
[[nodiscard]] DebugStats GetDebugStats();
|
||||
|
||||
struct Lifecycle {
|
||||
static constexpr const char* name = "Memory";
|
||||
static constexpr auto initialize = Libs::LibKernel::Memory::Initialize;
|
||||
|
||||
Reference in New Issue
Block a user