2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-10 12:28:48 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-08-03 08:26:04 +02:00
|
|
|
#include "ProcessFileDescriptorMapWidget.h"
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/JsonArrayModel.h>
|
2020-09-22 00:40:57 +02:00
|
|
|
#include <LibGUI/SortingProxyModel.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/TableView.h>
|
2019-08-03 08:26:04 +02:00
|
|
|
|
2022-03-24 13:30:52 +01:00
|
|
|
REGISTER_WIDGET(SystemMonitor, ProcessFileDescriptorMapWidget)
|
|
|
|
|
|
|
|
namespace SystemMonitor {
|
|
|
|
|
2020-02-23 12:07:13 +01:00
|
|
|
ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget()
|
2019-08-03 08:26:04 +02:00
|
|
|
{
|
2020-03-04 09:43:54 +01:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-17 00:11:38 +00:00
|
|
|
layout()->set_margins(4);
|
2020-02-23 12:07:13 +01:00
|
|
|
m_table_view = add<GUI::TableView>();
|
2019-08-10 11:07:55 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields;
|
2020-02-06 11:56:38 +01:00
|
|
|
pid_fds_fields.empend("fd", "FD", Gfx::TextAlignment::CenterRight);
|
|
|
|
pid_fds_fields.empend("class", "Class", Gfx::TextAlignment::CenterLeft);
|
|
|
|
pid_fds_fields.empend("offset", "Offset", Gfx::TextAlignment::CenterRight);
|
|
|
|
pid_fds_fields.empend("absolute_path", "Path", Gfx::TextAlignment::CenterLeft);
|
|
|
|
pid_fds_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return object.get("seekable"sv).to_bool() ? "Seekable" : "Sequential";
|
2019-08-10 11:07:55 +02:00
|
|
|
});
|
2020-02-06 11:56:38 +01:00
|
|
|
pid_fds_fields.empend("Blocking", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return object.get("blocking"sv).to_bool() ? "Blocking" : "Nonblocking";
|
2019-09-28 23:01:10 +03:00
|
|
|
});
|
2020-02-06 11:56:38 +01:00
|
|
|
pid_fds_fields.empend("On exec", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return object.get("cloexec"sv).to_bool() ? "Close" : "Keep";
|
2019-09-28 23:01:10 +03:00
|
|
|
});
|
2020-02-06 11:56:38 +01:00
|
|
|
pid_fds_fields.empend("Can read", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return object.get("can_read"sv).to_bool() ? "Yes" : "No";
|
2019-11-09 22:15:35 +01:00
|
|
|
});
|
2020-02-06 11:56:38 +01:00
|
|
|
pid_fds_fields.empend("Can write", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return object.get("can_write"sv).to_bool() ? "Yes" : "No";
|
2019-11-09 22:15:35 +01:00
|
|
|
});
|
2019-08-10 11:07:55 +02:00
|
|
|
|
2020-09-22 00:40:57 +02:00
|
|
|
m_model = GUI::JsonArrayModel::create({}, move(pid_fds_fields));
|
2021-12-24 12:12:04 +00:00
|
|
|
m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model)));
|
2019-08-03 08:26:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessFileDescriptorMapWidget::set_pid(pid_t pid)
|
|
|
|
{
|
|
|
|
if (m_pid == pid)
|
|
|
|
return;
|
|
|
|
m_pid = pid;
|
2022-12-04 18:02:33 +00:00
|
|
|
m_model->set_json_path(DeprecatedString::formatted("/proc/{}/fds", m_pid));
|
2019-08-03 08:26:04 +02:00
|
|
|
}
|
2022-03-24 13:30:52 +01:00
|
|
|
|
|
|
|
}
|