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) {
|
2022-12-04 21:02:33 +03:00
|
|
|
out("{:>10}", DeprecatedString::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();
|
2022-12-22 17:28:07 +03:00
|
|
|
auto purpose = handler.get_deprecated_string("purpose"sv).value_or({});
|
2023-05-17 00:04:46 +03:00
|
|
|
auto interrupt = handler.get_u8("interrupt_line"sv).value();
|
2022-12-22 17:28:07 +03:00
|
|
|
auto controller = handler.get_deprecated_string("controller"sv).value_or({});
|
|
|
|
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)
|
2022-12-06 04:12:49 +03:00
|
|
|
out("{:>10}", call_counts[i].to_deprecated_string());
|
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;
|
|
|
|
}
|