Skip to contentSkip to conversation

Fix flowindent for "return" probes with multiple statements

PATCH In review [email protected] 2 participants 2 messages Mar 30 – Apr 14

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fix flowindent for "return" probes with multiple statements

From: Eugene Loh <[email protected]>

The flowindent algorithm should change indentation based only on the number of levels of entry and return. So, if an entry or return probe has multiple statements, the indentation should change only for the first statement.

Such logic is used for entry probes. Similar logic should be used for return probes.

Add a test to cover the case of multiple statements per entry and return probes. Also have it check a greater number of indentations. Since the new test supersedes the old ones, remove the old tests, which were fickle anyhow. The new test can still fail -- the flowindent algorithm is not completely robust -- so allow reinvocation in case of failure. The intermittent failures of flowindent tests have long been a testing irritant. Now, with reinvocation, testing shows no failures in 100 iterations on over a dozen systems.

Orabug: 39140395

---
 libdtrace/dt_consume.c                        |  11 +-
 test/unittest/options/tst.F.aarch64.r         |   1 -
 test/unittest/options/tst.F.d                 |  36 ----
 test/unittest/options/tst.F.r.p               |   1 -
 test/unittest/options/tst.F.x86_64.r          |   1 -
 .../unittest/options/tst.flowindent.aarch64.r | 160 ----------------
 test/unittest/options/tst.flowindent.d        |  36 ----
 test/unittest/options/tst.flowindent.r        |   1 +
 test/unittest/options/tst.flowindent.r.p      |   7 -
 test/unittest/options/tst.flowindent.sh       | 171 ++++++++++++++++++
 test/unittest/options/tst.flowindent.x86_64.r | 160 ----------------
 11 files changed, 176 insertions(+), 409 deletions(-)
 delete mode 120000 test/unittest/options/tst.F.aarch64.r
 delete mode 100644 test/unittest/options/tst.F.d
 delete mode 120000 test/unittest/options/tst.F.r.p
 delete mode 120000 test/unittest/options/tst.F.x86_64.r
 delete mode 100644 test/unittest/options/tst.flowindent.aarch64.r
 delete mode 100644 test/unittest/options/tst.flowindent.d
 create mode 100644 test/unittest/options/tst.flowindent.r
 delete mode 100755 test/unittest/options/tst.flowindent.r.p
 create mode 100755 test/unittest/options/tst.flowindent.sh
 delete mode 100644 test/unittest/options/tst.flowindent.x86_64.r
libdtrace/dt_consume.c +4 -7
index eca2139fb..8888af5f1 100644
@@ -474,17 +474,14 @@ dt_flowindent(dtrace_hdl_t *dtp, dtrace_probedata_t *data, dtrace_id_t lastprid,
 	}
 
 	/*
-	 * If we're going to indent this, we need to check the ID of our last
-	 * call.  If we're looking at the same probe ID but a different STID,
-	 * we _don't_ want to indent.  (Yes, there are some minor holes in
-	 * this scheme -- it's a heuristic.)
+	 * If we're looking at the same probe ID but a different STID,
+	 * we do NOT want to change indentation.  (This heuristic could fail.)
 	 */
-	if (flow == DTRACEFLOW_ENTRY) {
+	if (flow != DTRACEFLOW_NONE)
 		if (stid != laststid && pd->id == lastprid)
 			flow = DTRACEFLOW_NONE;
-	}
 
-	if (flow == DTRACEFLOW_ENTRY || flow == DTRACEFLOW_RETURN)
+	if (flow != DTRACEFLOW_NONE)
 		data->dtpda_prefix = str;
 	else
 		data->dtpda_prefix = "| ";
