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