2019-07-28 07:15:24 -03:00
|
|
|
#include "ProcessMemoryMapWidget.h"
|
2019-12-02 13:36:10 -03:00
|
|
|
#include <LibCore/CTimer.h>
|
2019-07-28 07:15:24 -03:00
|
|
|
#include <LibGUI/GBoxLayout.h>
|
2019-08-10 11:08:51 -03:00
|
|
|
#include <LibGUI/GJsonArrayModel.h>
|
2019-12-02 13:43:34 -03:00
|
|
|
#include <LibGUI/GSortingProxyModel.h>
|
2019-07-28 07:15:24 -03:00
|
|
|
#include <LibGUI/GTableView.h>
|
|
|
|
|
|
|
|
|
|
ProcessMemoryMapWidget::ProcessMemoryMapWidget(GWidget* parent)
|
|
|
|
|
: GWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
set_layout(make<GBoxLayout>(Orientation::Vertical));
|
|
|
|
|
layout()->set_margins({ 4, 4, 4, 4 });
|
2019-09-21 11:03:59 -03:00
|
|
|
m_table_view = GTableView::construct(this);
|
2019-08-09 14:32:09 -03:00
|
|
|
m_table_view->set_size_columns_to_fit_content(true);
|
2019-08-10 11:08:51 -03:00
|
|
|
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);
|
2019-12-29 08:28:32 -03:00
|
|
|
pid_vm_fields.empend("amount_dirty", "Dirty", TextAlignment::CenterRight);
|
2019-08-10 11:08:51 -03:00
|
|
|
pid_vm_fields.empend("Access", TextAlignment::CenterLeft, [](auto& object) {
|
|
|
|
|
StringBuilder builder;
|
2019-12-15 16:11:57 -03:00
|
|
|
if (!object.get("user_accessible").to_bool())
|
|
|
|
|
builder.append('K');
|
2019-08-10 11:08:51 -03:00
|
|
|
if (object.get("readable").to_bool())
|
|
|
|
|
builder.append('R');
|
|
|
|
|
if (object.get("writable").to_bool())
|
|
|
|
|
builder.append('W');
|
2019-12-21 12:26:42 -03:00
|
|
|
if (object.get("executable").to_bool())
|
|
|
|
|
builder.append('X');
|
2019-11-17 08:14:13 -03:00
|
|
|
if (object.get("shared").to_bool())
|
|
|
|
|
builder.append('S');
|
|
|
|
|
if (object.get("stack").to_bool())
|
|
|
|
|
builder.append('T');
|
2019-08-10 11:08:51 -03:00
|
|
|
return builder.to_string();
|
|
|
|
|
});
|
2019-12-09 15:16:58 -03:00
|
|
|
pid_vm_fields.empend("Purgeable", TextAlignment::CenterLeft, [](auto& object) {
|
|
|
|
|
if (!object.get("purgeable").to_bool())
|
|
|
|
|
return "";
|
|
|
|
|
if (object.get("volatile").to_bool())
|
|
|
|
|
return "Volatile";
|
|
|
|
|
return "Non-volatile";
|
|
|
|
|
});
|
2019-12-15 12:53:00 -03:00
|
|
|
pid_vm_fields.empend("cow_pages", "# CoW", TextAlignment::CenterRight);
|
2019-08-10 11:08:51 -03:00
|
|
|
pid_vm_fields.empend("name", "Name", TextAlignment::CenterLeft);
|
2019-12-02 13:43:34 -03:00
|
|
|
m_json_model = GJsonArrayModel::create({}, move(pid_vm_fields));
|
|
|
|
|
m_table_view->set_model(GSortingProxyModel::create(*m_json_model));
|
|
|
|
|
m_table_view->model()->set_key_column_and_sort_order(0, GSortOrder::Ascending);
|
2019-12-02 13:36:10 -03:00
|
|
|
m_timer = CTimer::construct(1000, [this] { refresh(); }, this);
|
2019-07-28 07:15:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessMemoryMapWidget::~ProcessMemoryMapWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessMemoryMapWidget::set_pid(pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
if (m_pid == pid)
|
|
|
|
|
return;
|
|
|
|
|
m_pid = pid;
|
2019-12-02 13:43:34 -03:00
|
|
|
m_json_model->set_json_path(String::format("/proc/%d/vm", pid));
|
2019-07-28 07:15:24 -03:00
|
|
|
}
|
2019-12-02 13:36:10 -03:00
|
|
|
|
|
|
|
|
void ProcessMemoryMapWidget::refresh()
|
|
|
|
|
{
|
|
|
|
|
if (m_pid != -1)
|
2019-12-02 13:43:34 -03:00
|
|
|
m_json_model->update();
|
2019-12-02 13:36:10 -03:00
|
|
|
}
|