test/unittest/options/tst.F.aarch64.r deleted +0 -1
deleted file mode 120000
index 802f9b829..000000000
@@ -1 +0,0 @@
-tst.flowindent.aarch64.r
\ No newline at end of file
test/unittest/options/tst.F.d deleted +0 -36
deleted file mode 100644
index 90430868e..000000000
@@ -1,36 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2022, 2024, 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: The -F option enables entry/return matching output.
- *
- * SECTION: Options and Tunables/Consumer Options
- */
-
-/* @@runtest-opts: -FZ -xswitchrate=1s */
-/* @@timeout: 15 */
-/* @@trigger: readwholedir */
-
-BEGIN
-{
-	i = 0;
-	j = 0;
-}
-
-syscall::read:
-/pid == $target/
-{
-	printf("syscall: %d\n", i++);
-}
-
-fbt:vmlinux:SyS_read:,
-fbt:vmlinux:__arm64_sys_read:,
-fbt:vmlinux:__x64_sys_read:
-/pid == $target/
-{
-	printf("fbt: %d\n", j++);
-}
test/unittest/options/tst.F.r.p deleted +0 -1
deleted file mode 120000
index 6260a34c1..000000000
@@ -1 +0,0 @@
-tst.flowindent.r.p
\ No newline at end of file
test/unittest/options/tst.F.x86_64.r deleted +0 -1
deleted file mode 120000
index 509d38a69..000000000
@@ -1 +0,0 @@
-tst.flowindent.x86_64.r
\ No newline at end of file
test/unittest/options/tst.flowindent.aarch64.r deleted +0 -160

160 lines not on this page · raw message

test/unittest/options/tst.flowindent.d deleted +0 -36
deleted file mode 100644
index 1ce1e26f7..000000000
@@ -1,36 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2022, 2024, 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: The -xflowindent option enables entry/return matching output.
- *
- * SECTION: Options and Tunables/Consumer Options
- */
-
-/* @@runtest-opts: -xflowindent -Z -xswitchrate=1s */
-/* @@timeout: 15 */
-/* @@trigger: readwholedir */
-
-BEGIN
-{
-	i = 0;
-	j = 0;
-}
-
-syscall::read:
-/pid == $target/
-{
-	printf("syscall: %d\n", i++);
-}
-
-fbt:vmlinux:SyS_read:,
-fbt:vmlinux:__arm64_sys_read:,
-fbt:vmlinux:__x64_sys_read:
-/pid == $target/
-{
-	printf("fbt: %d\n", j++);
-}
test/unittest/options/tst.flowindent.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/options/tst.flowindent.r.p deleted +0 -7
deleted file mode 100755
index 1c6489608..000000000
@@ -1,7 +0,0 @@
-#!/usr/bin/gawk -f
-
-# Report only from 40 to 80.
-BEGIN { report = 0 }
-$NF == 40 { report = 1 }
-$NF == 80 { report = 0 }
-report == 1 { print }
test/unittest/options/tst.flowindent.sh new file +171 -0

171 lines not on this page · raw message

test/unittest/options/tst.flowindent.x86_64.r deleted +0 -160

160 lines not on this page · raw message

Signature · 1 line
2.47.3
Reviewed-by on v2 1/1
#1 lore raw

On 30 Mar 2026, eugene loh spake thusly:

Quoted 19 lines

From: Eugene Loh <[email protected]>

The flowindent algorithm should change indentation based only on the number of levels of entry and return. So, if an entry or return probe has multiple statements, the indentation should change only for the first statement.

Such logic is used for entry probes. Similar logic should be used for return probes.

Add a test to cover the case of multiple statements per entry and return probes. Also have it check a greater number of indentations. Since the new test supersedes the old ones, remove the old tests, which were fickle anyhow. The new test can still fail -- the flowindent algorithm is not completely robust -- so allow reinvocation in case of failure. The intermittent failures of flowindent tests have long been a testing irritant. Now, with reinvocation, testing shows no failures in 100 iterations on over a dozen systems.

Quoted 2 lines

Orabug: 39140395

Much better tests!

Signature · 1 line
NULL && (void)