109 lines
4.5 KiB
Diff
109 lines
4.5 KiB
Diff
|
From f8dc87ed130a0cfe1077242a4da2d621c4016bfb Mon Sep 17 00:00:00 2001
|
||
|
From: Ken McDonell <kenj@kenj.id.au>
|
||
|
Date: Thu, 4 Apr 2024 11:34:41 +1100
|
||
|
Subject: [PATCH] libpcp: small derived metrics bug fix
|
||
|
|
||
|
This is a partial fix for
|
||
|
https://github.com/performancecopilot/pcp/issues/1921
|
||
|
|
||
|
If the operand has the semantics of PM_SEM_COUNTER and the
|
||
|
value goes backwards from one fetch to the next, then return
|
||
|
no values for rate().
|
||
|
|
||
|
There is QA to come, but this needs a final blessing from Oracle
|
||
|
before the reproducer archive can be included.
|
||
|
|
||
|
cherry-picked:- f8dc87ed130a0cfe1077242a4da2d621c4016bfb
|
||
|
[Orabug: 36538820]
|
||
|
Signed-off-by: sagar sagar <sagar.sagar@oracle.com>
|
||
|
---
|
||
|
man/man3/pmregisterderived.3 | 13 +++++++++----
|
||
|
src/libpcp/src/derive_fetch.c | 23 ++++++++++++++++++++++-
|
||
|
2 files changed, 31 insertions(+), 5 deletions(-)
|
||
|
|
||
|
diff --git a/man/man3/pmregisterderived.3 b/man/man3/pmregisterderived.3
|
||
|
index d8719f373..32963c3b3 100644
|
||
|
--- a/man/man3/pmregisterderived.3
|
||
|
+++ b/man/man3/pmregisterderived.3
|
||
|
@@ -485,15 +485,20 @@ metric x with the dimension in the
|
||
|
.B time
|
||
|
domain decreased by one and scaling if required in the time utilization case
|
||
|
where the operand is in units of time, and the derived metric is unitless.
|
||
|
-This mimics the rate conversion applied to counter metrics by tools
|
||
|
+There is one value in the result
|
||
|
+for each instance that appears in both the current and the previous
|
||
|
+sample, except in the case where the metric x has
|
||
|
+the semantics of a counter, i.e. PM_SEM_COUNTER, and
|
||
|
+current value of an instance is smaller than the previous value
|
||
|
+of the same instance then no value is
|
||
|
+returned for this instance (this corresponds to a ``counter wrap'' or a ``counter reset'').
|
||
|
+These rules
|
||
|
+mimic the rate conversion applied to counter metrics by tools
|
||
|
such as
|
||
|
.BR pmval (1),
|
||
|
.BR pmie (1)
|
||
|
and
|
||
|
.BR pmchart (1).
|
||
|
-There is one value in the result
|
||
|
-for each instance that appears in both the current and the previous
|
||
|
-sample.
|
||
|
T}
|
||
|
_
|
||
|
instant(x) T{
|
||
|
diff --git a/src/libpcp/src/derive_fetch.c b/src/libpcp/src/derive_fetch.c
|
||
|
index 62921ece4..ed5f6ebcf 100644
|
||
|
--- a/src/libpcp/src/derive_fetch.c
|
||
|
+++ b/src/libpcp/src/derive_fetch.c
|
||
|
@@ -847,7 +847,13 @@ eval_expr(__pmContext *ctxp, node_t *np, struct timespec *stamp, int numpmid,
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
- /* rate() conversion, type will be DOUBLE */
|
||
|
+ /*
|
||
|
+ * rate() conversion, type will be DOUBLE
|
||
|
+ *
|
||
|
+ * For COUNTER metrics, return "no value" if the counter is
|
||
|
+ * NOT monotonic increasing ... this matches what pmval(1)
|
||
|
+ * and pmie(1) do in the same circumstances.
|
||
|
+ */
|
||
|
struct timespec stampdiff;
|
||
|
|
||
|
stampdiff = np->data.info->stamp;
|
||
|
@@ -857,18 +863,33 @@ eval_expr(__pmContext *ctxp, node_t *np, struct timespec *stamp, int numpmid,
|
||
|
np->data.info->ivlist[k].value.d = (double)(np->left->data.info->ivlist[i].value.l - np->left->data.info->last_ivlist[j].value.l);
|
||
|
break;
|
||
|
case PM_TYPE_U32:
|
||
|
+ if (np->left->desc.sem == PM_SEM_COUNTER &&
|
||
|
+ np->left->data.info->ivlist[i].value.ul < np->left->data.info->last_ivlist[j].value.ul)
|
||
|
+ continue;
|
||
|
np->data.info->ivlist[k].value.d = (double)(np->left->data.info->ivlist[i].value.ul - np->left->data.info->last_ivlist[j].value.ul);
|
||
|
break;
|
||
|
case PM_TYPE_64:
|
||
|
+ if (np->left->desc.sem == PM_SEM_COUNTER &&
|
||
|
+ np->left->data.info->ivlist[i].value.ll < np->left->data.info->last_ivlist[j].value.ll)
|
||
|
+ continue;
|
||
|
np->data.info->ivlist[k].value.d = (double)(np->left->data.info->ivlist[i].value.ll - np->left->data.info->last_ivlist[j].value.ll);
|
||
|
break;
|
||
|
case PM_TYPE_U64:
|
||
|
+ if (np->left->desc.sem == PM_SEM_COUNTER &&
|
||
|
+ np->left->data.info->ivlist[i].value.ull < np->left->data.info->last_ivlist[j].value.ull)
|
||
|
+ continue;
|
||
|
np->data.info->ivlist[k].value.d = (double)(np->left->data.info->ivlist[i].value.ull - np->left->data.info->last_ivlist[j].value.ull);
|
||
|
break;
|
||
|
case PM_TYPE_FLOAT:
|
||
|
+ if (np->left->desc.sem == PM_SEM_COUNTER &&
|
||
|
+ np->left->data.info->ivlist[i].value.f < np->left->data.info->last_ivlist[j].value.f)
|
||
|
+ continue;
|
||
|
np->data.info->ivlist[k].value.d = (double)(np->left->data.info->ivlist[i].value.f - np->left->data.info->last_ivlist[j].value.f);
|
||
|
break;
|
||
|
case PM_TYPE_DOUBLE:
|
||
|
+ if (np->left->desc.sem == PM_SEM_COUNTER &&
|
||
|
+ np->left->data.info->ivlist[i].value.d < np->left->data.info->last_ivlist[j].value.d)
|
||
|
+ continue;
|
||
|
np->data.info->ivlist[k].value.d = np->left->data.info->ivlist[i].value.d - np->left->data.info->last_ivlist[j].value.d;
|
||
|
break;
|
||
|
default:
|
||
|
--
|
||
|
2.39.3
|
||
|
|