Platform.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef HEADER_Platform
  2. #define HEADER_Platform
  3. /*
  4. htop - pcp/Platform.h
  5. (C) 2014 Hisham H. Muhammad
  6. (C) 2020-2021 htop dev team
  7. (C) 2020-2021 Red Hat, Inc. All Rights Reserved.
  8. Released under the GNU GPLv2+, see the COPYING file
  9. in the source distribution for its full text.
  10. */
  11. #include <stdbool.h>
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <pcp/pmapi.h>
  15. #include <sys/time.h>
  16. #include <sys/types.h>
  17. /* use htop config.h values for these macros, not pcp values */
  18. #undef PACKAGE_URL
  19. #undef PACKAGE_NAME
  20. #undef PACKAGE_STRING
  21. #undef PACKAGE_TARNAME
  22. #undef PACKAGE_VERSION
  23. #undef PACKAGE_BUGREPORT
  24. #include "Action.h"
  25. #include "BatteryMeter.h"
  26. #include "DiskIOMeter.h"
  27. #include "Hashtable.h"
  28. #include "Meter.h"
  29. #include "NetworkIOMeter.h"
  30. #include "Process.h"
  31. #include "ProcessLocksScreen.h"
  32. #include "RichString.h"
  33. #include "SignalsPanel.h"
  34. #include "CommandLine.h"
  35. #include "pcp/Metric.h"
  36. #include "pcp/PCPDynamicColumn.h"
  37. #include "pcp/PCPDynamicMeter.h"
  38. #include "pcp/PCPDynamicScreen.h"
  39. typedef struct Platform_ {
  40. int context; /* PMAPI(3) context identifier */
  41. size_t totalMetrics; /* total number of all metrics */
  42. const char** names; /* name array indexed by Metric */
  43. pmID* pmids; /* all known metric identifiers */
  44. pmID* fetch; /* enabled identifiers for sampling */
  45. pmDesc* descs; /* metric desc array indexed by Metric */
  46. pmResult* result; /* sample values result indexed by Metric */
  47. PCPDynamicMeters meters; /* dynamic meters via configuration files */
  48. PCPDynamicColumns columns; /* dynamic columns via configuration files */
  49. PCPDynamicScreens screens; /* dynamic screens via configuration files */
  50. struct timeval offset; /* time offset used in archive mode only */
  51. long long btime; /* boottime in seconds since the epoch */
  52. char* release; /* uname and distro from this context */
  53. int pidmax; /* maximum platform process identifier */
  54. unsigned int ncpu; /* maximum processor count configured */
  55. } Platform;
  56. extern const ScreenDefaults Platform_defaultScreens[];
  57. extern const unsigned int Platform_numberOfDefaultScreens;
  58. extern const SignalItem Platform_signals[];
  59. extern const unsigned int Platform_numberOfSignals;
  60. extern const MeterClass* const Platform_meterTypes[];
  61. bool Platform_init(void);
  62. void Platform_done(void);
  63. void Platform_setBindings(Htop_Action* keys);
  64. int Platform_getUptime(void);
  65. void Platform_getLoadAverage(double* one, double* five, double* fifteen);
  66. long long Platform_getBootTime(void);
  67. unsigned int Platform_getMaxCPU(void);
  68. pid_t Platform_getMaxPid(void);
  69. double Platform_setCPUValues(Meter* this, int cpu);
  70. void Platform_setMemoryValues(Meter* this);
  71. void Platform_setSwapValues(Meter* this);
  72. void Platform_setZramValues(Meter* this);
  73. void Platform_setZfsArcValues(Meter* this);
  74. void Platform_setZfsCompressedArcValues(Meter* this);
  75. char* Platform_getProcessEnv(pid_t pid);
  76. FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
  77. void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred);
  78. bool Platform_getDiskIO(DiskIOData* data);
  79. bool Platform_getNetworkIO(NetworkIOData* data);
  80. void Platform_getBattery(double* percent, ACPresence* isOnAC);
  81. void Platform_getHostname(char* buffer, size_t size);
  82. void Platform_getRelease(char** string);
  83. enum {
  84. PLATFORM_LONGOPT_HOST = 128,
  85. PLATFORM_LONGOPT_TIMEZONE,
  86. PLATFORM_LONGOPT_HOSTZONE,
  87. };
  88. #define PLATFORM_LONG_OPTIONS \
  89. {PMLONGOPT_HOST, optional_argument, 0, PLATFORM_LONGOPT_HOST}, \
  90. {PMLONGOPT_TIMEZONE, optional_argument, 0, PLATFORM_LONGOPT_TIMEZONE}, \
  91. {PMLONGOPT_HOSTZONE, optional_argument, 0, PLATFORM_LONGOPT_HOSTZONE}, \
  92. void Platform_longOptionsUsage(const char* name);
  93. CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv);
  94. extern pmOptions opts;
  95. size_t Platform_addMetric(Metric id, const char* name);
  96. void Platform_getFileDescriptors(double* used, double* max);
  97. void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec);
  98. void Platform_gettime_monotonic(uint64_t* msec);
  99. Hashtable* Platform_dynamicMeters(void);
  100. void Platform_dynamicMetersDone(Hashtable* meters);
  101. void Platform_dynamicMeterInit(Meter* meter);
  102. void Platform_dynamicMeterUpdateValues(Meter* meter);
  103. void Platform_dynamicMeterDisplay(const Meter* meter, RichString* out);
  104. Hashtable* Platform_dynamicColumns(void);
  105. void Platform_dynamicColumnsDone(Hashtable* columns);
  106. const char* Platform_dynamicColumnName(unsigned int key);
  107. bool Platform_dynamicColumnWriteField(const Process* proc, RichString* str, unsigned int key);
  108. Hashtable* Platform_dynamicScreens(void);
  109. void Platform_defaultDynamicScreens(Settings* settings);
  110. void Platform_addDynamicScreen(ScreenSettings* ss);
  111. void Platform_addDynamicScreenAvailableColumns(Panel* availableColumns, const char* screen);
  112. void Platform_dynamicScreensDone(Hashtable* screens);
  113. void Platform_updateTables(Machine* host);
  114. #endif