rpcsx/rpcs3/Gui/KernelExplorer.cpp

254 lines
7.2 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "stdafx_gui.h"
2014-07-26 07:51:45 +02:00
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
2014-08-26 01:55:37 +02:00
#include "Emu/IdManager.h"
2015-07-08 17:01:59 +02:00
#include "Emu/Cell/PPUThread.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/RawSPUThread.h"
2016-02-01 22:46:27 +01:00
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "Emu/Cell/lv2/sys_cond.h"
#include "Emu/Cell/lv2/sys_semaphore.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/lv2/sys_event_flag.h"
#include "Emu/Cell/lv2/sys_rwlock.h"
#include "Emu/Cell/lv2/sys_prx.h"
#include "Emu/Cell/lv2/sys_memory.h"
#include "Emu/Cell/lv2/sys_mmapper.h"
#include "Emu/Cell/lv2/sys_spu.h"
2015-04-14 04:00:31 +02:00
2014-12-24 17:09:32 +01:00
#include "KernelExplorer.h"
2014-07-26 07:51:45 +02:00
KernelExplorer::KernelExplorer(wxWindow* parent)
2015-11-26 08:37:53 +01:00
: wxDialog(parent, wxID_ANY, "Kernel Explorer", wxDefaultPosition, wxSize(700, 450))
2014-07-26 07:51:45 +02:00
{
this->SetBackgroundColour(wxColour(240,240,240)); //This fix the ugly background color under Windows
wxBoxSizer* s_panel = new wxBoxSizer(wxVERTICAL);
// Buttons
wxBoxSizer* box_buttons = new wxBoxSizer(wxHORIZONTAL);
wxButton* b_refresh = new wxButton(this, wxID_ANY, "Refresh");
box_buttons->AddSpacer(10);
box_buttons->Add(b_refresh);
box_buttons->AddSpacer(10);
wxStaticBoxSizer* box_tree = new wxStaticBoxSizer(wxHORIZONTAL, this, "Kernel");
m_tree = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(600,300));
box_tree->Add(m_tree);
// Merge and display everything
s_panel->AddSpacer(10);
s_panel->Add(box_buttons);
s_panel->AddSpacer(10);
s_panel->Add(box_tree, 0, 0, 100);
s_panel->AddSpacer(10);
SetSizerAndFit(s_panel);
// Events
b_refresh->Bind(wxEVT_BUTTON, &KernelExplorer::OnRefresh, this);
// Fill the wxTreeCtrl
Update();
};
void KernelExplorer::Update()
{
m_tree->DeleteAllItems();
2015-07-11 22:44:53 +02:00
const u32 total_memory_usage = vm::get(vm::user_space)->used.load();
2014-09-13 22:40:12 +02:00
2015-08-08 19:59:10 +02:00
const auto& root = m_tree->AddRoot(fmt::format("Process, ID = 0x00000001, Total Memory Usage = 0x%x (%0.2f MB)", total_memory_usage, (float)total_memory_usage / (1024 * 1024)));
2014-07-26 07:51:45 +02:00
2015-04-14 04:00:31 +02:00
union name64
{
u64 u64_data;
char string[8];
name64(u64 data)
: u64_data(data & 0x00ffffffffffffffull)
{
}
const char* operator &() const
{
return string;
}
};
2014-07-26 07:51:45 +02:00
// TODO: FileSystem
// Semaphores
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_sema_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Semaphores (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_sema_t>([&](u32 id, lv2_sema_t& sema)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Semaphore: ID = 0x%08x '%s', Count = %d, Max Count = %d, Waiters = %#zu", id,
2015-08-08 19:59:10 +02:00
&name64(sema.name), sema.value.load(), sema.max, sema.sq.size()));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
// Mutexes
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_mutex_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Mutexes (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_mutex_t>([&](u32 id, lv2_mutex_t& mutex)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Mutex: ID = 0x%08x '%s'", id,
2015-08-08 19:59:10 +02:00
&name64(mutex.name)));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
2015-08-08 19:59:10 +02:00
// Lightweight Mutexes
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_lwmutex_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Lightweight Mutexes (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_lwmutex_t>([&](u32 id, lv2_lwmutex_t& lwm)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("LWMutex: ID = 0x%08x '%s'", id,
2015-08-08 19:59:10 +02:00
&name64(lwm.name)));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
// Condition Variables
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_cond_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Condition Variables (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_cond_t>([&](u32 id, lv2_cond_t& cond)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Cond: ID = 0x%08x '%s'", id,
2015-08-08 19:59:10 +02:00
&name64(cond.name)));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
2015-08-08 19:59:10 +02:00
// Lightweight Condition Variables
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_lwcond_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Lightweight Condition Variables (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_lwcond_t>([&](u32 id, lv2_lwcond_t& lwc)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("LWCond: ID = 0x%08x '%s'", id,
2015-08-08 19:59:10 +02:00
&name64(lwc.name)));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
// Event Queues
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_event_queue_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Event Queues (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_event_queue_t>([&](u32 id, lv2_event_queue_t& eq)
2015-04-14 04:00:31 +02:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Event Queue: ID = 0x%08x '%s', %s, Key = %#llx, Events = %zu/%d, Waiters = %zu", id,
2016-02-01 22:46:27 +01:00
&name64(eq.name), eq.type == SYS_SPU_QUEUE ? "SPU" : "PPU", eq.ipc_key, eq.events(), eq.size, eq.waiters()));
2016-05-13 16:01:48 +02:00
});
2015-04-14 04:00:31 +02:00
}
// Event Ports
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_event_port_t>())
2015-04-14 04:00:31 +02:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Event Ports (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_event_port_t>([&](u32 id, lv2_event_port_t& ep)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Event Port: ID = 0x%08x, Name = %#llx", id,
2015-08-08 19:59:10 +02:00
ep.name));
2016-05-13 16:01:48 +02:00
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
2015-08-08 19:59:10 +02:00
// Event Flags
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_event_flag_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Event Flags (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_event_flag_t>([&](u32 id, lv2_event_flag_t& ef)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Event Flag: ID = 0x%08x '%s', Type = 0x%x, Pattern = 0x%llx", id,
&name64(ef.name), ef.type, ef.pattern.load()));
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
2015-08-08 19:59:10 +02:00
// Reader/writer Locks
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_rwlock_t>())
2015-08-08 19:59:10 +02:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Reader/writer Locks (%zu)", count));
2015-08-08 19:59:10 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_rwlock_t>([&](u32 id, lv2_rwlock_t&)
2015-08-08 19:59:10 +02:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("RWLock: ID = 0x%08x", id));
});
2015-08-08 19:59:10 +02:00
}
// PRX Libraries
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_prx_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("PRX Libraries (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_prx_t>([&](u32 id, lv2_prx_t&)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("PRX: ID = 0x%08x", id));
});
2014-12-24 17:09:32 +01:00
}
2014-09-13 22:40:12 +02:00
2015-08-08 19:59:10 +02:00
// Memory Containers
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_memory_container_t>())
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Memory Containers (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_memory_container_t>([&](u32 id, lv2_memory_container_t&)
2014-12-24 17:09:32 +01:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Memory Container: ID = 0x%08x", id));
});
2014-12-24 17:09:32 +01:00
}
2014-07-26 07:51:45 +02:00
2015-08-08 19:59:10 +02:00
// Memory Objects
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_memory_t>())
2015-07-08 17:01:59 +02:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("Memory Objects (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<lv2_memory_t>([&](u32 id, lv2_memory_t&)
2015-07-08 17:01:59 +02:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("Memory Object: ID = 0x%08x", id));
});
2015-07-08 17:01:59 +02:00
}
2015-08-08 19:59:10 +02:00
// PPU Threads
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<PPUThread>())
2015-07-08 17:01:59 +02:00
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("PPU Threads (%zu)", count));
2015-07-08 17:01:59 +02:00
2016-05-13 16:01:48 +02:00
idm::select<PPUThread>([&](u32 id, PPUThread& ppu)
2015-07-08 17:01:59 +02:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("PPU Thread: ID = 0x%08x '%s'", id, ppu.get_name()));
});
2015-07-08 17:01:59 +02:00
}
2015-08-08 19:59:10 +02:00
// SPU Thread Groups
2016-05-13 16:01:48 +02:00
if (const u32 count = idm::get_count<lv2_spu_group_t>())
{
2016-05-13 16:01:48 +02:00
const auto& node = m_tree->AppendItem(root, fmt::format("SPU Thread Groups (%d)", count));
2016-05-13 16:01:48 +02:00
idm::select<lv2_spu_group_t>([&](u32 id, lv2_spu_group_t& tg)
2015-07-08 17:01:59 +02:00
{
2016-05-13 16:01:48 +02:00
m_tree->AppendItem(node, fmt::format("SPU Thread Group: ID = 0x%08x '%s'", id,
2015-08-08 19:59:10 +02:00
tg.name.c_str()));
2016-05-13 16:01:48 +02:00
});
}
2015-08-08 19:59:10 +02:00
// RawSPU Threads (TODO)
2014-07-26 07:51:45 +02:00
m_tree->Expand(root);
}
void KernelExplorer::OnRefresh(wxCommandEvent& WXUNUSED(event))
{
Update();
}