ZfsCompressedArcMeter.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. htop - ZfsCompressedArcMeter.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/ZfsCompressedArcMeter.h"
  9. #include <stddef.h>
  10. #include "CRT.h"
  11. #include "Meter.h"
  12. #include "Object.h"
  13. #include "Platform.h"
  14. #include "RichString.h"
  15. #include "XUtils.h"
  16. #include "zfs/ZfsArcStats.h"
  17. static const int ZfsCompressedArcMeter_attributes[] = {
  18. ZFS_COMPRESSED
  19. };
  20. void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
  21. if ( stats->isCompressed ) {
  22. this->total = stats->uncompressed;
  23. this->values[0] = stats->compressed;
  24. } else {
  25. // For uncompressed ARC, report 1:1 ratio
  26. this->total = stats->size;
  27. this->values[0] = stats->size;
  28. }
  29. }
  30. static int ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, size_t size) {
  31. if (this->values[0] > 0) {
  32. return xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]);
  33. }
  34. return xSnprintf(buffer, size, "N/A");
  35. }
  36. static void ZfsCompressedArcMeter_updateValues(Meter* this) {
  37. Platform_setZfsCompressedArcValues(this);
  38. ZfsCompressedArcMeter_printRatioString(this, this->txtBuffer, sizeof(this->txtBuffer));
  39. }
  40. static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
  41. const Meter* this = (const Meter*)cast;
  42. if (this->values[0] > 0) {
  43. char buffer[50];
  44. int len;
  45. Meter_humanUnit(buffer, this->total, sizeof(buffer));
  46. RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
  47. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Uncompressed, ");
  48. Meter_humanUnit(buffer, this->values[0], sizeof(buffer));
  49. RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
  50. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Compressed, ");
  51. len = ZfsCompressedArcMeter_printRatioString(this, buffer, sizeof(buffer));
  52. RichString_appendnAscii(out, CRT_colors[ZFS_RATIO], buffer, len);
  53. RichString_appendAscii(out, CRT_colors[METER_TEXT], " Ratio");
  54. } else {
  55. RichString_writeAscii(out, CRT_colors[METER_TEXT], " ");
  56. RichString_appendAscii(out, CRT_colors[FAILED_READ], "Compression Unavailable");
  57. }
  58. }
  59. const MeterClass ZfsCompressedArcMeter_class = {
  60. .super = {
  61. .extends = Class(Meter),
  62. .delete = Meter_delete,
  63. .display = ZfsCompressedArcMeter_display,
  64. },
  65. .updateValues = ZfsCompressedArcMeter_updateValues,
  66. .defaultMode = TEXT_METERMODE,
  67. .supportedModes = METERMODE_DEFAULT_SUPPORTED,
  68. .maxItems = 1,
  69. .total = 100.0,
  70. .attributes = ZfsCompressedArcMeter_attributes,
  71. .name = "ZFSCARC",
  72. .uiName = "ZFS CARC",
  73. .description = "ZFS CARC: Compressed ARC statistics",
  74. .caption = "ARC: "
  75. };