PressureStallMeter.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. htop - PressureStallMeter.c
  3. (C) 2004-2011 Hisham H. Muhammad
  4. (C) 2019 Ran Benita
  5. Released under the GNU GPLv2+, see the COPYING file
  6. in the source distribution for its full text.
  7. */
  8. #include "config.h" // IWYU pragma: keep
  9. #include "linux/PressureStallMeter.h"
  10. #include <stdbool.h>
  11. #include <string.h>
  12. #include "CRT.h"
  13. #include "Meter.h"
  14. #include "Object.h"
  15. #include "Platform.h"
  16. #include "RichString.h"
  17. #include "XUtils.h"
  18. static const int PressureStallMeter_attributes[] = {
  19. PRESSURE_STALL_TEN,
  20. PRESSURE_STALL_SIXTY,
  21. PRESSURE_STALL_THREEHUNDRED
  22. };
  23. static void PressureStallMeter_updateValues(Meter* this) {
  24. const char* file;
  25. if (strstr(Meter_name(this), "CPU")) {
  26. file = "cpu";
  27. } else if (strstr(Meter_name(this), "IO")) {
  28. file = "io";
  29. } else if (strstr(Meter_name(this), "IRQ")) {
  30. file = "irq";
  31. } else {
  32. file = "memory";
  33. }
  34. bool some;
  35. if (strstr(Meter_name(this), "Some")) {
  36. some = true;
  37. } else {
  38. some = false;
  39. }
  40. Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
  41. /* only print bar for ten (not sixty and threehundred), cause the sum is meaningless */
  42. this->curItems = 1;
  43. xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s %s %5.2lf%% %5.2lf%% %5.2lf%%", some ? "some" : "full", file, this->values[0], this->values[1], this->values[2]);
  44. }
  45. static void PressureStallMeter_display(const Object* cast, RichString* out) {
  46. const Meter* this = (const Meter*)cast;
  47. char buffer[20];
  48. int len;
  49. len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[0]);
  50. RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_TEN], buffer, len);
  51. len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[1]);
  52. RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer, len);
  53. len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[2]);
  54. RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer, len);
  55. }
  56. const MeterClass PressureStallCPUSomeMeter_class = {
  57. .super = {
  58. .extends = Class(Meter),
  59. .delete = Meter_delete,
  60. .display = PressureStallMeter_display,
  61. },
  62. .updateValues = PressureStallMeter_updateValues,
  63. .defaultMode = TEXT_METERMODE,
  64. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  65. .maxItems = 3,
  66. .total = 100.0,
  67. .attributes = PressureStallMeter_attributes,
  68. .name = "PressureStallCPUSome",
  69. .uiName = "PSI some CPU",
  70. .caption = "PSI some CPU: ",
  71. .description = "Pressure Stall Information, some cpu"
  72. };
  73. const MeterClass PressureStallIOSomeMeter_class = {
  74. .super = {
  75. .extends = Class(Meter),
  76. .delete = Meter_delete,
  77. .display = PressureStallMeter_display,
  78. },
  79. .updateValues = PressureStallMeter_updateValues,
  80. .defaultMode = TEXT_METERMODE,
  81. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  82. .maxItems = 3,
  83. .total = 100.0,
  84. .attributes = PressureStallMeter_attributes,
  85. .name = "PressureStallIOSome",
  86. .uiName = "PSI some IO",
  87. .caption = "PSI some IO: ",
  88. .description = "Pressure Stall Information, some io"
  89. };
  90. const MeterClass PressureStallIOFullMeter_class = {
  91. .super = {
  92. .extends = Class(Meter),
  93. .delete = Meter_delete,
  94. .display = PressureStallMeter_display,
  95. },
  96. .updateValues = PressureStallMeter_updateValues,
  97. .defaultMode = TEXT_METERMODE,
  98. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  99. .maxItems = 3,
  100. .total = 100.0,
  101. .attributes = PressureStallMeter_attributes,
  102. .name = "PressureStallIOFull",
  103. .uiName = "PSI full IO",
  104. .caption = "PSI full IO: ",
  105. .description = "Pressure Stall Information, full io"
  106. };
  107. const MeterClass PressureStallIRQFullMeter_class = {
  108. .super = {
  109. .extends = Class(Meter),
  110. .delete = Meter_delete,
  111. .display = PressureStallMeter_display,
  112. },
  113. .updateValues = PressureStallMeter_updateValues,
  114. .defaultMode = TEXT_METERMODE,
  115. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  116. .maxItems = 3,
  117. .total = 100.0,
  118. .attributes = PressureStallMeter_attributes,
  119. .name = "PressureStallIRQFull",
  120. .uiName = "PSI full IRQ",
  121. .caption = "PSI full IRQ: ",
  122. .description = "Pressure Stall Information, full irq"
  123. };
  124. const MeterClass PressureStallMemorySomeMeter_class = {
  125. .super = {
  126. .extends = Class(Meter),
  127. .delete = Meter_delete,
  128. .display = PressureStallMeter_display,
  129. },
  130. .updateValues = PressureStallMeter_updateValues,
  131. .defaultMode = TEXT_METERMODE,
  132. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  133. .maxItems = 3,
  134. .total = 100.0,
  135. .attributes = PressureStallMeter_attributes,
  136. .name = "PressureStallMemorySome",
  137. .uiName = "PSI some memory",
  138. .caption = "PSI some memory: ",
  139. .description = "Pressure Stall Information, some memory"
  140. };
  141. const MeterClass PressureStallMemoryFullMeter_class = {
  142. .super = {
  143. .extends = Class(Meter),
  144. .delete = Meter_delete,
  145. .display = PressureStallMeter_display,
  146. },
  147. .updateValues = PressureStallMeter_updateValues,
  148. .defaultMode = TEXT_METERMODE,
  149. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  150. .maxItems = 3,
  151. .total = 100.0,
  152. .attributes = PressureStallMeter_attributes,
  153. .name = "PressureStallMemoryFull",
  154. .uiName = "PSI full memory",
  155. .caption = "PSI full memory: ",
  156. .description = "Pressure Stall Information, full memory"
  157. };