Skip to content
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
17 changes: 13 additions & 4 deletions src/main/java/com/jvmtop/JvmTop.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import joptsimple.OptionSet;

import com.jvmtop.view.ConsoleView;
import com.jvmtop.view.VMDetailStatView;
import com.jvmtop.view.VMDetailView;
import com.jvmtop.view.VMOverviewView;
import com.jvmtop.view.VMProfileView;
Expand Down Expand Up @@ -91,6 +92,7 @@ private static OptionParser createOptionParser()
"delay between each output iteration").withRequiredArg()
.ofType(Double.class);
parser.accepts("profile", "start CPU profiling at the specified jvm");
parser.accepts("stat", "start stat view at the specified jvm");
parser.accepts("sysinfo", "outputs diagnostic information");
parser.accepts("verbose", "verbose mode");
parser.accepts("threadlimit",
Expand Down Expand Up @@ -141,6 +143,8 @@ public static void main(String[] args) throws Exception
double delay = 1.0;

boolean profileMode = a.has("profile");

boolean statMode = a.has("stat");

Integer iterations = a.has("once") ? 1 : -1;

Expand Down Expand Up @@ -221,8 +225,9 @@ public static void main(String[] args) throws Exception
{
jvmTop.run(new VMProfileView(pid, width));
}
else
{
else if (statMode) {
jvmTop.run(new VMDetailStatView(pid, width));
} else {
VMDetailView vmDetailView = new VMDetailView(pid, width);
vmDetailView.setDisplayedThreadLimit(threadLimitEnabled);
if (threadlimit != null)
Expand Down Expand Up @@ -298,9 +303,13 @@ protected void run(ConsoleView view) throws Exception
{
if (maxIterations_ > 1 || maxIterations_ == -1)
{
clearTerminal();
if (view.isClearingRequired()) {
clearTerminal();
}
}
if (view.isTopBarRequired()) {
printTopBar();
}
printTopBar();
view.printView();
System.out.flush();
iterations++;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/jvmtop/view/AbstractConsoleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String toMB(long bytes)
{
return "n/a";
}
return "" + (bytes / 1024 / 1024) + "m";
return "" + (bytes / 1000 / 1000);
}

/**
Expand Down Expand Up @@ -194,4 +194,15 @@ public void sleep(long millis) throws Exception
{
Thread.sleep(millis);
}

@Override
public boolean isTopBarRequired()
{
return true;
}

@Override
public boolean isClearingRequired() {
return true;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/jvmtop/view/ConsoleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public interface ConsoleView
*
*/
public void sleep(long millis) throws Exception;

boolean isTopBarRequired();

boolean isClearingRequired();

}
93 changes: 93 additions & 0 deletions src/main/java/com/jvmtop/view/VMDetailStatView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* jvmtop - java monitoring for the command-line
*
* Copyright (C) 2013 by Patric Rufflar. All rights reserved. DO NOT ALTER OR
* REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 only, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.jvmtop.view;


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

/**
* "detail" view, printing detail metrics of a specific jvm in a vmstat manner.
*
*
* @author
*
*/
public class VMDetailStatView extends AbstractConsoleView {

private VMInfo vmInfo_;

public VMDetailStatView(int vmid, Integer width) throws Exception {
super(width);
LocalVirtualMachine localVirtualMachine = LocalVirtualMachine
.getLocalVirtualMachine(vmid);
vmInfo_ = VMInfo.processNewVM(localVirtualMachine, vmid);
}

@Override
public void printView() throws Exception {
vmInfo_.update();

if (vmInfo_.getState() == VMInfoState.ATTACHED_UPDATE_ERROR) {
System.out
.println("ERROR: Could not fetch telemetries - Process terminated?");
exit();
return;
}
if (vmInfo_.getState() != VMInfoState.ATTACHED) {
System.out.println("ERROR: Could not attach to process.");
exit();
return;
}
printVM(vmInfo_);

}

private void printVM(VMInfo vmInfo) throws Exception {

String deadlockState = "";
if (vmInfo.hasDeadlockThreads()) {
deadlockState = "!D";
}

System.out
.printf(
"%5d %5s %5.2f%% %5.2f%% %4d %2.2s%n",
vmInfo.getId(),
toMB(vmInfo.getHeapUsed()),
vmInfo.getCpuLoad() * 100,
vmInfo.getGcLoad() * 100,
vmInfo.getThreadCount(),
deadlockState);

}

@Override
public boolean isTopBarRequired() {
return false;
}

@Override
public boolean isClearingRequired() {
return false;
}
}