2020-02-22 18:52:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2022-11-18 21:07:57 +00:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2020-02-22 18:52:54 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-22 18:52:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/JsonArray.h>
|
|
|
|
#include <AK/JsonObject.h>
|
2023-02-09 02:02:46 +00:00
|
|
|
#include <LibCore/File.h>
|
2022-01-20 14:42:33 +00:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2020-02-22 18:52:54 +00:00
|
|
|
|
2022-01-20 14:42:33 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2020-02-22 18:52:54 +00:00
|
|
|
{
|
2022-01-20 14:42:33 +00:00
|
|
|
TRY(Core::System::pledge("stdio rpath"));
|
2022-10-14 18:56:19 +00:00
|
|
|
TRY(Core::System::unveil("/sys/kernel/interrupts", "r"));
|
2022-01-20 14:42:33 +00:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-02-22 18:52:54 +00:00
|
|
|
|
2023-02-09 02:02:46 +00:00
|
|
|
auto proc_interrupts = TRY(Core::File::open("/sys/kernel/interrupts"sv, Core::File::OpenMode::Read));
|
2020-02-22 18:52:54 +00:00
|
|
|
|
2022-01-20 14:42:33 +00:00
|
|
|
TRY(Core::System::pledge("stdio"));
|
2020-02-22 18:52:54 +00:00
|
|
|
|
2022-12-11 16:49:00 +00:00
|
|
|
auto file_contents = TRY(proc_interrupts->read_until_eof());
|
2022-01-20 14:42:33 +00:00
|
|
|
auto json = TRY(JsonValue::from_string(file_contents));
|
2022-11-18 21:07:57 +00:00
|
|
|
|
2022-12-22 14:28:07 +00:00
|
|
|
auto cpu_count = json.as_array().at(0).as_object().get_array("per_cpu_call_counts"sv)->size();
|
2022-11-18 21:07:57 +00:00
|
|
|
|
|
|
|
out(" "sv);
|
|
|
|
for (size_t i = 0; i < cpu_count; ++i) {
|
2022-12-04 18:02:33 +00:00
|
|
|
out("{:>10}", DeprecatedString::formatted("CPU{}", i));
|
2022-11-18 21:07:57 +00:00
|
|
|
}
|
|
|
|
outln("");
|
|
|
|
|
|
|
|
json.as_array().for_each([cpu_count](JsonValue const& value) {
|
2021-05-31 16:59:02 +00:00
|
|
|
auto& handler = value.as_object();
|
2022-12-22 14:28:07 +00:00
|
|
|
auto purpose = handler.get_deprecated_string("purpose"sv).value_or({});
|
|
|
|
auto interrupt = handler.get_deprecated_string("interrupt_line"sv).value_or({});
|
|
|
|
auto controller = handler.get_deprecated_string("controller"sv).value_or({});
|
|
|
|
auto call_counts = handler.get_array("per_cpu_call_counts"sv).value();
|
2022-11-18 21:07:57 +00:00
|
|
|
|
|
|
|
out("{:>4}: ", interrupt);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < cpu_count; ++i)
|
2022-12-06 01:12:49 +00:00
|
|
|
out("{:>10}", call_counts[i].to_deprecated_string());
|
2020-02-22 18:52:54 +00:00
|
|
|
|
2022-11-18 21:07:57 +00:00
|
|
|
outln(" {:10} {:30}", controller, purpose);
|
2020-02-22 18:52:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|