Debugger.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.data.util;
00002
00003 public class Debugger {
00004
00005 final static int MAX_TRACES = 8;
00006 final static int MIN_TRACES = 2;
00007
00008 final static private String MSG_HEADER = "[hpctr] ";
00009 static private int debugLevel = 0;
00010
00011
00012 static private int timeCorrection = 976023;
00013 private static final boolean printTimeDebugMessages = false;
00014
00015
00016
00017
00018
00019 static public void printTrace(String str) {
00020 if (debugLevel > 0)
00021 {
00022 System.out.print(str + ":\t");
00023 Throwable t = new Throwable();
00024 StackTraceElement traces[] = t.getStackTrace();
00025 for (int i=MIN_TRACES; i<MAX_TRACES; i++) {
00026 System.out.println("\t" + traces[i]);
00027 }
00028 }
00029 }
00030
00031
00032
00033
00034
00035
00036 static public void setDebugLevel(int level) {
00037 debugLevel = level;
00038 System.out.println(MSG_HEADER +"Set debug level: " + level);
00039 }
00040
00041
00042
00043
00044
00045 static public int getDebugLevel() {
00046 return debugLevel;
00047 }
00048
00054 static public void checkArgDebug(String args[]) {
00055 boolean debugFlag = false;
00056
00057 for (String arg: args) {
00058 if (!debugFlag && arg.compareTo("-g")==0) {
00059 debugFlag = true;
00060 } else if (debugFlag) {
00061 int level = Integer.valueOf(arg);
00062 setDebugLevel( level );
00063 }
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 static public void printDebug( int level, String msg ) {
00074 if (debugLevel > level)
00075 System.out.println( MSG_HEADER + msg);
00076 }
00077
00078 public static void printTimestampDebug(String msg) {
00079 long t = System.nanoTime();
00080 if(printTimeDebugMessages) {
00081 System.out.println((t/1000 + timeCorrection) + "\t" + msg);
00082 }
00083
00084 }
00085 }