ladybird/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

63 lines
1.4 KiB
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ThreadStackWidget.h"
#include <AK/ByteBuffer.h>
#include <LibCore/File.h>
#include <LibCore/Timer.h>
#include <LibGUI/BoxLayout.h>
#include <LibSymbolClient/Client.h>
ThreadStackWidget::ThreadStackWidget()
{
set_layout<GUI::VerticalBoxLayout>();
layout()->set_margins({ 4, 4, 4, 4 });
m_stack_editor = add<GUI::TextEditor>();
m_stack_editor->set_mode(GUI::TextEditor::ReadOnly);
}
ThreadStackWidget::~ThreadStackWidget()
{
}
void ThreadStackWidget::show_event(GUI::ShowEvent&)
{
refresh();
if (!m_timer)
m_timer = add<Core::Timer>(1000, [this] { refresh(); });
}
void ThreadStackWidget::hide_event(GUI::HideEvent&)
{
m_timer = nullptr;
}
void ThreadStackWidget::set_ids(pid_t pid, pid_t tid)
{
if (m_pid == pid && m_tid == tid)
return;
m_pid = pid;
m_tid = tid;
}
void ThreadStackWidget::refresh()
{
auto symbols = SymbolClient::symbolicate_thread(m_pid, m_tid);
StringBuilder builder;
for (auto& symbol : symbols) {
builder.appendff("{:p}", symbol.address);
if (!symbol.name.is_empty())
builder.appendff(" {}", symbol.name);
builder.append('\n');
}
if (m_stack_editor->text() != builder.string_view()) {
m_stack_editor->set_text(builder.string_view());
}
}