summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-27 09:39:43 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-27 09:39:43 +0200
commit9b7e1eb287f8aa6c807303bf221e5498c8964960 (patch)
treee0c2cb678a0eadf5173898211d8b16b85fcc54f1
parentc4525289527bdf4c7254566eab55649899bf0a69 (diff)
downloadserenity-9b7e1eb287f8aa6c807303bf221e5498c8964960.zip
ProcessManager: Add a process-specific tab view below the process table.
To start out, add a "Stacks" view where we see what the selected process is currently doing (via /proc/PID/stack) :^)
-rw-r--r--Applications/ProcessManager/Makefile1
-rw-r--r--Applications/ProcessManager/ProcessStacksWidget.cpp38
-rw-r--r--Applications/ProcessManager/ProcessStacksWidget.h21
-rw-r--r--Applications/ProcessManager/main.cpp14
4 files changed, 73 insertions, 1 deletions
diff --git a/Applications/ProcessManager/Makefile b/Applications/ProcessManager/Makefile
index e5456fd82a..200c2f123e 100644
--- a/Applications/ProcessManager/Makefile
+++ b/Applications/ProcessManager/Makefile
@@ -5,6 +5,7 @@ OBJS = \
ProcessTableView.o \
MemoryStatsWidget.o \
GraphWidget.o \
+ ProcessStacksWidget.o \
main.o
APP = ProcessManager
diff --git a/Applications/ProcessManager/ProcessStacksWidget.cpp b/Applications/ProcessManager/ProcessStacksWidget.cpp
new file mode 100644
index 0000000000..4ebc0f09f8
--- /dev/null
+++ b/Applications/ProcessManager/ProcessStacksWidget.cpp
@@ -0,0 +1,38 @@
+#include "ProcessStacksWidget.h"
+#include <LibCore/CFile.h>
+#include <LibCore/CTimer.h>
+#include <LibGUI/GBoxLayout.h>
+
+ProcessStacksWidget::ProcessStacksWidget(GWidget* parent)
+ : GWidget(parent)
+{
+ set_layout(make<GBoxLayout>(Orientation::Vertical));
+ layout()->set_margins({ 4, 4, 4, 4 });
+ m_stacks_editor = new GTextEditor(GTextEditor::Type::MultiLine, this);
+ m_stacks_editor->set_readonly(true);
+
+ m_timer = new CTimer(1000, [this] { refresh(); });
+}
+
+ProcessStacksWidget::~ProcessStacksWidget()
+{
+}
+
+void ProcessStacksWidget::set_pid(pid_t pid)
+{
+ if (m_pid == pid)
+ return;
+ m_pid = pid;
+ refresh();
+}
+
+void ProcessStacksWidget::refresh()
+{
+ CFile file(String::format("/proc/%d/stack", m_pid));
+ if (!file.open(CIODevice::ReadOnly)) {
+ m_stacks_editor->set_text(String::format("Unable to open %s", file.filename().characters()));
+ return;
+ }
+
+ m_stacks_editor->set_text(file.read_all());
+}
diff --git a/Applications/ProcessManager/ProcessStacksWidget.h b/Applications/ProcessManager/ProcessStacksWidget.h
new file mode 100644
index 0000000000..9b0c6ac8f0
--- /dev/null
+++ b/Applications/ProcessManager/ProcessStacksWidget.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <LibGUI/GTextEditor.h>
+#include <LibGUI/GWidget.h>
+
+class CTimer;
+
+class ProcessStacksWidget final : public GWidget {
+ C_OBJECT(ProcessStacksWidget)
+public:
+ explicit ProcessStacksWidget(GWidget* parent);
+ virtual ~ProcessStacksWidget() override;
+
+ void set_pid(pid_t);
+ void refresh();
+
+private:
+ pid_t m_pid { -1 };
+ GTextEditor* m_stacks_editor { nullptr };
+ CTimer* m_timer { nullptr };
+};
diff --git a/Applications/ProcessManager/main.cpp b/Applications/ProcessManager/main.cpp
index c89af4dae5..f5efa1bce6 100644
--- a/Applications/ProcessManager/main.cpp
+++ b/Applications/ProcessManager/main.cpp
@@ -1,5 +1,6 @@
#include "GraphWidget.h"
#include "MemoryStatsWidget.h"
+#include "ProcessStacksWidget.h"
#include "ProcessTableView.h"
#include <LibCore/CTimer.h>
#include <LibGUI/GAction.h>
@@ -8,6 +9,7 @@
#include <LibGUI/GGroupBox.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GMenuBar.h>
+#include <LibGUI/GSplitter.h>
#include <LibGUI/GTabWidget.h>
#include <LibGUI/GToolBar.h>
#include <LibGUI/GWidget.h>
@@ -26,7 +28,9 @@ int main(int argc, char** argv)
keeper->set_background_color(Color::WarmGray);
keeper->layout()->set_margins({ 4, 4, 4, 4 });
- auto* tabwidget = new GTabWidget(keeper);
+ auto* splitter = new GSplitter(Orientation::Vertical, keeper);
+
+ auto* tabwidget = new GTabWidget(splitter);
auto* process_table_container = new GWidget(nullptr);
tabwidget->add_widget("Processes", process_table_container);
@@ -149,6 +153,14 @@ int main(int argc, char** argv)
app.set_menubar(move(menubar));
+ auto* process_tab_widget = new GTabWidget(splitter);
+ auto* stacks_widget = new ProcessStacksWidget(nullptr);
+ process_tab_widget->add_widget("Stacks", stacks_widget);
+
+ process_table_view->on_process_selected = [&](pid_t pid) {
+ stacks_widget->set_pid(pid);
+ };
+
auto* window = new GWindow;
window->set_title("Process Manager");
window->set_rect(20, 200, 680, 400);