package jp.co.flect.jvmtool;

import java.io.StringReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import jp.co.flect.io.RunProcess;

public class JMap {
	
	private String command;
	
	public JMap() {
		this("jmap");
	}
	
	public JMap(String command) {
		this.command = command;
	}
	
	public String run(int pid) throws IOException {
		return run("", pid);
	}
	
	public String heap(int pid) throws IOException {
		return run("-heap", pid);
	}
	
	public String histo(int pid) throws IOException {
		return run("-histo", pid);
	}
	
	public String permstat(int pid) throws IOException {
		return run("-permstat", pid);
	}
	
	public String run(String option, int pid) throws IOException {
		RunProcess process = new RunProcess();
		process.setStdOutAsString(true);
		
		int n = process.run(this.command, option, Integer.toString(pid));
		return process.getStdOutAsString();
	}
	
}

@@ -111,16 +111,37 @@
 eption;%0A
+import java.io.File;%0A
 import j
@@ -265,16 +265,65 @@
 ommand;%0A
+%09private String lastError;%0A%09private boolean d64;%0A
 %09%0A%09publi
@@ -428,489 +428,1449 @@
 lic 
-String run(int pid) throws IOException %7B%0A%09%09return run(%22%22, pid);%0A%09%7D%0A%09%0A%09public String heap(int pid) throws IOException %7B%0A%09%09return run(%22-heap%22, pid);%0A%09%7D%0A%09%0A%09public String histo(int pid) throws IOException %7B%0A%09%09return run(%22-histo%22, pid);%0A%09%7D%0A%09%0A%09public String permstat(int pid) throws IOException %7B%0A%09%09return run(%22-permstat%22, pid);%0A%09%7D%0A%09%0A%09public String run(String option, int pid) throws IOException %7B%0A%09%09RunProcess process = new RunProcess();%0A%09%09process.setStdOutAsString(true);%0A%09%09%0A%09%09int n = 
+boolean is64bit() %7B return this.d64;%7D%0A%09public void set64bit(boolean b) %7B this.d64 = b;%7D%0A%09public JMap with64bit(boolean b) %7B this.d64 = b; return this;%7D%0A%09%0A%09public String getLastError() %7B return this.lastError;%7D%0A%09%0A%09public String run(int pid) throws IOException %7B%0A%09%09return run(%22%22, pid);%0A%09%7D%0A%09%0A%09public String heap(int pid) throws IOException %7B%0A%09%09return run(%22-heap%22, pid);%0A%09%7D%0A%09%0A%09public String histo(int pid) throws IOException %7B%0A%09%09return histo(false, pid);%0A%09%7D%0A%09%0A%09public String histo(boolean live, int pid) throws IOException %7B%0A%09%09String op = %22-histo%22;%0A%09%09if (live) %7B%0A%09%09%09op += %22:live%22;%0A%09%09%7D%0A%09%09return run(op, pid);%0A%09%7D%0A%09%0A%09public String permstat(int pid) throws IOException %7B%0A%09%09return run(%22-permstat%22, pid);%0A%09%7D%0A%09%0A%09public String finalizerinfo(int pid) throws IOException %7B%0A%09%09return run(%22-finalizerinfo%22, pid);%0A%09%7D%0A%09%0A%09public void dump(int pid, File file) throws IOException %7B%0A%09%09dump(false, pid, file);%0A%09%7D%0A%09%0A%09public void dump(boolean live, int pid, File file) throws IOException %7B%0A%09%09StringBuilder buf = new StringBuilder();%0A%09%09buf.append(%22-dump:%22);%0A%09%09if (live) %7B%0A%09%09%09buf.append(%22live,%22);%0A%09%09%7D%0A%09%09buf.append(%22format=b,file=%22).append(file.getCanonicalPath());%0A%09%09run(buf.toString(), pid);%0A%09%7D%0A%09%0A%09public String run(String option, int pid) throws IOException %7B%0A%09%09RunProcess process = new RunProcess();%0A%09%09process.setStdOutAsString(true);%0A%09%09process.setStdErrAsString(true);%0A%09%09int n = this.d64 ?%0A%09%09%09process.run(this.command, %22-J-d64%22, option, Integer.toString(pid)) :%0A%09%09%09
 proc
@@ -1923,16 +1923,64 @@
 (pid));%0A
+%09%09this.lastError = process.getStdErrAsString();%0A
 %09%09return

Update JMap