|
|
27c44a |
commit 6b907e90c74fce82d6b712493d8b362bdd1a1ec1
|
|
|
27c44a |
Author: Nathan Scott <nathans@redhat.com>
|
|
|
27c44a |
Date: Tue Dec 14 08:54:14 2021 +1100
|
|
|
27c44a |
|
|
|
27c44a |
pmlogconf: switch to the bulk pmLookupDescs(3) interface
|
|
|
27c44a |
|
|
|
27c44a |
No functional change, all existing regression tests pass.
|
|
|
27c44a |
|
|
|
27c44a |
Related to Red Hat BZ #1973833.
|
|
|
27c44a |
|
|
|
27c44a |
diff --git a/src/pmlogconf/pmlogconf.c b/src/pmlogconf/pmlogconf.c
|
|
|
27c44a |
index fa1156859d..ef4fc08bbd 100644
|
|
|
27c44a |
--- a/src/pmlogconf/pmlogconf.c
|
|
|
27c44a |
+++ b/src/pmlogconf/pmlogconf.c
|
|
|
27c44a |
@@ -473,13 +473,19 @@ fetch_groups(void)
|
|
|
27c44a |
{
|
|
|
27c44a |
static pmResult *result;
|
|
|
27c44a |
const char **names;
|
|
|
27c44a |
+ pmDesc *descs;
|
|
|
27c44a |
pmID *pmids;
|
|
|
27c44a |
- int i, n, sts;
|
|
|
27c44a |
+ int i, n, sts, count;
|
|
|
27c44a |
|
|
|
27c44a |
- /* prepare arrays of names and identifiers for PMAPI metric lookup */
|
|
|
27c44a |
+ /* prepare arrays of names, descriptors and IDs for PMAPI metric lookup */
|
|
|
27c44a |
if ((names = calloc(ngroups, sizeof(char *))) == NULL)
|
|
|
27c44a |
return -ENOMEM;
|
|
|
27c44a |
+ if ((descs = calloc(ngroups, sizeof(pmDesc))) == NULL) {
|
|
|
27c44a |
+ free(names);
|
|
|
27c44a |
+ return -ENOMEM;
|
|
|
27c44a |
+ }
|
|
|
27c44a |
if ((pmids = calloc(ngroups, sizeof(pmID))) == NULL) {
|
|
|
27c44a |
+ free(descs);
|
|
|
27c44a |
free(names);
|
|
|
27c44a |
return -ENOMEM;
|
|
|
27c44a |
}
|
|
|
27c44a |
@@ -490,15 +496,16 @@ fetch_groups(void)
|
|
|
27c44a |
continue;
|
|
|
27c44a |
names[n++] = (const char *)groups[i].metric;
|
|
|
27c44a |
}
|
|
|
27c44a |
+ count = n;
|
|
|
27c44a |
|
|
|
27c44a |
- if ((sts = pmLookupName(n, names, pmids)) < 0) {
|
|
|
27c44a |
- if (n == 1)
|
|
|
27c44a |
+ if ((sts = pmLookupName(count, names, pmids)) < 0) {
|
|
|
27c44a |
+ if (count == 1)
|
|
|
27c44a |
groups[0].pmid = PM_ID_NULL;
|
|
|
27c44a |
else
|
|
|
27c44a |
fprintf(stderr, "%s: cannot lookup metric names: %s\n",
|
|
|
27c44a |
pmGetProgname(), pmErrStr(sts));
|
|
|
27c44a |
}
|
|
|
27c44a |
- else if ((sts = pmFetch(n, pmids, &result)) < 0) {
|
|
|
27c44a |
+ else if ((sts = pmFetch(count, pmids, &result)) < 0) {
|
|
|
27c44a |
fprintf(stderr, "%s: cannot fetch metric values: %s\n",
|
|
|
27c44a |
pmGetProgname(), pmErrStr(sts));
|
|
|
27c44a |
}
|
|
|
27c44a |
@@ -510,6 +517,13 @@ fetch_groups(void)
|
|
|
27c44a |
else
|
|
|
27c44a |
groups[i].pmid = pmids[n++];
|
|
|
27c44a |
}
|
|
|
27c44a |
+ /* descriptor lookup, descs_hash handles failure here */
|
|
|
27c44a |
+ (void) pmLookupDescs(count, pmids, descs);
|
|
|
27c44a |
+
|
|
|
27c44a |
+ /* create a hash over the descs for quick PMID lookup */
|
|
|
27c44a |
+ if ((sts = descs_hash(count, descs)) < 0)
|
|
|
27c44a |
+ fprintf(stderr, "%s: cannot hash metric descs: %s\n",
|
|
|
27c44a |
+ pmGetProgname(), pmErrStr(sts));
|
|
|
27c44a |
/* create a hash over the result for quick PMID lookup */
|
|
|
27c44a |
if ((sts = values_hash(result)) < 0)
|
|
|
27c44a |
fprintf(stderr, "%s: cannot hash metric values: %s\n",
|
|
|
27c44a |
@@ -806,14 +820,16 @@ evaluate_string_regexp(group_t *group, regex_cmp_t compare)
|
|
|
27c44a |
int i, found;
|
|
|
27c44a |
pmValueSet *vsp;
|
|
|
27c44a |
pmValue *vp;
|
|
|
27c44a |
+ pmDesc *dp;
|
|
|
27c44a |
pmAtomValue atom;
|
|
|
27c44a |
regex_t regex;
|
|
|
27c44a |
int sts, type;
|
|
|
27c44a |
|
|
|
27c44a |
- if ((vsp = metric_values(group->pmid)) == NULL)
|
|
|
27c44a |
+ if ((vsp = metric_values(group->pmid)) == NULL ||
|
|
|
27c44a |
+ (dp = metric_desc(group->pmid)) == NULL)
|
|
|
27c44a |
return 0;
|
|
|
27c44a |
|
|
|
27c44a |
- type = metric_type(group->pmid);
|
|
|
27c44a |
+ type = dp->type;
|
|
|
27c44a |
if (type < 0 || type > PM_TYPE_STRING) {
|
|
|
27c44a |
fprintf(stderr, "%s: %s uses regular expression on non-scalar metric\n",
|
|
|
27c44a |
pmGetProgname(), group->tag);
|
|
|
27c44a |
@@ -849,11 +865,14 @@ evaluate_string_regexp(group_t *group, regex_cmp_t compare)
|
|
|
27c44a |
static int
|
|
|
27c44a |
evaluate_values(group_t *group, numeric_cmp_t ncmp, string_cmp_t scmp)
|
|
|
27c44a |
{
|
|
|
27c44a |
- int type = metric_type(group->pmid);
|
|
|
27c44a |
+ pmDesc *dp;
|
|
|
27c44a |
+
|
|
|
27c44a |
+ if ((dp = metric_desc(group->pmid)) == NULL)
|
|
|
27c44a |
+ return 0;
|
|
|
27c44a |
|
|
|
27c44a |
- if (type == PM_TYPE_STRING)
|
|
|
27c44a |
+ if (dp->type == PM_TYPE_STRING)
|
|
|
27c44a |
return evaluate_string_values(group, scmp);
|
|
|
27c44a |
- return evaluate_number_values(group, type, ncmp);
|
|
|
27c44a |
+ return evaluate_number_values(group, dp->type, ncmp);
|
|
|
27c44a |
}
|
|
|
27c44a |
|
|
|
27c44a |
int
|
|
|
27c44a |
diff --git a/src/pmlogconf/util.c b/src/pmlogconf/util.c
|
|
|
27c44a |
index d44c2e529a..293eb2eca3 100644
|
|
|
27c44a |
--- a/src/pmlogconf/util.c
|
|
|
27c44a |
+++ b/src/pmlogconf/util.c
|
|
|
27c44a |
@@ -1,5 +1,5 @@
|
|
|
27c44a |
/*
|
|
|
27c44a |
- * Copyright (c) 2020 Red Hat. All Rights Reserved.
|
|
|
27c44a |
+ * Copyright (c) 2020-2021 Red Hat. All Rights Reserved.
|
|
|
27c44a |
*
|
|
|
27c44a |
* This program is free software; you can redistribute it and/or modify it
|
|
|
27c44a |
* under the terms of the GNU General Public License as published by the
|
|
|
27c44a |
@@ -14,7 +14,7 @@
|
|
|
27c44a |
#include "util.h"
|
|
|
27c44a |
|
|
|
27c44a |
static __pmHashCtl valuesctl; /* pointers to values in pmResult */
|
|
|
27c44a |
-static __pmHashCtl typesctl; /* metric types from pmLookupDesc */
|
|
|
27c44a |
+static __pmHashCtl descsctl; /* metric descs from pmLookupDesc */
|
|
|
27c44a |
|
|
|
27c44a |
int
|
|
|
27c44a |
values_hash(pmResult *result)
|
|
|
27c44a |
@@ -47,27 +47,33 @@ metric_values(pmID pmid)
|
|
|
27c44a |
}
|
|
|
27c44a |
|
|
|
27c44a |
int
|
|
|
27c44a |
-metric_type(pmID pmid)
|
|
|
27c44a |
+descs_hash(int numpmid, pmDesc *descs)
|
|
|
27c44a |
{
|
|
|
27c44a |
- __pmHashNode *node;
|
|
|
27c44a |
- pmDesc desc;
|
|
|
27c44a |
- int sts, *data;
|
|
|
27c44a |
+ unsigned int i;
|
|
|
27c44a |
+ pmDesc *dp;
|
|
|
27c44a |
+ int sts;
|
|
|
27c44a |
|
|
|
27c44a |
- if (pmid == PM_IN_NULL)
|
|
|
27c44a |
- return PM_TYPE_UNKNOWN;
|
|
|
27c44a |
- if ((node = __pmHashSearch(pmid, &typesctl)) == NULL) {
|
|
|
27c44a |
- if ((sts = pmLookupDesc(pmid, &desc)) < 0)
|
|
|
27c44a |
- return sts;
|
|
|
27c44a |
- if ((data = malloc(sizeof(int))) == NULL)
|
|
|
27c44a |
- return sts;
|
|
|
27c44a |
- *data = desc.type;
|
|
|
27c44a |
- if ((sts = __pmHashAdd(pmid, data, &typesctl)) < 0) {
|
|
|
27c44a |
- free(data);
|
|
|
27c44a |
+ if ((sts = __pmHashPreAlloc(numpmid, &descsctl)) < 0)
|
|
|
27c44a |
+ return sts;
|
|
|
27c44a |
+
|
|
|
27c44a |
+ for (i = 0; i < numpmid; i++) {
|
|
|
27c44a |
+ dp = &descs[i];
|
|
|
27c44a |
+ if ((sts = __pmHashAdd(dp->pmid, dp, &descsctl)) < 0)
|
|
|
27c44a |
return sts;
|
|
|
27c44a |
- }
|
|
|
27c44a |
- return *data;
|
|
|
27c44a |
}
|
|
|
27c44a |
- return *(int *)node->data;
|
|
|
27c44a |
+ return numpmid;
|
|
|
27c44a |
+}
|
|
|
27c44a |
+
|
|
|
27c44a |
+pmDesc *
|
|
|
27c44a |
+metric_desc(pmID pmid)
|
|
|
27c44a |
+{
|
|
|
27c44a |
+ __pmHashNode *node;
|
|
|
27c44a |
+
|
|
|
27c44a |
+ if (pmid == PM_IN_NULL)
|
|
|
27c44a |
+ return NULL;
|
|
|
27c44a |
+ if ((node = __pmHashSearch(pmid, &descsctl)) == NULL)
|
|
|
27c44a |
+ return NULL;
|
|
|
27c44a |
+ return (pmDesc *)node->data;
|
|
|
27c44a |
}
|
|
|
27c44a |
|
|
|
27c44a |
int
|
|
|
27c44a |
diff --git a/src/pmlogconf/util.h b/src/pmlogconf/util.h
|
|
|
27c44a |
index 17d856a0d7..a11350d899 100644
|
|
|
27c44a |
--- a/src/pmlogconf/util.h
|
|
|
27c44a |
+++ b/src/pmlogconf/util.h
|
|
|
27c44a |
@@ -34,7 +34,9 @@ extern void fmt(const char *, char *, size_t, int, int, fmt_t, void *);
|
|
|
27c44a |
|
|
|
27c44a |
extern int values_hash(pmResult *);
|
|
|
27c44a |
extern pmValueSet *metric_values(pmID);
|
|
|
27c44a |
-extern int metric_type(pmID);
|
|
|
27c44a |
+
|
|
|
27c44a |
+extern int descs_hash(int, pmDesc *);
|
|
|
27c44a |
+extern pmDesc *metric_desc(pmID);
|
|
|
27c44a |
|
|
|
27c44a |
typedef int (*numeric_cmp_t)(double, double);
|
|
|
27c44a |
extern int number_equal(double, double);
|