summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-10 16:08:51 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-10 16:08:51 +0200
commitaaccf6ee4eb616f979d50ebe6e85ef444b379ba6 (patch)
tree49eceadc57da4f82c5e82500a431156cde5ee11b /Applications
parentafd25679bc4e72db304322289af0566bde0b60b0 (diff)
downloadserenity-aaccf6ee4eb616f979d50ebe6e85ef444b379ba6.zip
ProcessManager: Use a GJsonArrayModel for the process memory maps
Diffstat (limited to 'Applications')
-rw-r--r--Applications/ProcessManager/Makefile1
-rw-r--r--Applications/ProcessManager/ProcessMemoryMapModel.cpp98
-rw-r--r--Applications/ProcessManager/ProcessMemoryMapModel.h32
-rw-r--r--Applications/ProcessManager/ProcessMemoryMapWidget.cpp21
4 files changed, 18 insertions, 134 deletions
diff --git a/Applications/ProcessManager/Makefile b/Applications/ProcessManager/Makefile
index 096d57dcbf..e91f1d3a69 100644
--- a/Applications/ProcessManager/Makefile
+++ b/Applications/ProcessManager/Makefile
@@ -7,7 +7,6 @@ OBJS = \
GraphWidget.o \
ProcessStacksWidget.o \
ProcessMemoryMapWidget.o \
- ProcessMemoryMapModel.o \
ProcessFileDescriptorMapWidget.o \
NetworkStatisticsWidget.o \
main.o
diff --git a/Applications/ProcessManager/ProcessMemoryMapModel.cpp b/Applications/ProcessManager/ProcessMemoryMapModel.cpp
deleted file mode 100644
index 8d847e8ddd..0000000000
--- a/Applications/ProcessManager/ProcessMemoryMapModel.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-#include "ProcessMemoryMapModel.h"
-#include <AK/JsonObject.h>
-#include <AK/StringBuilder.h>
-#include <LibCore/CFile.h>
-
-void ProcessMemoryMapModel::update()
-{
- CFile file(String::format("/proc/%d/vm", m_pid));
- if (!file.open(CIODevice::ReadOnly)) {
- dbg() << "Unable to open " << file.filename();
- return;
- }
-
- auto json = JsonValue::from_string(file.read_all());
-
- ASSERT(json.is_array());
- m_process_vm = json.as_array();
-
- did_update();
-}
-
-int ProcessMemoryMapModel::row_count(const GModelIndex&) const
-{
- return m_process_vm.size();
-}
-
-String ProcessMemoryMapModel::column_name(int column) const
-{
- switch (column) {
- case Column::Address:
- return "Address";
- case Column::Size:
- return "Size";
- case Column::AmountResident:
- return "Resident";
- case Column::Access:
- return "Access";
- case Column::Name:
- return "Name";
- default:
- ASSERT_NOT_REACHED();
- }
-}
-
-GModel::ColumnMetadata ProcessMemoryMapModel::column_metadata(int column) const
-{
- switch (column) {
- case Column::Address:
- return { 80 };
- case Column::Size:
- return { 60, TextAlignment::CenterRight };
- case Column::AmountResident:
- return { 60, TextAlignment::CenterRight };
- case Column::Access:
- return { 50 };
- case Column::Name:
- return { 200 };
- default:
- ASSERT_NOT_REACHED();
- }
- return {};
-}
-
-GVariant ProcessMemoryMapModel::data(const GModelIndex& index, Role role) const
-{
- auto& region_object = m_process_vm.at(index.row()).as_object();
- if (role == GModel::Role::Display) {
- switch (index.column()) {
- case Column::Address:
- return String::format("%#x", region_object.get("address").to_u32());
- case Column::Size:
- return region_object.get("size").to_int();
- case Column::AmountResident:
- return region_object.get("amount_resident").to_int();
- case Column::Access: {
- StringBuilder builder;
- if (region_object.get("readable").to_bool())
- builder.append('R');
- if (region_object.get("writable").to_bool())
- builder.append('W');
- return builder.to_string();
- }
- case Column::Name:
- return region_object.get("name").to_string();
- default:
- ASSERT_NOT_REACHED();
- }
- }
- return {};
-}
-
-void ProcessMemoryMapModel::set_pid(pid_t pid)
-{
- if (m_pid == pid)
- return;
- m_pid = pid;
- update();
-}
diff --git a/Applications/ProcessManager/ProcessMemoryMapModel.h b/Applications/ProcessManager/ProcessMemoryMapModel.h
deleted file mode 100644
index cc28aef223..0000000000
--- a/Applications/ProcessManager/ProcessMemoryMapModel.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-
-#include <AK/JsonArray.h>
-#include <LibGUI/GModel.h>
-
-class ProcessMemoryMapModel final : public GModel {
-public:
- enum Column {
- Address,
- Size,
- AmountResident,
- Access,
- Name,
- __Count
- };
-
- ProcessMemoryMapModel() {}
- virtual ~ProcessMemoryMapModel() override {}
-
- virtual int row_count(const GModelIndex& = GModelIndex()) const override;
- virtual int column_count(const GModelIndex& = GModelIndex()) const override { return Column::__Count; }
- virtual String column_name(int) const override;
- virtual ColumnMetadata column_metadata(int) const override;
- virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
- virtual void update() override;
-
- void set_pid(pid_t);
-
-private:
- JsonArray m_process_vm;
- int m_pid { -1 };
-};
diff --git a/Applications/ProcessManager/ProcessMemoryMapWidget.cpp b/Applications/ProcessManager/ProcessMemoryMapWidget.cpp
index 6e751054e2..938f8f5237 100644
--- a/Applications/ProcessManager/ProcessMemoryMapWidget.cpp
+++ b/Applications/ProcessManager/ProcessMemoryMapWidget.cpp
@@ -1,6 +1,6 @@
#include "ProcessMemoryMapWidget.h"
-#include "ProcessMemoryMapModel.h"
#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GJsonArrayModel.h>
#include <LibGUI/GTableView.h>
ProcessMemoryMapWidget::ProcessMemoryMapWidget(GWidget* parent)
@@ -10,7 +10,22 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GWidget* parent)
layout()->set_margins({ 4, 4, 4, 4 });
m_table_view = new GTableView(this);
m_table_view->set_size_columns_to_fit_content(true);
- m_table_view->set_model(adopt(*new ProcessMemoryMapModel));
+ Vector<GJsonArrayModel::FieldSpec> pid_vm_fields;
+ pid_vm_fields.empend("Address", TextAlignment::CenterLeft, [](auto& object) {
+ return String::format("%#x", object.get("address").to_u32());
+ });
+ pid_vm_fields.empend("size", "Size", TextAlignment::CenterRight);
+ pid_vm_fields.empend("amount_resident", "Resident", TextAlignment::CenterRight);
+ pid_vm_fields.empend("Access", TextAlignment::CenterLeft, [](auto& object) {
+ StringBuilder builder;
+ if (object.get("readable").to_bool())
+ builder.append('R');
+ if (object.get("writable").to_bool())
+ builder.append('W');
+ return builder.to_string();
+ });
+ pid_vm_fields.empend("name", "Name", TextAlignment::CenterLeft);
+ m_table_view->set_model(GJsonArrayModel::create({}, move(pid_vm_fields)));
}
ProcessMemoryMapWidget::~ProcessMemoryMapWidget()
@@ -22,5 +37,5 @@ void ProcessMemoryMapWidget::set_pid(pid_t pid)
if (m_pid == pid)
return;
m_pid = pid;
- static_cast<ProcessMemoryMapModel*>(m_table_view->model())->set_pid(pid);
+ static_cast<GJsonArrayModel*>(m_table_view->model())->set_json_path(String::format("/proc/%d/vm", pid));
}