use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.
the class MonitorsCommand method threadCommand.
/**
* Dumps all monitors that are active for the specified J9Thread/J9VMThread/java.lang.Thread
* @param args
* @param out
* @throws DDRInteractiveCommandException
*/
private void threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
if (args.length < 2) {
out.println("This command takes one address argument: \"!monitors thread <address>\"");
return;
}
try {
long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
VoidPointer ptr = VoidPointer.cast(address);
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
J9VMThreadPointer mainThread = vm.mainThread();
J9ThreadLibraryPointer lib = mainThread.osThread().library();
J9PoolPointer pool = lib.thread_pool();
Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
J9ThreadPointer osThreadPtr = null;
while (poolIterator.hasNext()) {
osThreadPtr = poolIterator.next();
// Is there an associated J9VMThread?
J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
J9ObjectPointer jlThread = null;
if (vmThread.notNull()) {
jlThread = vmThread.threadObject();
if ((null != jlThread) && jlThread.equals(ptr)) {
out.println("Found java/lang/Thread @ " + ptr.getHexAddress());
printMonitorsForJ9VMThread(out, vm, vmThread);
return;
} else if (vmThread.equals(ptr)) {
out.println("Found j9vmthread @ " + ptr.getHexAddress());
printMonitorsForJ9VMThread(out, vm, vmThread);
return;
}
}
if (osThreadPtr.equals(ptr)) {
out.println("Found j9thread @ " + ptr.getHexAddress());
if (vmThread.notNull()) {
printMonitorsForJ9VMThread(out, vm, vmThread);
}
printMonitorsForJ9Thread(out, vm, osThreadPtr);
return;
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.
the class RuntimeSettingsCommand method run.
/**
* Run method for !runtimesettings extension.
*
* @param command !runtimesettings
* @param args args passed by !runtimesettings extension.
* @param context Context of current core file.
* @param out PrintStream to print the output to the console.
* @throws DDRInteractiveCommandException
*/
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (0 < args.length) {
out.println("!runtimesettings expects no args. Usage :");
printUsage(out);
return;
}
try {
Long currentSoftmx;
String qualifiedCurrentSoftmx = "";
String initialSoftmx = "not set";
J9RASPointer ras = DataType.getJ9RASPointer();
J9JavaVMPointer vm = J9RASHelper.getVM(ras);
IProcess process = vm.getProcess();
J9DDRImageProcess ddrProcess = new J9DDRImageProcess(process);
String cmdline;
/* Parse the command line of a running program that generated core
* file to get the original -Xsoftmx setting
*/
cmdline = ddrProcess.getCommandLine();
int start = cmdline.indexOf("-Xsoftmx");
int length = "-Xsoftmx".length();
int end = cmdline.indexOf(" ", start);
if (-1 != start) {
/* extract the value from the end of the option */
initialSoftmx = cmdline.substring(start + length, end);
initialSoftmx = initialSoftmx.toUpperCase();
}
currentSoftmx = new Long(GCExtensions.softMx().longValue());
qualifiedCurrentSoftmx = currentSoftmx.toString();
Matcher m = p.matcher(initialSoftmx);
/* if initial softmx value is set on the command line as qualified
* value, print current softmx value in qualified form, otherwise
* print current in byte value
*/
if (m.matches()) {
/* User may add multiple letters after the number on the command
* line, currently GC parser accepts this and simply ignores
* extra letters, so we need to do the same, set initialSoftmx
* to the first match of the pattern
*/
initialSoftmx = m.group(1);
/* convert size in bytes held in currentSoftmx to canonical form */
qualifiedCurrentSoftmx = qualifiedSize(currentSoftmx);
/* If qualifiedSize() returns size in bytes, it could not
* convert the value, so print the initialSoftmx variable in
* bytes
*/
m = p.matcher(qualifiedCurrentSoftmx);
if (!m.matches()) {
initialSoftmx = sizeInBytes(initialSoftmx);
}
} else {
/* InitialSoftmx value has either not been set or is in byte
* form, so print current value as byte form
*/
qualifiedCurrentSoftmx = currentSoftmx.toString();
}
printTableOfEqualSpacedColumns(out, new String[] { "name", "initial value", "current value" }, new String[][] { { "-Xsoftmx", initialSoftmx, qualifiedCurrentSoftmx } });
} catch (DataUnavailable e) {
/* For Z/OS core files, command line is not available */
out.println("COMMANDLINE is not available\n");
} catch (com.ibm.dtfj.image.CorruptDataException e) {
throw new DDRInteractiveCommandException("CorruptDataException occured while getting the commandline from process");
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.
the class NativeMemInfoCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
this.out = out;
try {
Iterator<? extends OMRMemCategoryPointer> categories = MemoryCategoryIterator.iterateCategoryRootSet(DTFJContext.getVm().portLibrary());
while (categories.hasNext()) {
OMRMemCategoryPointer next = categories.next();
printSections(next, 0);
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.
the class ShrCCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
if (!J9BuildFlags.opt_sharedClasses) {
CommandUtils.dbgPrint(out, "no shared cache\n");
return;
}
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
J9SharedClassConfigPointer sharedClassConfig = vm.sharedClassConfig();
CommandUtils.dbgPrint(out, "!j9sharedclassconfig %s\n\n", sharedClassConfig.getHexAddress());
if (args.length == 0) {
printHelp(out);
} else if (sharedClassConfig.notNull()) {
U8Pointer metaStartInCache = getSharedCacheMetadataStart(vm, out);
U8Pointer metaEndInCache = getSharedCacheMetadataEnd(vm, out);
U8Pointer metaStart = metaStartInCache;
U8Pointer metaEnd = metaEndInCache;
initTotalCacheSize(out, sharedClassConfig);
/* check if the first parameter specifies the range of metadata region to be used */
if (args.length > 1) {
/* Presence of '..' indicates user specified the range */
if (args[1].indexOf(rangeDelim) != -1) {
String addr;
addr = args[1].substring(0, args[1].indexOf(rangeDelim));
metaStart = U8Pointer.cast(CommandUtils.parsePointer(addr, J9BuildFlags.env_data64));
addr = args[1].substring(args[1].indexOf(rangeDelim) + rangeDelim.length());
metaEnd = U8Pointer.cast(CommandUtils.parsePointer(addr, J9BuildFlags.env_data64));
}
}
if (metaStart != null && metaStart.longValue() < metaStartInCache.longValue()) {
CommandUtils.dbgPrint(out, "User specified start boundary is before metadata start in cache\n");
metaStart = metaStartInCache;
}
if (metaEnd != null && metaEnd.longValue() > metaEndInCache.longValue()) {
CommandUtils.dbgPrint(out, "User specified end boundary is beyond metadata end in cache\n");
metaEnd = metaEndInCache;
}
if (metaStart != null && metaEnd != null && metaEnd.longValue() < metaStart.longValue()) {
CommandUtils.dbgPrint(out, "User specified metadata region boundary is not valid. Ensure 'end' > 'start'\n");
return;
}
CommandUtils.dbgPrint(out, "Meta data region to be used: %s..%s\n", metaStart.getHexAddress(), metaEnd.getHexAddress());
if (args[0].equals("allstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, ALL_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("rcstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, ROMCLASS_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("cpstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, CLASSPATH_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("aotstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, AOT_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("invaotstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, INV_AOT_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("orphanstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, ORPHAN_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("scopestats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, SCOPE_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("bytestats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, BYTE_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("ubytestats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, UNINDEXED_BYTE_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("clstats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, CACHELET_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("stalestats")) {
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, ALL_STALE_STATS, null, false, VoidPointer.NULL, false);
} else if (args[0].equals("classpath")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc classpath <address>\n");
} else {
long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintClasspath(out, ClasspathWrapperPointer.cast(address));
}
} else if (args[0].equals("findclass")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findclass <name>\n");
} else {
String className = args[1];
CommandUtils.dbgPrint(out, "Looking for class \"%s\"\n", className);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, ROMCLASS_STATS | ORPHAN_STATS, className, false, VoidPointer.NULL, false);
}
} else if (args[0].equals("findclassp")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findclassp <name>\n");
} else {
String className = args[1];
CommandUtils.dbgPrint(out, "Looking for class prefix \"%s\"\n", className);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, ROMCLASS_STATS | ORPHAN_STATS, className, true, VoidPointer.NULL, false);
}
} else if (args[0].equals("findaot")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findaot <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for AOT method \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, AOT_STATS | INV_AOT_STATS, methodName, false, VoidPointer.NULL, false);
}
} else if (args[0].equals("findaotp")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findaot <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for AOT method prefix \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, AOT_STATS | INV_AOT_STATS, methodName, true, VoidPointer.NULL, false);
}
} else if (args[0].equals("aotfor")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc aotfor <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, AOT_STATS | INV_AOT_STATS, null, true, VoidPointer.cast(addr), false);
}
} else if (args[0].equals("rcfor")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc rcfor <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, ROMCLASS_STATS | ORPHAN_STATS, null, false, VoidPointer.cast(addr), false);
}
} else if (args[0].equals("incache")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc incache <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcInCache(out, vm, sharedClassConfig, VoidPointer.cast(addr));
}
} else if (args[0].equals("stats")) {
if (sharedClassConfig.notNull()) {
dbgShrcInCache(out, vm, sharedClassConfig, VoidPointer.NULL);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, 0, null, false, VoidPointer.NULL, false);
}
} else if (args[0].equals("method")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc method <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, FIND_METHOD, null, false, VoidPointer.cast(addr), false);
}
} else if (args[0].equals("cachelet")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc incache <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintCachelet(out, CacheletWrapperPointer.cast(addr));
}
/**
* JIT profiling data
*/
} else if (args[0].equals("jitpstats")) {
if (sharedClassConfig.notNull()) {
dbgShrcInCache(out, vm, sharedClassConfig, VoidPointer.NULL);
boolean corrupt = (args.length > 1) && "corrupt".equals(args[1]);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, JITPROFILE_STATS, null, false, VoidPointer.NULL, corrupt);
}
} else if (args[0].equals("findjitp")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findjitp <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for JIT PROFILE method \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITPROFILE_STATS, methodName, false, VoidPointer.NULL, false);
}
} else if (args[0].equals("findjitpp")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findjitpp <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for JIT PROFILE method prefix \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITPROFILE_STATS, methodName, true, VoidPointer.NULL, false);
}
} else if (args[0].equals("jitpfor")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc jitpfor <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITPROFILE_STATS, null, false, VoidPointer.cast(addr), false);
}
/**
* JIT hints
*/
} else if (args[0].equals("jithstats")) {
if (sharedClassConfig.notNull()) {
dbgShrcInCache(out, vm, sharedClassConfig, VoidPointer.NULL);
boolean corrupt = (args.length > 1) && "corrupt".equals(args[1]);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStart, metaEnd, JITHINT_STATS, null, false, VoidPointer.NULL, corrupt);
}
} else if (args[0].equals("findjith")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findjith <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for JIT HINT method \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITHINT_STATS, methodName, false, VoidPointer.NULL, false);
}
} else if (args[0].equals("findjithp")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc findjithp <name>\n");
} else {
String methodName = args[1];
CommandUtils.dbgPrint(out, "Looking for JIT HINT method prefix \"%s\"\n", methodName);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITHINT_STATS, methodName, true, VoidPointer.NULL, false);
}
} else if (args[0].equals("jithfor")) {
if (args.length != 2) {
CommandUtils.dbgPrint(out, "Usage: !shrc jithfor <address>\n");
} else {
long addr = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
dbgShrcPrintAllStats(out, vm, sharedClassConfig, metaStartInCache, metaEndInCache, JITHINT_STATS, null, false, VoidPointer.cast(addr), false);
}
} else if (args[0].equals("rtflags")) {
if (sharedClassConfig.notNull()) {
U64 runtimeFlags = sharedClassConfig.runtimeFlags();
CommandUtils.dbgPrint(out, "Printing the shared classes runtime flags %s\n", runtimeFlags.getHexValue());
printShCFlags(out, runtimeFlags, "RUNTIMEFLAG");
}
} else if (args[0].equals("extraflags")) {
if (sharedClassConfig.notNull()) {
ShrcConfig config = dbgShrcReadConfig(sharedClassConfig, out);
UDATA extraFlags = config.getCacheStartAddress().extraFlags();
CommandUtils.dbgPrint(out, "Printing the shared classes extra flags present in cache header %s\n", extraFlags.getHexValue());
printShCFlags(out, extraFlags, "EXTRA_FLAGS");
}
} else if (args[0].equals("write")) {
if (args.length != 2 && args.length != 3) {
CommandUtils.dbgPrint(out, "Usage: !shrc write <cachedir> [<cachename>]\n");
} else {
String cacheDir = args[1];
String cacheName = args.length == 3 ? args[2] : null;
try {
dbgShrcWriteCache(out, sharedClassConfig, cacheDir, cacheName);
} catch (CorruptDataException e) {
/* retry writing only populated areas of cache */
CommandUtils.dbgPrint(out, "Unable to write complete cache: %s", e.getMessage());
CommandUtils.dbgPrint(out, "Attempting to write only populated areas of cache.\n");
dbgShrcWriteCacheByAreas(out, sharedClassConfig, cacheDir, cacheName);
}
}
} else if (args[0].equals("name")) {
dbgShrcCacheName(out, sharedClassConfig);
} else {
CommandUtils.dbgPrint(out, "Unknown arg(s) : ");
for (int i = 0; i < args.length; i++) {
CommandUtils.dbgPrint(out, args[i] + " ");
}
CommandUtils.dbgPrint(out, "\nType !shrc to see all the valid options.\n");
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.
the class SnapFormatCommand method run.
/**
* Options should be:
* -f ouputFile
* -t vmthread
* -d .dat file path
*/
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
String fileName = null;
String userDatPath = null;
String userThreadId = null;
String messageFilePath = null;
TraceFilterExpression specFilter = null;
if (args.length == 0) {
// Write formatted trace to the console.
fileName = null;
} else if (args.length == 1) {
fileName = args[0];
} else {
/* Walk the arguments and look for flag/value pairs. */
for (int i = 0; i < args.length - 1; ) {
String flag = args[i++];
String value = args[i++];
if ("-f".equals(flag)) {
fileName = value;
} else if ("-d".equals(flag)) {
userDatPath = value;
} else if ("-t".equals(flag)) {
userThreadId = value;
outputHeader = false;
} else if ("-s".equals(flag)) {
specFilter = TraceFilterExpression.parseExpression(value);
outputHeader = false;
}
}
}
/* Look for message files, search order is:
* - User specified location to this command.
* - as resources located under same class loader as TraceContext
* - current working directory
* - jre/lib for the current jre
*/
boolean foundDatFiles = false;
if (userDatPath != null) {
int i = 0;
for (String name : MESSAGEFILENAMES) {
File f = new File(userDatPath + File.separator + name);
if (!f.exists()) {
out.printf("Error locating .dat file %s on user path %s\n", name, userDatPath);
return;
} else {
try {
messageFiles[i++] = new FileInputStream(f);
foundDatFiles = true;
} catch (FileNotFoundException e) {
// We've done f.exists(), this should be fine.
// foundDatFiles will be false if not.
}
}
}
} else {
int i = 0;
String[] messageFileStrings = new String[MESSAGEFILENAMES.length];
for (String name : MESSAGEFILENAMES) {
InputStream s = TraceContext.class.getResourceAsStream('/' + name);
if (null != s) {
messageFileStrings[i] = TraceContext.class.getResource('/' + name).toString();
messageFiles[i++] = s;
foundDatFiles = true;
}
}
if (foundDatFiles) {
out.printf("Formatting trace using format dat files from %s and %s\n", messageFileStrings[0], messageFileStrings[1]);
} else {
for (String path : DEFAULTMESSAGEFILEPATHS) {
for (String name : MESSAGEFILENAMES) {
File f = new File(path + File.separator + name);
if (f.exists()) {
try {
messageFiles[i++] = new FileInputStream(f);
foundDatFiles = true;
} catch (FileNotFoundException e) {
// We've done f.exists(), this should be fine.
// foundDatFiles will be false if not.
}
}
}
if (foundDatFiles) {
messageFilePath = path;
out.printf("Formatting trace using format dat files from %s and %s from %s\n", MESSAGEFILENAMES[0], MESSAGEFILENAMES[1], messageFilePath);
break;
}
}
}
if (!foundDatFiles) {
out.printf("Unable to find %s and %s in %s or %s\n", MESSAGEFILENAMES[0], MESSAGEFILENAMES[1], DEFAULTMESSAGEFILEPATHS[0], DEFAULTMESSAGEFILEPATHS[1]);
return;
}
}
if (outputHeader) {
extractTraceData(context, out);
} else {
extractTraceData(context, dummyOut);
}
if (traceContext == null) {
out.println("Unable to create trace context, command failed.");
return;
}
long threadId = 0;
if (userThreadId != null) {
boolean is64BitPlatform = (context.process.bytesPerPointer() == 8) ? true : false;
threadId = CommandUtils.parsePointer(userThreadId, is64BitPlatform);
}
/* Create the stream to write the trace to.
* The specified output file or "out" if we
* are writing to the console.
* (Do this last so we have less cases where we
* need to exit for an error and close the printstream.)
*/
PrintStream traceOut = out;
PrintStream filePrintStream = null;
if (fileName != null) {
try {
filePrintStream = new PrintStream(fileName);
traceOut = filePrintStream;
} catch (FileNotFoundException e) {
out.printf("Unable to write formatted trace to file %s\n", fileName);
}
}
if (outputHeader) {
traceOut.println(traceContext.summary());
}
try {
Iterator<TracePoint> tpIterator = null;
if (userThreadId != null) {
Iterator<TraceThread> threadsIterator = (Iterator<TraceThread>) traceContext.getThreads();
boolean foundThread = false;
while (threadsIterator.hasNext()) {
TraceThread thread = threadsIterator.next();
if (thread.getThreadID() == threadId) {
foundThread = true;
tpIterator = (Iterator<TracePoint>) thread.getIterator();
}
}
if (!foundThread) {
out.printf("Unable to find thread %s in trace data\n", userThreadId);
}
} else {
tpIterator = (Iterator<TracePoint>) traceContext.getTracepoints();
}
if (tpIterator != null) {
int tpCount = printTracePoints(traceOut, tpIterator, specFilter);
out.printf("Completed processing of %d tracepoints with %d warnings and %d errors\n", traceContext.getTotalTracePoints(), traceContext.getWarningCount(), traceContext.getErrorCount());
}
} catch (Exception e) {
e.printStackTrace();
}
if (filePrintStream != null) {
out.println("Snap trace written to: " + fileName);
filePrintStream.close();
}
}
Aggregations