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

Added option for CSV and TS usage #91

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
25 changes: 25 additions & 0 deletions doc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ USERNAME = Username which owns this jvm process
DL = If !D is shown if the jvm detected a thread deadlock
```

### JVM overview CSV mode ###
Command-line: `jvmtop.sh --csv`

The CSV option removes the header and enables easy and parsing (e.g. in R).

```
PID,MAIN-CLASS,HPCUR,HPMAX,NHCUR,NHMAX,CPU,GC,VM,USERNAME,#T,DL
3370,wrapperSimpleApp,165m,455m,109m,176m,0.12%,0.00%,S6U37,web,21
27338,WatchdogManager,11m,28m,23m,130m,0.00%,0.00%,6U37 web,,31
19187,m.jvmtop.JvmTop,20m,3544m,13m,130m,0.93%,0.47%,S6U37,web,20
16733,artup.Bootstrap,159m,455m,166m,304m,0.12%,0.00%,S6U37,web,46
```

### JVM overview timestamp (+ optional CSV) mode ###
Command-line: `jvmtop.sh --ts --csv`

The timestamp option is a `new Date().toTime()` command for continuous monitoring.

```
PID,MAIN-CLASS,HPCUR,HPMAX,NHCUR,NHMAX,CPU,GC,VM,USERNAME,#T,DL,TS
3370,wrapperSimpleApp,165m,455m,109m,176m,0.12%,0.00%,S6U37,web,21,1480337426048
27338,WatchdogManager,11m,28m,23m,130m,0.00%,0.00%,6U37 web,,31,1480337426048
19187,m.jvmtop.JvmTop,20m,3544m,13m,130m,0.93%,0.47%,S6U37,web,20,1480337426048
16733,artup.Bootstrap,159m,455m,166m,304m,0.12%,0.00%,S6U37,web,46,1480337426048
```

### Detail mode (Single-VM monitoring) ###

Expand Down
40 changes: 27 additions & 13 deletions src/main/java/com/jvmtop/JvmTop.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/
package com.jvmtop;

import com.jvmtop.view.*;
import joptsimple.OptionParser;
import joptsimple.OptionSet;

import java.io.BufferedOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
Expand All @@ -33,14 +37,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import joptsimple.OptionParser;
import joptsimple.OptionSet;

import com.jvmtop.view.ConsoleView;
import com.jvmtop.view.VMDetailView;
import com.jvmtop.view.VMOverviewView;
import com.jvmtop.view.VMProfileView;

/**
* JvmTop entry point class.
*
Expand Down Expand Up @@ -73,8 +69,9 @@ public class JvmTop
private int maxIterations_ = -1;

private static Logger logger;
private static DisplayOptions opts;

private static OptionParser createOptionParser()
private static OptionParser createOptionParser()
{
OptionParser parser = new OptionParser();
parser.acceptsAll(Arrays.asList(new String[] { "help", "?", "h" }),
Expand Down Expand Up @@ -112,6 +109,9 @@ private static OptionParser createOptionParser()
"sets displayed thread name length in detail mode (defaults to 30)")
.withRequiredArg().ofType(Integer.class);

parser.accepts("ts", "Display timestamp");
parser.accepts("csv", "Use CSV output");

return parser;
}

Expand Down Expand Up @@ -202,6 +202,20 @@ public static void main(String[] args) throws Exception
threadNameWidth = (Integer) a.valueOf("threadnamewidth");
}

boolean isCsv = false;
if (a.has("csv"))
{
isCsv = true;
}

boolean isTS = false;
if (a.has("ts"))
{
isTS = true;
}

opts = new DisplayOptions(isCsv, isTS, width);

if (sysInfoOption)
{
outputSystemProps();
Expand All @@ -213,17 +227,17 @@ public static void main(String[] args) throws Exception
jvmTop.setMaxIterations(iterations);
if (pid == null)
{
jvmTop.run(new VMOverviewView(width));
jvmTop.run(new VMOverviewView(opts));
}
else
{
if (profileMode)
{
jvmTop.run(new VMProfileView(pid, width));
jvmTop.run(new VMProfileView(pid, opts));
}
else
{
VMDetailView vmDetailView = new VMDetailView(pid, width);
VMDetailView vmDetailView = new VMDetailView(pid, opts);
vmDetailView.setDisplayedThreadLimit(threadLimitEnabled);
if (threadlimit != null)
{
Expand Down Expand Up @@ -300,7 +314,7 @@ protected void run(ConsoleView view) throws Exception
{
clearTerminal();
}
printTopBar();
if(!opts.isCSV()) printTopBar();
view.printView();
System.out.flush();
iterations++;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jvmtop/view/AbstractConsoleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public abstract class AbstractConsoleView implements ConsoleView
/**
*
*/
public AbstractConsoleView(Integer width)
public AbstractConsoleView(DisplayOptions opts)
{
super();
if (width == null) width = MIN_WIDTH;
if (width < MIN_WIDTH) width = MIN_WIDTH;
this.width = width;
if (opts.getWidth() == null) width = MIN_WIDTH;
else if (opts.getWidth() < MIN_WIDTH) width = MIN_WIDTH;
else this.width = opts.getWidth();
}

/**
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/jvmtop/view/DisplayOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.jvmtop.view;


public class DisplayOptions {
private boolean isCSV = false;
private boolean displayTS = false;
private Integer width = 0;

public DisplayOptions(boolean isCSV, boolean displayTS, Integer width) {
this.isCSV = isCSV;
this.displayTS = displayTS;
this.width = width;
}

public boolean isCSV() {
return isCSV;
}

public void setCSV(boolean CSV) {
isCSV = CSV;
}

public boolean isDisplayTS() {
return displayTS;
}

public void setDisplayTS(boolean displayTS) {
this.displayTS = displayTS;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}
}
14 changes: 5 additions & 9 deletions src/main/java/com/jvmtop/view/VMDetailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@

package com.jvmtop.view;

import java.lang.management.ThreadInfo;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.jvmtop.monitor.VMInfo;
import com.jvmtop.monitor.VMInfoState;
import com.jvmtop.openjdk.tools.LocalVirtualMachine;

import java.lang.management.ThreadInfo;
import java.util.*;

/**
* "detail" view, printing detail metrics of a specific jvm.
* Also printing the top threads (based on the current CPU usage)
Expand All @@ -55,9 +51,9 @@ public class VMDetailView extends AbstractConsoleView
//TODO: refactor
private Map<Long, Long> previousThreadCPUMillis = new HashMap<Long, Long>();

public VMDetailView(int vmid, Integer width) throws Exception
public VMDetailView(int vmid, DisplayOptions opts) throws Exception
{
super(width);
super(opts);
LocalVirtualMachine localVirtualMachine = LocalVirtualMachine
.getLocalVirtualMachine(vmid);
vmInfo_ = VMInfo.processNewVM(localVirtualMachine, vmid);
Expand Down
Loading