summaryrefslogtreecommitdiff
path: root/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-12 12:05:23 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-12 12:05:23 +0100
commitdc28c07fa526841e05e16161c74a6c23984f1dd5 (patch)
treed68796bc7708eba33fbf7247e1a92188ac5acf6f /Applications/SystemMonitor/ProcessMemoryMapWidget.cpp
parentaa939c4b4b8a7eb1d22b166ebb5fb737d6e66714 (diff)
downloadserenity-dc28c07fa526841e05e16161c74a6c23984f1dd5.zip
Applications: Move to Userland/Applications/
Diffstat (limited to 'Applications/SystemMonitor/ProcessMemoryMapWidget.cpp')
-rw-r--r--Applications/SystemMonitor/ProcessMemoryMapWidget.cpp141
1 files changed, 0 insertions, 141 deletions
diff --git a/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp b/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp
deleted file mode 100644
index d36a7f57ab..0000000000
--- a/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "ProcessMemoryMapWidget.h"
-#include <LibCore/Timer.h>
-#include <LibGUI/BoxLayout.h>
-#include <LibGUI/JsonArrayModel.h>
-#include <LibGUI/Painter.h>
-#include <LibGUI/SortingProxyModel.h>
-#include <LibGUI/TableView.h>
-#include <LibGfx/Palette.h>
-
-class PagemapPaintingDelegate final : public GUI::TableCellPaintingDelegate {
-public:
- virtual ~PagemapPaintingDelegate() override { }
-
- virtual void paint(GUI::Painter& painter, const Gfx::IntRect& a_rect, const Gfx::Palette&, const GUI::ModelIndex& index) override
- {
- auto rect = a_rect.shrunken(2, 2);
- auto pagemap = index.data(GUI::ModelRole::Custom).to_string();
-
- float scale_factor = (float)pagemap.length() / (float)rect.width();
-
- for (int i = 0; i < rect.width(); ++i) {
- int x = rect.x() + i;
- char c = pagemap[(float)i * scale_factor];
- Color color;
- if (c == 'N') // Null (no page at all, typically an inode-backed page that hasn't been paged in.)
- color = Color::White;
- else if (c == 'Z') // Zero (globally shared zero page, typically an untouched anonymous page.)
- color = Color::from_rgb(0xc0c0ff);
- else if (c == 'P') // Physical (a resident page)
- color = Color::Black;
- else
- ASSERT_NOT_REACHED();
-
- painter.draw_line({ x, rect.top() }, { x, rect.bottom() }, color);
- }
-
- painter.draw_rect(rect, Color::Black);
- }
-};
-
-ProcessMemoryMapWidget::ProcessMemoryMapWidget()
-{
- set_layout<GUI::VerticalBoxLayout>();
- layout()->set_margins({ 4, 4, 4, 4 });
- m_table_view = add<GUI::TableView>();
- Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields;
- pid_vm_fields.empend(
- "Address", Gfx::TextAlignment::CenterLeft,
- [](auto& object) { return String::formatted("{:#x}", object.get("address").to_u32()); },
- [](auto& object) { return object.get("address").to_u32(); });
- pid_vm_fields.empend("size", "Size", Gfx::TextAlignment::CenterRight);
- pid_vm_fields.empend("amount_resident", "Resident", Gfx::TextAlignment::CenterRight);
- pid_vm_fields.empend("amount_dirty", "Dirty", Gfx::TextAlignment::CenterRight);
- pid_vm_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) {
- StringBuilder builder;
- if (!object.get("user_accessible").to_bool())
- builder.append('K');
- if (object.get("readable").to_bool())
- builder.append('R');
- if (object.get("writable").to_bool())
- builder.append('W');
- if (object.get("executable").to_bool())
- builder.append('X');
- if (object.get("shared").to_bool())
- builder.append('S');
- if (object.get("stack").to_bool())
- builder.append('T');
- return builder.to_string();
- });
- pid_vm_fields.empend("vmobject", "VMObject type", Gfx::TextAlignment::CenterLeft);
- pid_vm_fields.empend("Purgeable", Gfx::TextAlignment::CenterLeft, [](auto& object) {
- if (object.get("volatile").to_bool())
- return "Volatile";
- return "Non-volatile";
- });
- pid_vm_fields.empend(
- "Page map", Gfx::TextAlignment::CenterLeft,
- [](auto&) {
- return GUI::Variant();
- },
- [](auto&) {
- return GUI::Variant(0);
- },
- [](const JsonObject& object) {
- auto pagemap = object.get("pagemap").as_string_or({});
- return pagemap;
- });
- pid_vm_fields.empend("cow_pages", "# CoW", Gfx::TextAlignment::CenterRight);
- pid_vm_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft);
- m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields));
- m_table_view->set_model(GUI::SortingProxyModel::create(*m_json_model));
-
- m_table_view->set_column_painting_delegate(7, make<PagemapPaintingDelegate>());
-
- m_table_view->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending);
- m_timer = add<Core::Timer>(1000, [this] { refresh(); });
-}
-
-ProcessMemoryMapWidget::~ProcessMemoryMapWidget()
-{
-}
-
-void ProcessMemoryMapWidget::set_pid(pid_t pid)
-{
- if (m_pid == pid)
- return;
- m_pid = pid;
- m_json_model->set_json_path(String::formatted("/proc/{}/vm", pid));
-}
-
-void ProcessMemoryMapWidget::refresh()
-{
- if (m_pid != -1)
- m_json_model->update();
-}