1 package org
.eclipse
.linuxtools
.tmf
;
3 import java
.io
.BufferedWriter
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
7 import org
.eclipse
.core
.runtime
.Platform
;
8 import org
.eclipse
.linuxtools
.tmf
.component
.ITmfComponent
;
9 import org
.eclipse
.linuxtools
.tmf
.component
.ITmfDataProvider
;
10 import org
.eclipse
.linuxtools
.tmf
.event
.TmfData
;
11 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
;
12 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignal
;
14 @SuppressWarnings("nls")
17 private static String pluginID
= TmfCorePlugin
.PLUGIN_ID
;
19 static Boolean ERROR
= Boolean
.FALSE
;
20 static Boolean WARNING
= Boolean
.FALSE
;
21 static Boolean INFO
= Boolean
.FALSE
;
23 static Boolean COMPONENT
= Boolean
.FALSE
;
24 static Boolean REQUEST
= Boolean
.FALSE
;
25 static Boolean SIGNAL
= Boolean
.FALSE
;
26 static Boolean EVENT
= Boolean
.FALSE
;
28 private static String LOGNAME
= "trace.log";
29 private static BufferedWriter fTraceLog
= null;
31 private static BufferedWriter
openLogFile(String filename
) {
32 BufferedWriter outfile
= null;
34 outfile
= new BufferedWriter(new FileWriter(filename
));
35 } catch (IOException e
) {
41 public static void init() {
44 boolean isTracing
= false;
46 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
47 if (traceKey
!= null) {
48 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
52 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
53 if (traceKey
!= null) {
54 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
58 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
59 if (traceKey
!= null) {
60 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
64 traceKey
= Platform
.getDebugOption(pluginID
+ "/component");
65 if (traceKey
!= null) {
66 COMPONENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
67 isTracing
|= COMPONENT
;
70 traceKey
= Platform
.getDebugOption(pluginID
+ "/request");
71 if (traceKey
!= null) {
72 REQUEST
= (Boolean
.valueOf(traceKey
)).booleanValue();
76 traceKey
= Platform
.getDebugOption(pluginID
+ "/signal");
77 if (traceKey
!= null) {
78 SIGNAL
= (Boolean
.valueOf(traceKey
)).booleanValue();
82 traceKey
= Platform
.getDebugOption(pluginID
+ "/event");
83 if (traceKey
!= null) {
84 EVENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
88 // Create trace log file if needed
90 fTraceLog
= openLogFile(LOGNAME
);
94 public static void stop() {
95 if (fTraceLog
== null)
101 } catch (IOException e
) {
107 public static boolean isErrorTraced() {
111 public static boolean isComponentTraced() {
115 public static boolean isRequestTraced() {
119 public static boolean isSignalTraced() {
123 public static boolean isEventTraced() {
128 public static void trace(String msg
) {
129 long currentTime
= System
.currentTimeMillis();
130 StringBuilder message
= new StringBuilder("[");
131 message
.append(currentTime
/ 1000);
133 message
.append(String
.format("%1$03d", currentTime
% 1000));
134 message
.append("] ");
136 // System.out.println(message);
138 if (fTraceLog
!= null) {
140 fTraceLog
.write(message
.toString());
143 } catch (IOException e
) {
149 public static void traceComponent(ITmfComponent component
, String msg
) {
150 String message
= ("[CMP] Thread=" + Thread
.currentThread().getId() + " Cmp=" + component
.getName() + " " + msg
);
154 public static void traceRequest(ITmfDataRequest
<?
> request
, String msg
) {
155 String message
= ("[REQ] Req=" + request
.getRequestId() +
156 (request
.getExecType() == ITmfDataRequest
.ExecutionType
.BACKGROUND ?
" (BG)" : " (FG)") +
157 " Thread=" + Thread
.currentThread().getId() +
158 " Type=" + request
.getClass().getName() +
159 " DataType=" + request
.getDataType().getSimpleName() + " " + msg
);
163 public static void traceSignal(TmfSignal signal
, String msg
) {
164 String message
= ("[SIG] Type=" + signal
.getClass().getSimpleName() + " Target=" + msg
);
168 public static void traceEvent(ITmfDataProvider
<?
> provider
, ITmfDataRequest
<?
> request
, TmfData data
) {
169 String message
= ("[EVT] Provider=" + provider
.toString() + ", Req=" + request
.getRequestId() + ", Event=" + data
.toString());
173 public static void traceError(String msg
) {
174 String message
= ("[ERR] Thread=" + Thread
.currentThread().getId() + " " + msg
);
178 public static void traceInfo(String msg
) {
179 String message
= ("[INF] Thread=" + Thread
.currentThread().getId() + " " + msg
);
This page took 0.035765 seconds and 6 git commands to generate.