CProcessStatisticsReader.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/HashMap.h>
  28. #include <AK/String.h>
  29. #include <unistd.h>
  30. struct CThreadStatistics {
  31. int tid;
  32. unsigned times_scheduled;
  33. unsigned ticks;
  34. unsigned syscall_count;
  35. unsigned inode_faults;
  36. unsigned zero_faults;
  37. unsigned cow_faults;
  38. unsigned unix_socket_read_bytes;
  39. unsigned unix_socket_write_bytes;
  40. unsigned ipv4_socket_read_bytes;
  41. unsigned ipv4_socket_write_bytes;
  42. unsigned file_read_bytes;
  43. unsigned file_write_bytes;
  44. String state;
  45. u32 priority;
  46. u32 effective_priority;
  47. String name;
  48. };
  49. struct CProcessStatistics {
  50. // Keep this in sync with /proc/all.
  51. // From the kernel side:
  52. pid_t pid;
  53. unsigned pgid;
  54. unsigned pgp;
  55. unsigned sid;
  56. uid_t uid;
  57. gid_t gid;
  58. pid_t ppid;
  59. unsigned nfds;
  60. String name;
  61. String tty;
  62. String pledge;
  63. String veil;
  64. size_t amount_virtual;
  65. size_t amount_resident;
  66. size_t amount_shared;
  67. size_t amount_dirty_private;
  68. size_t amount_clean_inode;
  69. size_t amount_purgeable_volatile;
  70. size_t amount_purgeable_nonvolatile;
  71. int icon_id;
  72. Vector<CThreadStatistics> threads;
  73. // synthetic
  74. String username;
  75. };
  76. class CProcessStatisticsReader {
  77. public:
  78. static HashMap<pid_t, CProcessStatistics> get_all();
  79. private:
  80. static String username_from_uid(uid_t);
  81. static HashMap<uid_t, String> s_usernames;
  82. };