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
|
|
|
{
|
2023-02-16 21:07:06 +00:00
|
|
|
set_layout<GUI::VerticalBoxLayout>(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;
|
2023-05-14 19:38:08 +02:00
|
|
|
pid_fds_fields.empend("fd", "FD"_short_string, Gfx::TextAlignment::CenterRight);
|
|
|
|
|
pid_fds_fields.empend("class", "Class"_short_string, Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
pid_fds_fields.empend("offset", "Offset"_short_string, Gfx::TextAlignment::CenterRight);
|
|
|
|
|
pid_fds_fields.empend("absolute_path", "Path"_short_string, Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
pid_fds_fields.empend("Access"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-12-21 20:26:11 +00:00
|
|
|
return object.get_bool("seekable"sv).value_or(false) ? "Seekable" : "Sequential";
|
2019-08-10 11:07:55 +02:00
|
|
|
});
|
2023-05-14 19:38:08 +02:00
|
|
|
pid_fds_fields.empend("Blocking"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-12-21 20:26:11 +00:00
|
|
|
return object.get_bool("blocking"sv).value_or(false) ? "Blocking" : "Nonblocking";
|
2019-09-28 23:01:10 +03:00
|
|
|
});
|
2023-05-14 19:38:08 +02:00
|
|
|
pid_fds_fields.empend("On exec"_short_string, Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-12-21 20:26:11 +00:00
|
|
|
return object.get_bool("cloexec"sv).value_or(false) ? "Close" : "Keep";
|
2019-09-28 23:01:10 +03:00
|
|
|
});
|
2023-05-14 19:38:08 +02:00
|
|
|
pid_fds_fields.empend("Can read"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-12-21 20:26:11 +00:00
|
|
|
return object.get_bool("can_read"sv).value_or(false) ? "Yes" : "No";
|
2019-11-09 22:15:35 +01:00
|
|
|
});
|
2023-05-14 19:38:08 +02:00
|
|
|
pid_fds_fields.empend("Can write"_string.release_value_but_fixme_should_propagate_errors(), Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2022-12-21 20:26:11 +00:00
|
|
|
return object.get_bool("can_write"sv).value_or(false) ? "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
|
|
|
|
|
|
|
|
}
|