lsirq.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Assertions.h>
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/JsonArray.h>
  9. #include <AK/JsonObject.h>
  10. #include <LibCore/File.h>
  11. #include <stdio.h>
  12. #include <unistd.h>
  13. int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
  14. {
  15. if (pledge("stdio rpath", nullptr) < 0) {
  16. perror("pledge");
  17. return 1;
  18. }
  19. if (unveil("/proc/interrupts", "r") < 0) {
  20. perror("unveil");
  21. return 1;
  22. }
  23. unveil(nullptr, nullptr);
  24. auto proc_interrupts = Core::File::construct("/proc/interrupts");
  25. if (!proc_interrupts->open(Core::OpenMode::ReadOnly)) {
  26. fprintf(stderr, "Error: %s\n", proc_interrupts->error_string());
  27. return 1;
  28. }
  29. if (pledge("stdio", nullptr) < 0) {
  30. perror("pledge");
  31. return 1;
  32. }
  33. printf("%4s %-10s\n", " ", "CPU0");
  34. auto file_contents = proc_interrupts->read_all();
  35. auto json = JsonValue::from_string(file_contents);
  36. VERIFY(json.has_value());
  37. json.value().as_array().for_each([](auto& value) {
  38. auto handler = value.as_object();
  39. auto purpose = handler.get("purpose").to_string();
  40. auto interrupt = handler.get("interrupt_line").to_string();
  41. auto controller = handler.get("controller").to_string();
  42. auto call_count = handler.get("call_count").to_string();
  43. printf("%4s: %-10s %-10s %-30s\n",
  44. interrupt.characters(), call_count.characters(), controller.characters(), purpose.characters());
  45. });
  46. return 0;
  47. }