From f5720096ad76a70316b8a0f0dbd6f2039b75394a Mon Sep 17 00:00:00 2001 From: Haim Yadid Date: Thu, 8 Dec 2022 15:41:55 +0200 Subject: [PATCH] move ProfileNodeFilter to plugins package --- .../java/com/performizeit/mjprof/model/Profile.java | 6 +++--- .../java/com/performizeit/mjprof/model/SFNode.java | 4 +++- .../com/performizeit/mjprof/parser/ThreadDump.java | 7 +++---- .../filters}/ProfileNodeFilter.java | 7 ++++--- .../plugins/mappers/singlethread/StackBottom.java | 2 -- .../mappers/singlethread/StackFrameContains.java | 2 -- .../plugins/mappers/singlethread/StackTop.java | 2 +- .../plugin/PluginWithParameterConstructorTest.java | 12 ++++-------- 8 files changed, 18 insertions(+), 24 deletions(-) rename src/main/java/com/performizeit/mjprof/{model => plugins/filters}/ProfileNodeFilter.java (83%) diff --git a/src/main/java/com/performizeit/mjprof/model/Profile.java b/src/main/java/com/performizeit/mjprof/model/Profile.java index b023644..fdf7c5c 100644 --- a/src/main/java/com/performizeit/mjprof/model/Profile.java +++ b/src/main/java/com/performizeit/mjprof/model/Profile.java @@ -16,6 +16,8 @@ */ package com.performizeit.mjprof.model; +import com.performizeit.mjprof.plugins.filters.ProfileNodeFilter; + import java.util.HashMap; @@ -72,9 +74,7 @@ public void addSingle(StackTraceElement[] elements) { HashMap c = root.children; root.count ++; for (int i=elements.length-1;i>=0;i--) { - String sfi = "at "+ elements[i].getClassName() + "." +elements[i].getMethodName() +"("+elements[i].getFileName()+":"+elements[i].getLineNumber()+")"; - if (sfi.isEmpty()) continue; SFNode node = c.get(sfi); if (node == null) { node = new SFNode(); @@ -133,7 +133,7 @@ public void visit(ProfileVisitor pv) { root.visitChildren(pv,0); } - public void filter(ProfileNodeFilter pnf,Object context) { + public void filter(ProfileNodeFilter pnf, Object context) { root.filterChildren(pnf,0,context); } public int getCount() { diff --git a/src/main/java/com/performizeit/mjprof/model/SFNode.java b/src/main/java/com/performizeit/mjprof/model/SFNode.java index e3a2f08..f6d1180 100644 --- a/src/main/java/com/performizeit/mjprof/model/SFNode.java +++ b/src/main/java/com/performizeit/mjprof/model/SFNode.java @@ -16,6 +16,8 @@ */ package com.performizeit.mjprof.model; +import com.performizeit.mjprof.plugins.filters.ProfileNodeFilter; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -275,4 +277,4 @@ public int depthBelow() { return depthB; } -} \ No newline at end of file +} diff --git a/src/main/java/com/performizeit/mjprof/parser/ThreadDump.java b/src/main/java/com/performizeit/mjprof/parser/ThreadDump.java index 3609c39..333ee27 100644 --- a/src/main/java/com/performizeit/mjprof/parser/ThreadDump.java +++ b/src/main/java/com/performizeit/mjprof/parser/ThreadDump.java @@ -45,7 +45,6 @@ public ThreadDump(JStackHeader header, ArrayList threadInfos) { } - public ThreadDump() { } @@ -83,9 +82,9 @@ public void setHeader(JStackHeader header) { } public ArrayList cloneStacks() { - ArrayList newStcks = new ArrayList<>(); - newStcks.addAll(getThreadInfos()); - return newStcks; + ArrayList newStacks = new ArrayList<>(); + newStacks.addAll(getThreadInfos()); + return newStacks; } public int getJNIglobalReferences() { diff --git a/src/main/java/com/performizeit/mjprof/model/ProfileNodeFilter.java b/src/main/java/com/performizeit/mjprof/plugins/filters/ProfileNodeFilter.java similarity index 83% rename from src/main/java/com/performizeit/mjprof/model/ProfileNodeFilter.java rename to src/main/java/com/performizeit/mjprof/plugins/filters/ProfileNodeFilter.java index b009312..c752a8b 100644 --- a/src/main/java/com/performizeit/mjprof/model/ProfileNodeFilter.java +++ b/src/main/java/com/performizeit/mjprof/plugins/filters/ProfileNodeFilter.java @@ -15,9 +15,10 @@ along with mjprof. If not, see . */ -package com.performizeit.mjprof.model; +package com.performizeit.mjprof.plugins.filters; -public interface ProfileNodeFilter { - boolean accept(SFNode node, int level,Object context); +import com.performizeit.mjprof.model.SFNode; +public interface ProfileNodeFilter { + boolean accept(SFNode node, int level, Object context); } diff --git a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackBottom.java b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackBottom.java index 6e53d9c..8e1778c 100644 --- a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackBottom.java +++ b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackBottom.java @@ -20,8 +20,6 @@ import com.performizeit.mjprof.api.Plugin; import com.performizeit.mjprof.api.PluginCategory; import com.performizeit.mjprof.model.Profile; -import com.performizeit.mjprof.model.ProfileNodeFilter; -import com.performizeit.mjprof.model.SFNode; import com.performizeit.mjprof.api.Param; import com.performizeit.mjprof.parser.ThreadInfo; diff --git a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackFrameContains.java b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackFrameContains.java index ba1b5b9..6dca34f 100644 --- a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackFrameContains.java +++ b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackFrameContains.java @@ -20,8 +20,6 @@ import com.performizeit.mjprof.api.Plugin; import com.performizeit.mjprof.api.PluginCategory; import com.performizeit.mjprof.model.Profile; -import com.performizeit.mjprof.model.ProfileNodeFilter; -import com.performizeit.mjprof.model.SFNode; import com.performizeit.mjprof.api.Param; import com.performizeit.mjprof.parser.ThreadInfo; diff --git a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackTop.java b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackTop.java index 2a4dfb6..899b8df 100644 --- a/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackTop.java +++ b/src/main/java/com/performizeit/mjprof/plugins/mappers/singlethread/StackTop.java @@ -20,7 +20,7 @@ import com.performizeit.mjprof.api.Plugin; import com.performizeit.mjprof.api.PluginCategory; import com.performizeit.mjprof.model.Profile; -import com.performizeit.mjprof.model.ProfileNodeFilter; +import com.performizeit.mjprof.plugins.filters.ProfileNodeFilter; import com.performizeit.mjprof.model.SFNode; import com.performizeit.mjprof.api.Param; import com.performizeit.mjprof.parser.ThreadInfo; diff --git a/src/test/java/com/performizeit/mjprof/plugin/PluginWithParameterConstructorTest.java b/src/test/java/com/performizeit/mjprof/plugin/PluginWithParameterConstructorTest.java index 89bff57..2cc09b3 100644 --- a/src/test/java/com/performizeit/mjprof/plugin/PluginWithParameterConstructorTest.java +++ b/src/test/java/com/performizeit/mjprof/plugin/PluginWithParameterConstructorTest.java @@ -20,7 +20,7 @@ import com.performizeit.mjprof.plugin.types.SingleThreadMapper; import com.performizeit.mjprof.api.Plugin; import com.performizeit.mjprof.model.Profile; -import com.performizeit.mjprof.model.ProfileNodeFilter; +import com.performizeit.mjprof.plugins.filters.ProfileNodeFilter; import com.performizeit.mjprof.model.SFNode; import com.performizeit.mjprof.api.Param; import com.performizeit.mjprof.parser.ThreadInfo; @@ -39,13 +39,9 @@ public ThreadInfo map(ThreadInfo stck) { HashMap mtd = stck.cloneMetaData(); Profile jss = (Profile) mtd.get("stack"); - jss.filter(new ProfileNodeFilter() { - - @Override - public boolean accept(SFNode node, int level, Object context) { - if (node.getStackFrame() == null) return true; - return node.getStackFrame().contains("lock"); - } + jss.filter((node, level, context) -> { + if (node.getStackFrame() == null) return true; + return node.getStackFrame().contains("lock"); },null); return stck; }