aboutsummaryrefslogtreecommitdiffstats
path: root/pcp/Platform.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2023-02-05 04:25:56 +0100
committerDaniel Lange <DLange@git.local>2023-02-05 04:25:56 +0100
commitf288666edc9180a2e81e6655951878124f321df6 (patch)
treeda70bf44b2423f6f8e9a070c063fed79d190b489 /pcp/Platform.c
parent937052b231259a47d881d539ad5748245ef55b99 (diff)
downloaddebian_htop-f288666edc9180a2e81e6655951878124f321df6.tar.gz
debian_htop-f288666edc9180a2e81e6655951878124f321df6.tar.bz2
debian_htop-f288666edc9180a2e81e6655951878124f321df6.zip
New upstream version 3.2.2upstream/3.2.2
Diffstat (limited to 'pcp/Platform.c')
-rw-r--r--pcp/Platform.c84
1 files changed, 51 insertions, 33 deletions
diff --git a/pcp/Platform.c b/pcp/Platform.c
index 342bf43..994cef3 100644
--- a/pcp/Platform.c
+++ b/pcp/Platform.c
@@ -1,8 +1,8 @@
/*
htop - linux/Platform.c
(C) 2014 Hisham H. Muhammad
-(C) 2020-2021 htop dev team
-(C) 2020-2021 Red Hat, Inc.
+(C) 2020-2022 htop dev team
+(C) 2020-2022 Red Hat, Inc.
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@@ -248,6 +248,37 @@ static const char* Platform_metricNames[] = {
[PCP_METRIC_COUNT] = NULL
};
+#ifndef HAVE_PMLOOKUPDESCS
+/*
+ * pmLookupDescs(3) exists in latest versions of libpcp (5.3.6+),
+ * but for older versions we provide an implementation here. This
+ * involves multiple round trips to pmcd though, which the latest
+ * libpcp version avoids by using a protocol extension. In time,
+ * perhaps in a few years, we could remove this back-compat code.
+ */
+int pmLookupDescs(int numpmid, pmID* pmids, pmDesc* descs) {
+ int count = 0;
+
+ for (int i = 0; i < numpmid; i++) {
+ /* expect some metrics to be missing - e.g. PMDA not available */
+ if (pmids[i] == PM_ID_NULL)
+ continue;
+
+ int sts = pmLookupDesc(pmids[i], &descs[i]);
+ if (sts < 0) {
+ if (pmDebugOptions.appl0)
+ fprintf(stderr, "Error: cannot lookup metric %s(%s): %s\n",
+ pcp->names[i], pmIDStr(pcp->pmids[i]), pmErrStr(sts));
+ pmids[i] = PM_ID_NULL;
+ continue;
+ }
+
+ count++;
+ }
+ return count;
+}
+#endif
+
size_t Platform_addMetric(PCPMetric id, const char* name) {
unsigned int i = (unsigned int)id;
@@ -325,21 +356,14 @@ bool Platform_init(void) {
return false;
}
- for (size_t i = 0; i < pcp->totalMetrics; i++) {
- pcp->fetch[i] = PM_ID_NULL; /* default is to not sample */
-
- /* expect some metrics to be missing - e.g. PMDA not available */
- if (pcp->pmids[i] == PM_ID_NULL)
- continue;
-
- sts = pmLookupDesc(pcp->pmids[i], &pcp->descs[i]);
- if (sts < 0) {
- if (pmDebugOptions.appl0)
- fprintf(stderr, "Error: cannot lookup metric %s(%s): %s\n",
- pcp->names[i], pmIDStr(pcp->pmids[i]), pmErrStr(sts));
- pcp->pmids[i] = PM_ID_NULL;
- continue;
- }
+ sts = pmLookupDescs(pcp->totalMetrics, pcp->pmids, pcp->descs);
+ if (sts < 1) {
+ if (sts < 0)
+ fprintf(stderr, "Error: cannot lookup descriptors: %s\n", pmErrStr(sts));
+ else /* ensure we have at least one valid metric to work with */
+ fprintf(stderr, "Error: cannot find a single valid metric, exiting\n");
+ Platform_done();
+ return false;
}
/* set proc.control.perclient.threads to 1 for live contexts */
@@ -504,28 +528,28 @@ void Platform_setMemoryValues(Meter* this) {
const PCPProcessList* ppl = (const PCPProcessList*) pl;
this->total = pl->totalMem;
- this->values[0] = pl->usedMem;
- this->values[1] = pl->buffersMem;
- this->values[2] = pl->sharedMem;
- this->values[3] = pl->cachedMem;
- this->values[4] = pl->availableMem;
+ this->values[MEMORY_METER_USED] = pl->usedMem;
+ this->values[MEMORY_METER_BUFFERS] = pl->buffersMem;
+ this->values[MEMORY_METER_SHARED] = pl->sharedMem;
+ this->values[MEMORY_METER_CACHE] = pl->cachedMem;
+ this->values[MEMORY_METER_AVAILABLE] = pl->availableMem;
if (ppl->zfs.enabled != 0) {
// ZFS does not shrink below the value of zfs_arc_min.
unsigned long long int shrinkableSize = 0;
if (ppl->zfs.size > ppl->zfs.min)
shrinkableSize = ppl->zfs.size - ppl->zfs.min;
- this->values[0] -= shrinkableSize;
- this->values[3] += shrinkableSize;
- this->values[4] += shrinkableSize;
+ this->values[MEMORY_METER_USED] -= shrinkableSize;
+ this->values[MEMORY_METER_CACHE] += shrinkableSize;
+ this->values[MEMORY_METER_AVAILABLE] += shrinkableSize;
}
}
void Platform_setSwapValues(Meter* this) {
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
- this->values[0] = pl->usedSwap;
- this->values[1] = pl->cachedSwap;
+ this->values[SWAP_METER_USED] = pl->usedSwap;
+ this->values[SWAP_METER_CACHE] = pl->cachedSwap;
}
void Platform_setZramValues(Meter* this) {
@@ -645,12 +669,6 @@ char* Platform_getProcessEnv(pid_t pid) {
return value.cp;
}
-char* Platform_getInodeFilename(pid_t pid, ino_t inode) {
- (void)pid;
- (void)inode;
- return NULL;
-}
-
FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
(void)pid;
return NULL;

© 2014-2024 Faster IT GmbH | imprint | privacy policy