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     //Set to negative of what client says
00012     static private int timeCorrection = 976023; //in microseconds
00013     private static final boolean printTimeDebugMessages = false;
00014     /***
00015      * print the call stack debugging info
00016      * 
00017      * @param str
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      * set a new debug level
00033      * 
00034      * @param level
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      * return the current debug level (set by user)
00043      * @return
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      * synchronously output the debugging message if it exceeds certain level
00069      * 
00070      * @param level: minimum debug level 
00071      * @param msg
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 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1