tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / TraceDebug.java
CommitLineData
638eac44 1package org.eclipse.linuxtools.internal.lttng.ui;\r
6e512b93 2\r
b12f4544 3\r
0c2a2e08
FC
4import java.io.FileWriter;\r
5import java.io.IOException;\r
6import java.io.PrintWriter;\r
6e512b93
ASL
7import java.text.SimpleDateFormat;\r
8import java.util.Date;\r
9\r
10import org.eclipse.core.runtime.ILog;\r
11import org.eclipse.core.runtime.IStatus;\r
12import org.eclipse.core.runtime.Platform;\r
13import org.eclipse.core.runtime.Plugin;\r
14import org.eclipse.core.runtime.Status;\r
15\r
3b38ea61 16@SuppressWarnings("nls")\r
6e512b93 17public class TraceDebug {\r
b12f4544
FC
18 static boolean DEBUG = false;\r
19 static boolean INFO = false;\r
20 static boolean WARN = false;\r
21\r
22 static boolean CFV = false;\r
23 static boolean RV = false;\r
24 static boolean SV = false;\r
25\r
638eac44
FC
26 private static Plugin plugin = Activator.getDefault();\r
27 private static String pluginID = Activator.PLUGIN_ID;\r
b12f4544
FC
28 private static SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss:SSS");\r
29\r
30 // Note: files are created in $HOME\r
31 static private PrintWriter fCFVfile = null;\r
32 static private PrintWriter fRVfile = null;\r
33 static private PrintWriter fSVfile = null;\r
34\r
35 public static void init() {\r
36 // Update Trace configuration options\r
37 String debugTrace = Platform.getDebugOption(pluginID + "/debug");\r
38 String infoTrace = Platform.getDebugOption(pluginID + "/info");\r
39 String warnTrace = Platform.getDebugOption(pluginID + "/warn");\r
40\r
41 if (debugTrace != null) {\r
c6f55e56 42 DEBUG = Boolean.valueOf(debugTrace);\r
b12f4544
FC
43 }\r
44\r
45 if (infoTrace != null) {\r
c6f55e56 46 INFO = Boolean.valueOf(infoTrace);\r
b12f4544
FC
47 }\r
48\r
49 if (warnTrace != null) {\r
c6f55e56 50 WARN = Boolean.valueOf(warnTrace);\r
b12f4544
FC
51 }\r
52\r
53 String cfvTrace = Platform.getDebugOption(pluginID + "/cfv");\r
54 if (cfvTrace != null) {\r
c6f55e56 55 CFV = Boolean.valueOf(cfvTrace);\r
b12f4544
FC
56 if (CFV) {\r
57 try {\r
58 fCFVfile = new PrintWriter(new FileWriter("CFVTrace.txt"));\r
59 } catch (IOException e) {\r
60 e.printStackTrace();\r
61 }\r
62 }\r
63 }\r
64\r
65 String rvTrace = Platform.getDebugOption(pluginID + "/rv");\r
66 if (rvTrace != null) {\r
c6f55e56 67 RV = Boolean.valueOf(rvTrace);\r
b12f4544
FC
68 if (RV) {\r
69 try {\r
70 fRVfile = new PrintWriter(new FileWriter("RVTrace.txt"));\r
71 } catch (IOException e) {\r
72 e.printStackTrace();\r
73 }\r
74 }\r
75 }\r
76\r
77 String svTrace = Platform.getDebugOption(pluginID + "/sv");\r
78 if (svTrace != null) {\r
c6f55e56 79 SV = Boolean.valueOf(svTrace);\r
b12f4544
FC
80 if (SV) {\r
81 try {\r
82 fSVfile = new PrintWriter(new FileWriter("SVTrace.txt"));\r
83 } catch (IOException e) {\r
84 e.printStackTrace();\r
85 }\r
86 }\r
87 }\r
88 }\r
89\r
90 public static void stop() {\r
91 if (fCFVfile != null) {\r
92 fCFVfile.close();\r
93 fCFVfile = null;\r
94 }\r
95\r
96 if (fRVfile != null) {\r
97 fRVfile.close();\r
98 fRVfile = null;\r
99 }\r
100\r
101 if (fSVfile != null) {\r
102 fSVfile.close();\r
103 fSVfile = null;\r
104 }\r
105 }\r
106\r
107 public static void traceCFV(String trace) {\r
108 if (CFV && fCFVfile != null) {\r
109 fCFVfile.println(trace);\r
110 fCFVfile.flush();\r
111 }\r
112 }\r
113\r
114 public static void traceRV(String trace) {\r
115 if (RV && fRVfile != null) {\r
116 fRVfile.println(trace);\r
117 fRVfile.flush();\r
118 }\r
119 }\r
120\r
121 public static void traceSV(String trace) {\r
122 if (SV && fSVfile != null) {\r
123 fSVfile.println(trace);\r
124 fSVfile.flush();\r
125 }\r
126 }\r
127\r
128 public static void info(String message) {\r
129 if (INFO) {\r
130 ILog logger = plugin.getLog();\r
638eac44 131 logger.log(new Status(IStatus.INFO, Activator.PLUGIN_ID, IStatus.OK, message, null));\r
b12f4544
FC
132 }\r
133 }\r
134\r
135 public static void warn(String message) {\r
136 if (WARN) {\r
137 ILog logger = plugin.getLog();\r
638eac44 138 logger.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, IStatus.WARNING, message, null));\r
b12f4544
FC
139 }\r
140 }\r
141\r
142 public static void debug(String message) {\r
143 if (DEBUG) {\r
144 String location = getCallingLocation();\r
145 System.out.println(location + "\n\t-> " + message);\r
146\r
147 }\r
148 }\r
149\r
150 public static void debug(String message, int additionalStackLines) {\r
151 if (DEBUG) {\r
152 String location = getCallingLocation(additionalStackLines);\r
153 System.out.println(location + "\n\t-> " + message);\r
154 }\r
155 }\r
156\r
157 public static void throwException(String message) {\r
158 if (DEBUG) {\r
159 try {\r
160 triggerException(message);\r
161 } catch (Exception e) {\r
162 e.printStackTrace();\r
163 }\r
164 }\r
165 }\r
166\r
167 private static void triggerException(String message) throws Exception {\r
168 throw new Exception(message);\r
169 }\r
170\r
171 private static String getCallingLocation() {\r
172 StringBuilder sb = new StringBuilder();\r
173 sb.append(trace(Thread.currentThread().getStackTrace(), 4));\r
174 sb.append("\n" + trace(Thread.currentThread().getStackTrace(), 3));\r
175 return sb.toString();\r
176 }\r
177\r
178 private static String getCallingLocation(int numOfStackLines) {\r
179 int stackCalledFromIdx = 3;\r
180 int earliestRequested = numOfStackLines > 0 ? stackCalledFromIdx + numOfStackLines : stackCalledFromIdx;\r
181 StringBuilder sb = new StringBuilder();\r
182 for (int i = earliestRequested; i >= stackCalledFromIdx; i--) {\r
183 sb.append(trace(Thread.currentThread().getStackTrace(), i) + "\n");\r
184 }\r
185 return sb.toString();\r
186 }\r
187\r
188 private static String trace(StackTraceElement e[], int level) {\r
189 if (e != null) {\r
190 level = level >= e.length ? e.length - 1 : level;\r
191 StackTraceElement s = e[level];\r
192 if (s != null) {\r
193 String simpleClassName = s.getClassName();\r
194 String[] clsNameSegs = simpleClassName.split("\\.");\r
195 if (clsNameSegs.length > 0)\r
196 simpleClassName = clsNameSegs[clsNameSegs.length - 1];\r
197 return stimeformat.format(new Date()) + " " + simpleClassName + "." + s.getLineNumber() + "." + s.getMethodName();\r
198 }\r
199 }\r
200\r
201 return null;\r
202 }\r
203\r
204 public static boolean isDEBUG() {\r
205 return DEBUG;\r
206 }\r
207\r
208 public static boolean isINFO() {\r
209 return INFO;\r
210 }\r
211\r
212 public static boolean isWARN() {\r
213 return WARN;\r
214 }\r
215\r
216 public static boolean isCFV() {\r
217 return CFV;\r
218 }\r
219\r
220 public static boolean isRV() {\r
221 return RV;\r
222 }\r
223\r
224 public static boolean isSV() {\r
3037adf3
FC
225 return SV;\r
226 }\r
6e512b93 227}\r
This page took 0.046468 seconds and 5 git commands to generate.