diff options
author | Nathan Scott <nathans@redhat.com> | 2022-09-13 12:14:40 +1000 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2022-09-14 09:13:07 +0200 |
commit | d58180bdac59800df47e182555e3a1f68358cddd (patch) | |
tree | deb1280f961c8abefc33b0f5e43c227d2aa848d0 /pcp | |
parent | 5552dc9c668908939493bf04f904a2e454ef1d51 (diff) |
Use pmLookupDescs(3) function if available from libpcp
This is a relative new, single-round-trip variant of the
pmLookupDesc(3) function for metric descriptors lookup.
Diffstat (limited to 'pcp')
-rw-r--r-- | pcp/Platform.c | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/pcp/Platform.c b/pcp/Platform.c index 342bf439..bec5cad9 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 */ |