[DTrace-devel] [PATCH 3/5] agg: ensure there is always space for at least one aggregation
Kris Van Hees
kris.van.hees at oracle.com
Mon May 1 19:49:30 UTC 2023
When aggregations are used, raise the aggsize option value if needed to
ensure there is room for at least one aggregation.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
libdtrace/dt_bpf.c | 8 ++++---
test/unittest/aggs/tst.aggsize-too-small.d | 28 ++++++++++++++++++++++
test/unittest/aggs/tst.aggsize-too-small.r | 7 ++++++
3 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 test/unittest/aggs/tst.aggsize-too-small.d
create mode 100644 test/unittest/aggs/tst.aggsize-too-small.r
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index 18aa07af..0f33f245 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -520,9 +520,11 @@ gmap_create_aggs(dtrace_hdl_t *dtp)
nelems = dtp->dt_options[DTRACEOPT_AGGSIZE] /
(dtp->dt_maxtuplesize + dtp->dt_maxaggdsize);
-
- if (nelems == 0)
- return 0;
+ if (nelems == 0) {
+ dtp->dt_options[DTRACEOPT_AGGSIZE] =
+ dtp->dt_maxtuplesize + dtp->dt_maxaggdsize;
+ nelems = 1;
+ }
dtp->dt_aggmap_fd = create_gmap_of_maps(dtp, "aggs",
BPF_MAP_TYPE_ARRAY_OF_MAPS,
diff --git a/test/unittest/aggs/tst.aggsize-too-small.d b/test/unittest/aggs/tst.aggsize-too-small.d
new file mode 100644
index 00000000..3298d600
--- /dev/null
+++ b/test/unittest/aggs/tst.aggsize-too-small.d
@@ -0,0 +1,28 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: If aggsize is too small to hold a single aggregation, the size is
+ * increased to make it fit.
+ *
+ * SECTION: Aggregations/Aggregations
+ */
+
+#pragma D option quietresize=no
+#pragma D option aggsize=256
+#pragma D option strsize=256
+
+BEGIN
+{
+ @["a"] = count();
+ exit(0);
+}
+
+ERROR
+{
+ exit(0);
+}
diff --git a/test/unittest/aggs/tst.aggsize-too-small.r b/test/unittest/aggs/tst.aggsize-too-small.r
new file mode 100644
index 00000000..504e0ed0
--- /dev/null
+++ b/test/unittest/aggs/tst.aggsize-too-small.r
@@ -0,0 +1,7 @@
+ FUNCTION:NAME
+ :BEGIN
+
+ a 1
+-- @@stderr --
+dtrace: script 'test/unittest/aggs/tst.aggsize-too-small.d' matched 2 probes
+dtrace: aggregation size raised to 285
--
2.39.1
More information about the DTrace-devel
mailing list