This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fac088073e26 chore: camel-jbang - Memory Leak says where each sample
was allocated, so two leaks of byte[] are told apart (#29513)
fac088073e26 is described below
commit fac088073e26960832a53a744d521cacd083cdad
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 9 22:53:03 2026 +0100
chore: camel-jbang - Memory Leak says where each sample was allocated, so
two leaks of byte[] are told apart (#29513)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../dsl/jbang/core/commands/tui/LeakSite.java | 60 ++++++++++++++++++++++
.../dsl/jbang/core/commands/tui/MemoryLeakTab.java | 2 +-
.../src/main/resources/tui/help/memory-leak.md | 2 +-
.../dsl/jbang/core/commands/tui/LeakSiteTest.java | 54 +++++++++++++++++++
4 files changed, 116 insertions(+), 2 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSite.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSite.java
new file mode 100644
index 000000000000..84ac936b986e
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSite.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.List;
+
+import dev.tamboui.style.Style;
+import dev.tamboui.text.Line;
+import dev.tamboui.text.Span;
+import dev.tamboui.widgets.table.Cell;
+
+/**
+ * Where the objects of a sample of the Memory Leak tab were allocated, in the
code of the integration: the first frame
+ * of their stack that is not of the JDK or of Camel. Two leaks of byte[] are
two lines that say byte[]; their sites
+ * (MemoryLeak.lambda$configure$0:21, BufferLeakProcessor.process:45) tell
them apart.
+ */
+final class LeakSite {
+
+ private static final List<String> FRAMEWORK = List.of("java.", "javax.",
"jdk.", "sun.", "com.sun.", "org.apache.camel.");
+
+ private LeakSite() {
+ }
+
+ /** The first frame of the stack in the code of the integration,
method:line; null when there is none. */
+ static String of(List<MemoryLeakTab.StackEntry> stack) {
+ if (stack == null) {
+ return null;
+ }
+ for (MemoryLeakTab.StackEntry se : stack) {
+ String m = se.method;
+ // the class of a lambda is generated (MemoryLeak$$Lambda.0x...):
its body is the frame before
+ if (m == null || m.contains("$$Lambda") ||
FRAMEWORK.stream().anyMatch(m::startsWith)) {
+ continue;
+ }
+ return se.line > 0 ? m + ":" + se.line : m;
+ }
+ return null;
+ }
+
+ /** The class of the objects, and where they were allocated after it. */
+ static Cell classCell(String className, List<MemoryLeakTab.StackEntry>
stack) {
+ String site = of(stack);
+ Span cls = Span.styled(className != null ? className : "",
Style.EMPTY.fg(Theme.accent()));
+ return site == null ? Cell.from(cls) : Cell.from(Line.from(cls,
Span.styled(" in " + site, Theme.muted())));
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryLeakTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryLeakTab.java
index e6625e1f6053..a40614f73a37 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryLeakTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryLeakTab.java
@@ -428,7 +428,7 @@ class MemoryLeakTab extends AbstractTab {
String totalStr = e.sampledSize > 0 ? formatBytes(e.sampledSize) :
"-";
rows.add(Row.from(
rightCell(String.valueOf(e.num), 6),
- Cell.from(Span.styled(e.className != null ? e.className :
"", Style.EMPTY.fg(Theme.accent()))),
+ LeakSite.classCell(e.className, e.stackTrace),
rightCell(String.valueOf(e.count), 8),
rightCell(totalStr, 12),
rightCell(formatDuration(e.objectAge), 12)));
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/memory-leak.md
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/memory-leak.md
index 625fa1a4220e..e30fb9362b37 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/memory-leak.md
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/memory-leak.md
@@ -25,7 +25,7 @@ Samples from the same class and allocation site (stack trace)
are
grouped together automatically.
- **#** — Group number
-- **CLASS** — The class of the sampled long-lived object
+- **CLASS** — The class of the sampled long-lived object, and where it was
allocated in the code of the integration (the first frame of its stack that is
not of the JDK or of Camel, as `BufferLeakProcessor.process:45`): two leaks of
the same class, as `byte[]`, are told apart by it
- **COUNT** — Number of samples from the same allocation site
- **SAMPLED** — Sum of sampled allocation sizes during the recording
- **AGE** — Maximum age across samples in the group
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSiteTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSiteTest.java
new file mode 100644
index 000000000000..d658e210802e
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LeakSiteTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The memory-leak example leaks byte[] in two routes: the sites of the two
samples tell them apart.
+ */
+class LeakSiteTest {
+
+ @Test
+ void theSiteIsTheFirstFrameOfTheCodeOfTheIntegration() {
+ assertThat(LeakSite.of(List.of(
+ frame("java.util.Arrays.copyOf", 3512),
+ frame("BufferLeakProcessor.process", 45),
+
frame("org.apache.camel.support.processor.DelegateSyncProcessor.process", 67))))
+ .isEqualTo("BufferLeakProcessor.process:45");
+ // a lambda: its body, not its generated class
+ assertThat(LeakSite.of(List.of(
+ frame("MemoryLeak.lambda$configure$0", 21),
+ frame("MemoryLeak$$Lambda.0x000000006a812c00.process", -1),
+
frame("org.apache.camel.support.processor.DelegateSyncProcessor.process", 67))))
+ .isEqualTo("MemoryLeak.lambda$configure$0:21");
+ // all of Camel and the JDK: no site
+
assertThat(LeakSite.of(List.of(frame("org.apache.camel.util.IOHelper.copy",
10)))).isNull();
+ assertThat(LeakSite.of(null)).isNull();
+ }
+
+ private static MemoryLeakTab.StackEntry frame(String method, int line) {
+ MemoryLeakTab.StackEntry se = new MemoryLeakTab.StackEntry();
+ se.method = method;
+ se.line = line;
+ return se;
+ }
+}