mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:35:07 +00:00
SystemMonitor: Symbolicate process stacks in a background thread
Use a Threading::BackgroundAction to symbolicate stacks. This avoids blocking the main thread and keeps the GUI running (mostly.)
This commit is contained in:
parent
b5d73c834f
commit
9676548800
3 changed files with 34 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibSymbolication/Symbolication.h>
|
||||
#include <LibThreading/BackgroundAction.h>
|
||||
|
||||
ThreadStackWidget::ThreadStackWidget()
|
||||
{
|
||||
|
@ -16,6 +17,7 @@ ThreadStackWidget::ThreadStackWidget()
|
|||
layout()->set_margins({ 4, 4, 4, 4 });
|
||||
m_stack_editor = add<GUI::TextEditor>();
|
||||
m_stack_editor->set_mode(GUI::TextEditor::ReadOnly);
|
||||
m_stack_editor->set_text("Symbolicating...");
|
||||
}
|
||||
|
||||
ThreadStackWidget::~ThreadStackWidget()
|
||||
|
@ -42,13 +44,41 @@ void ThreadStackWidget::set_ids(pid_t pid, pid_t tid)
|
|||
m_tid = tid;
|
||||
}
|
||||
|
||||
class CompletionEvent : public Core::CustomEvent {
|
||||
public:
|
||||
explicit CompletionEvent(Vector<Symbolication::Symbol> symbols)
|
||||
: Core::CustomEvent(0)
|
||||
, m_symbols(move(symbols))
|
||||
{
|
||||
}
|
||||
|
||||
Vector<Symbolication::Symbol> const& symbols() const { return m_symbols; }
|
||||
|
||||
private:
|
||||
Vector<Symbolication::Symbol> m_symbols;
|
||||
};
|
||||
|
||||
void ThreadStackWidget::refresh()
|
||||
{
|
||||
auto symbols = Symbolication::symbolicate_thread(m_pid, m_tid);
|
||||
Threading::BackgroundAction<Vector<Symbolication::Symbol>>::create(
|
||||
[pid = m_pid, tid = m_tid] {
|
||||
return Symbolication::symbolicate_thread(pid, tid);
|
||||
},
|
||||
|
||||
[weak_this = make_weak_ptr()](auto result) {
|
||||
if (!weak_this)
|
||||
return;
|
||||
Core::EventLoop::main().post_event(const_cast<Core::Object&>(*weak_this), make<CompletionEvent>(move(result)));
|
||||
});
|
||||
}
|
||||
|
||||
void ThreadStackWidget::custom_event(Core::CustomEvent& event)
|
||||
{
|
||||
auto& completion_event = downcast<CompletionEvent>(event);
|
||||
|
||||
StringBuilder builder;
|
||||
|
||||
for (auto& symbol : symbols) {
|
||||
for (auto& symbol : completion_event.symbols()) {
|
||||
builder.appendff("{:p}", symbol.address);
|
||||
if (!symbol.name.is_empty())
|
||||
builder.appendff(" {}", symbol.name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue