NetBSDProcess.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. htop - NetBSDProcess.c
  3. (C) 2015 Hisham H. Muhammad
  4. (C) 2015 Michael McConville
  5. (C) 2021 Santhosh Raju
  6. (C) 2021 htop dev team
  7. Released under the GNU GPLv2+, see the COPYING file
  8. in the source distribution for its full text.
  9. */
  10. #include "config.h" // IWYU pragma: keep
  11. #include "netbsd/NetBSDProcess.h"
  12. #include <stdlib.h>
  13. #include "CRT.h"
  14. #include "Process.h"
  15. #include "RichString.h"
  16. #include "XUtils.h"
  17. const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
  18. [0] = {
  19. .name = "",
  20. .title = NULL,
  21. .description = NULL,
  22. .flags = 0,
  23. },
  24. [PID] = {
  25. .name = "PID",
  26. .title = "PID",
  27. .description = "Process/thread ID",
  28. .flags = 0,
  29. .pidColumn = true,
  30. },
  31. [COMM] = {
  32. .name = "Command",
  33. .title = "Command ",
  34. .description = "Command line",
  35. .flags = 0,
  36. },
  37. [STATE] = {
  38. .name = "STATE",
  39. .title = "S ",
  40. .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)",
  41. .flags = 0,
  42. },
  43. [PPID] = {
  44. .name = "PPID",
  45. .title = "PPID",
  46. .description = "Parent process ID",
  47. .flags = 0,
  48. .pidColumn = true,
  49. },
  50. [PGRP] = {
  51. .name = "PGRP",
  52. .title = "PGRP",
  53. .description = "Process group ID",
  54. .flags = 0,
  55. .pidColumn = true,
  56. },
  57. [SESSION] = {
  58. .name = "SESSION",
  59. .title = "SESN",
  60. .description = "Process's session ID",
  61. .flags = 0,
  62. .pidColumn = true,
  63. },
  64. [TTY] = {
  65. .name = "TTY",
  66. .title = "TTY ",
  67. .description = "Controlling terminal",
  68. .flags = 0,
  69. },
  70. [TPGID] = {
  71. .name = "TPGID",
  72. .title = "TPGID",
  73. .description = "Process ID of the fg process group of the controlling terminal",
  74. .flags = 0,
  75. .pidColumn = true,
  76. },
  77. [MINFLT] = {
  78. .name = "MINFLT",
  79. .title = " MINFLT ",
  80. .description = "Number of minor faults which have not required loading a memory page from disk",
  81. .flags = 0,
  82. .defaultSortDesc = true,
  83. },
  84. [MAJFLT] = {
  85. .name = "MAJFLT",
  86. .title = " MAJFLT ",
  87. .description = "Number of major faults which have required loading a memory page from disk",
  88. .flags = 0,
  89. .defaultSortDesc = true,
  90. },
  91. [PRIORITY] = {
  92. .name = "PRIORITY",
  93. .title = "PRI ",
  94. .description = "Kernel's internal priority for the process",
  95. .flags = 0,
  96. },
  97. [NICE] = {
  98. .name = "NICE",
  99. .title = " NI ",
  100. .description = "Nice value (the higher the value, the more it lets other processes take priority)",
  101. .flags = 0,
  102. },
  103. [STARTTIME] = {
  104. .name = "STARTTIME",
  105. .title = "START ",
  106. .description = "Time the process was started",
  107. .flags = 0,
  108. },
  109. [ELAPSED] = {
  110. .name = "ELAPSED",
  111. .title = "ELAPSED ",
  112. .description = "Time since the process was started",
  113. .flags = 0,
  114. },
  115. [PROCESSOR] = {
  116. .name = "PROCESSOR",
  117. .title = "CPU ",
  118. .description = "Id of the CPU the process last executed on",
  119. .flags = 0,
  120. },
  121. [M_VIRT] = {
  122. .name = "M_VIRT",
  123. .title = " VIRT ",
  124. .description = "Total program size in virtual memory",
  125. .flags = 0,
  126. .defaultSortDesc = true,
  127. },
  128. [M_RESIDENT] = {
  129. .name = "M_RESIDENT",
  130. .title = " RES ",
  131. .description = "Resident set size, size of the text and data sections, plus stack usage",
  132. .flags = 0,
  133. .defaultSortDesc = true,
  134. },
  135. [ST_UID] = {
  136. .name = "ST_UID",
  137. .title = "UID",
  138. .description = "User ID of the process owner",
  139. .flags = 0,
  140. },
  141. [PERCENT_CPU] = {
  142. .name = "PERCENT_CPU",
  143. .title = " CPU%",
  144. .description = "Percentage of the CPU time the process used in the last sampling",
  145. .flags = 0,
  146. .defaultSortDesc = true,
  147. .autoWidth = true,
  148. .autoTitleRightAlign = true,
  149. },
  150. [PERCENT_NORM_CPU] = {
  151. .name = "PERCENT_NORM_CPU",
  152. .title = "NCPU%",
  153. .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)",
  154. .flags = 0,
  155. .defaultSortDesc = true,
  156. .autoWidth = true,
  157. },
  158. [PERCENT_MEM] = {
  159. .name = "PERCENT_MEM",
  160. .title = "MEM% ",
  161. .description = "Percentage of the memory the process is using, based on resident memory size",
  162. .flags = 0,
  163. .defaultSortDesc = true,
  164. },
  165. [USER] = {
  166. .name = "USER",
  167. .title = "USER ",
  168. .description = "Username of the process owner (or user ID if name cannot be determined)",
  169. .flags = 0,
  170. },
  171. [TIME] = {
  172. .name = "TIME",
  173. .title = " TIME+ ",
  174. .description = "Total time the process has spent in user and system time",
  175. .flags = 0,
  176. .defaultSortDesc = true,
  177. },
  178. [NLWP] = {
  179. .name = "NLWP",
  180. .title = "NLWP ",
  181. .description = "Number of threads in the process",
  182. .flags = 0,
  183. },
  184. [TGID] = {
  185. .name = "TGID",
  186. .title = "TGID",
  187. .description = "Thread group ID (i.e. process ID)",
  188. .flags = 0,
  189. .pidColumn = true,
  190. },
  191. [PROC_COMM] = {
  192. .name = "COMM",
  193. .title = "COMM ",
  194. .description = "comm string of the process",
  195. .flags = 0,
  196. },
  197. [PROC_EXE] = {
  198. .name = "EXE",
  199. .title = "EXE ",
  200. .description = "Basename of exe of the process",
  201. .flags = 0,
  202. },
  203. [CWD] = {
  204. .name = "CWD",
  205. .title = "CWD ",
  206. .description = "The current working directory of the process",
  207. .flags = PROCESS_FLAG_CWD,
  208. },
  209. };
  210. Process* NetBSDProcess_new(const Machine* host) {
  211. NetBSDProcess* this = xCalloc(1, sizeof(NetBSDProcess));
  212. Object_setClass(this, Class(NetBSDProcess));
  213. Process_init(&this->super, host);
  214. return (Process*)this;
  215. }
  216. void Process_delete(Object* cast) {
  217. NetBSDProcess* this = (NetBSDProcess*) cast;
  218. Process_done((Process*)cast);
  219. free(this);
  220. }
  221. static void NetBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
  222. const NetBSDProcess* np = (const NetBSDProcess*) super;
  223. char buffer[256]; buffer[255] = '\0';
  224. int attr = CRT_colors[DEFAULT_COLOR];
  225. //size_t n = sizeof(buffer) - 1;
  226. switch (field) {
  227. // add NetBSD-specific fields here
  228. default:
  229. Process_writeField(&np->super, str, field);
  230. return;
  231. }
  232. RichString_appendWide(str, attr, buffer);
  233. }
  234. static int NetBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) {
  235. const NetBSDProcess* p1 = (const NetBSDProcess*)v1;
  236. const NetBSDProcess* p2 = (const NetBSDProcess*)v2;
  237. // remove if actually used
  238. (void)p1; (void)p2;
  239. switch (key) {
  240. // add NetBSD-specific fields here
  241. default:
  242. return Process_compareByKey_Base(v1, v2, key);
  243. }
  244. }
  245. const ProcessClass NetBSDProcess_class = {
  246. .super = {
  247. .super = {
  248. .extends = Class(Process),
  249. .display = Row_display,
  250. .delete = Process_delete,
  251. .compare = Process_compare
  252. },
  253. .isHighlighted = Process_rowIsHighlighted,
  254. .isVisible = Process_rowIsVisible,
  255. .matchesFilter = Process_rowMatchesFilter,
  256. .compareByParent = Process_compareByParent,
  257. .sortKeyString = Process_rowGetSortKey,
  258. .writeField = NetBSDProcess_rowWriteField
  259. },
  260. .compareByKey = NetBSDProcess_compareByKey
  261. };