aboutsummaryrefslogtreecommitdiffstats
path: root/pcp
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
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')
-rw-r--r--pcp/PCPDynamicColumn.c7
-rw-r--r--pcp/PCPDynamicMeter.c10
-rw-r--r--pcp/PCPProcessList.c2
-rw-r--r--pcp/Platform.c84
-rw-r--r--pcp/Platform.h2
5 files changed, 68 insertions, 37 deletions
diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c
index aab2525..33c6d72 100644
--- a/pcp/PCPDynamicColumn.c
+++ b/pcp/PCPDynamicColumn.c
@@ -14,6 +14,7 @@ in the source distribution for its full text.
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
+#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -194,6 +195,12 @@ void PCPDynamicColumns_init(PCPDynamicColumns* columns) {
const char* home = getenv("HOME");
char* path;
+ if (!xdgConfigHome && !home) {
+ const struct passwd* pw = getpwuid(getuid());
+ if (pw)
+ home = pw->pw_dir;
+ }
+
columns->table = Hashtable_new(0, true);
/* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */
diff --git a/pcp/PCPDynamicMeter.c b/pcp/PCPDynamicMeter.c
index 7c55e4b..e899988 100644
--- a/pcp/PCPDynamicMeter.c
+++ b/pcp/PCPDynamicMeter.c
@@ -12,12 +12,14 @@ in the source distribution for its full text.
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
-#include <pcp/pmapi.h>
+#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <pcp/pmapi.h>
+
#include "Macros.h"
#include "Platform.h"
#include "RichString.h"
@@ -251,6 +253,12 @@ void PCPDynamicMeters_init(PCPDynamicMeters* meters) {
const char* home = getenv("HOME");
char* path;
+ if (!xdgConfigHome && !home) {
+ const struct passwd* pw = getpwuid(getuid());
+ if (pw)
+ home = pw->pw_dir;
+ }
+
meters->table = Hashtable_new(0, true);
/* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */
diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c
index 045f7ae..f893689 100644
--- a/pcp/PCPProcessList.c
+++ b/pcp/PCPProcessList.c
@@ -571,7 +571,7 @@ static void PCPProcessList_updateAllCPUTime(PCPProcessList* this, PCPMetric metr
{
pmAtomValue* value = &this->cpu[cpumetric];
if (PCPMetric_values(metric, value, 1, PM_TYPE_U64) == NULL)
- memset(&value, 0, sizeof(pmAtomValue));
+ memset(value, 0, sizeof(pmAtomValue));
}
static void PCPProcessList_updatePerCPUTime(PCPProcessList* this, PCPMetric metric, CPUMetric cpumetric)
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;
diff --git a/pcp/Platform.h b/pcp/Platform.h
index dc51c73..f06f226 100644
--- a/pcp/Platform.h
+++ b/pcp/Platform.h
@@ -98,8 +98,6 @@ void Platform_setZfsCompressedArcValues(Meter* this);
char* Platform_getProcessEnv(pid_t pid);
-char* Platform_getInodeFilename(pid_t pid, ino_t inode);
-
FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred);

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