Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding commadline option to filter packages from profiling #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/com/jvmtop/JvmTop.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
import java.util.SplittableRandom;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
Expand Down Expand Up @@ -106,6 +107,9 @@ private static OptionParser createOptionParser()
parser
.acceptsAll(Arrays.asList(new String[] { "w", "width" }),
"Width in columns for the console display").withRequiredArg().ofType(Integer.class);
parser
.acceptsAll(Arrays.asList(new String[] { "f", "filter" }),
"packages to be filtered from profiling").withRequiredArg().ofType(String.class);

parser
.accepts("threadnamewidth",
Expand Down Expand Up @@ -145,6 +149,8 @@ public static void main(String[] args) throws Exception
Integer iterations = a.has("once") ? 1 : -1;

Integer threadlimit = null;

String[] filters = new String[]{};

boolean threadLimitEnabled = true;

Expand Down Expand Up @@ -179,6 +185,16 @@ public static void main(String[] args) throws Exception
{
width = (Integer) a.valueOf("width");
}

if (a.hasArgument("filter"))
{
String filter = (String) a.valueOf("filter");
filters = filter.split(",");
for (int i = 0; i < filters.length; i++)
{
System.out.println("filter: "+filters[i]);
}
}

if (a.hasArgument("threadlimit"))
{
Expand Down Expand Up @@ -219,7 +235,7 @@ public static void main(String[] args) throws Exception
{
if (profileMode)
{
jvmTop.run(new VMProfileView(pid, width));
jvmTop.run(new VMProfileView(pid, width, filters));
}
else
{
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/com/jvmtop/profiler/CPUSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

import joptsimple.internal.Strings;

import com.jvmtop.monitor.VMInfo;

/**
Expand All @@ -55,13 +57,7 @@ public class CPUSampler


//TODO: these exception list should be expanded to the most common 3rd-party library packages
private List<String> filter = Arrays
.asList(new String[] {
"org.eclipse.", "org.apache.", "java.", "sun.", "com.sun.", "javax.",
"oracle.", "com.trilead.", "org.junit.", "org.mockito.",
"org.hibernate.", "com.ibm.", "com.caucho."

});
private List<String> filter = new ArrayList<String>();

private ConcurrentMap<Long, Long> threadCPUTime = new ConcurrentHashMap<Long, Long>();

Expand All @@ -71,15 +67,29 @@ public class CPUSampler
private VMInfo vmInfo_;

/**
* @param filters
* @param threadMxBean
* @throws Exception
*/
public CPUSampler(VMInfo vmInfo) throws Exception
public CPUSampler(VMInfo vmInfo, String[] filters) throws Exception
{
super();
threadMxBean_ = vmInfo.getThreadMXBean();
beginCPUTime_ = vmInfo.getProxyClient().getProcessCpuTime();
vmInfo_ = vmInfo;
String[] defaultFilters = new String[] {
"org.eclipse.", "org.apache.", "java.", "sun.", "com.sun.", "javax.",
"oracle.", "com.trilead.", "org.junit.", "org.mockito.",
"org.hibernate.", "com.ibm.", "com.caucho.", "org.mariadb."};
for (int i = 0; i < defaultFilters.length; i++)
{
filter.add(defaultFilters[i]);
}
for (int i = 0; i < filters.length; i++)
{
if(!Strings.isNullOrEmpty(filters[i]))
filter.add(filters[i]);
}
}

public List<MethodStats> getTop(int limit)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jvmtop/view/VMProfileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public class VMProfileView extends AbstractConsoleView

private VMInfo vmInfo_;

public VMProfileView(int vmid, Integer width) throws Exception
public VMProfileView(int vmid, Integer width, String[] filters) throws Exception
{
super(width);
LocalVirtualMachine localVirtualMachine = LocalVirtualMachine
.getLocalVirtualMachine(vmid);
vmInfo_ = VMInfo.processNewVM(localVirtualMachine, vmid);
cpuSampler_ = new CPUSampler(vmInfo_);
cpuSampler_ = new CPUSampler(vmInfo_, filters);
}

@Override
Expand Down