ZfsArcMeter.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. htop - ZfsArcMeter.c
  3. (C) 2004-2011 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "zfs/ZfsArcMeter.h"
  9. #include <stddef.h>
  10. #include "CRT.h"
  11. #include "Object.h"
  12. #include "Platform.h"
  13. #include "RichString.h"
  14. #include "zfs/ZfsArcStats.h"
  15. static const int ZfsArcMeter_attributes[] = {
  16. ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER
  17. };
  18. void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
  19. this->total = stats->max;
  20. this->values[0] = stats->MFU;
  21. this->values[1] = stats->MRU;
  22. this->values[2] = stats->anon;
  23. this->values[3] = stats->header;
  24. this->values[4] = stats->other;
  25. // "Hide" the last value so it can
  26. // only be accessed by index and is not
  27. // displayed by the Bar or Graph style
  28. this->curItems = 5;
  29. this->values[5] = stats->size;
  30. }
  31. static void ZfsArcMeter_updateValues(Meter* this) {
  32. char* buffer = this->txtBuffer;
  33. size_t size = sizeof(this->txtBuffer);
  34. int written;
  35. Platform_setZfsArcValues(this);
  36. written = Meter_humanUnit(buffer, this->values[5], size);
  37. METER_BUFFER_CHECK(buffer, size, written);
  38. METER_BUFFER_APPEND_CHR(buffer, size, '/');
  39. Meter_humanUnit(buffer, this->total, size);
  40. }
  41. static void ZfsArcMeter_display(const Object* cast, RichString* out) {
  42. const Meter* this = (const Meter*)cast;
  43. if (this->values[5] > 0) {
  44. char buffer[50];
  45. Meter_humanUnit(buffer, this->total, sizeof(buffer));
  46. RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
  47. Meter_humanUnit(buffer, this->values[5], sizeof(buffer));
  48. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Used:");
  49. RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
  50. Meter_humanUnit(buffer, this->values[0], sizeof(buffer));
  51. RichString_appendAscii(out, CRT_colors[METER_TEXT], " MFU:");
  52. RichString_appendAscii(out, CRT_colors[ZFS_MFU], buffer);
  53. Meter_humanUnit(buffer, this->values[1], sizeof(buffer));
  54. RichString_appendAscii(out, CRT_colors[METER_TEXT], " MRU:");
  55. RichString_appendAscii(out, CRT_colors[ZFS_MRU], buffer);
  56. Meter_humanUnit(buffer, this->values[2], sizeof(buffer));
  57. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Anon:");
  58. RichString_appendAscii(out, CRT_colors[ZFS_ANON], buffer);
  59. Meter_humanUnit(buffer, this->values[3], sizeof(buffer));
  60. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Hdr:");
  61. RichString_appendAscii(out, CRT_colors[ZFS_HEADER], buffer);
  62. Meter_humanUnit(buffer, this->values[4], sizeof(buffer));
  63. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Oth:");
  64. RichString_appendAscii(out, CRT_colors[ZFS_OTHER], buffer);
  65. } else {
  66. RichString_writeAscii(out, CRT_colors[METER_TEXT], " ");
  67. RichString_appendAscii(out, CRT_colors[FAILED_READ], "Unavailable");
  68. }
  69. }
  70. const MeterClass ZfsArcMeter_class = {
  71. .super = {
  72. .extends = Class(Meter),
  73. .delete = Meter_delete,
  74. .display = ZfsArcMeter_display,
  75. },
  76. .updateValues = ZfsArcMeter_updateValues,
  77. .defaultMode = TEXT_METERMODE,
  78. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  79. .maxItems = 6,
  80. .total = 100.0,
  81. .attributes = ZfsArcMeter_attributes,
  82. .name = "ZFSARC",
  83. .uiName = "ZFS ARC",
  84. .caption = "ARC: "
  85. };