27d25c3e530b276b95aee0d7dc641d73b7eafbe8
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
;
13 @SuppressWarnings("nls")
16 private static String pluginID
= TmfCorePlugin
.PLUGIN_ID
;
18 static Boolean ERROR
= Boolean
.FALSE
;
19 static Boolean WARNING
= Boolean
.FALSE
;
20 static Boolean INFO
= Boolean
.FALSE
;
22 static Boolean COMPONENT
= Boolean
.FALSE
;
23 static Boolean REQUEST
= Boolean
.FALSE
;
24 static Boolean SIGNAL
= Boolean
.FALSE
;
25 static Boolean EVENT
= Boolean
.FALSE
;
27 private static String LOGNAME
= "trace.log";
28 private static BufferedWriter fTraceLog
= null;
30 private static BufferedWriter
openLogFile(String filename
) {
31 BufferedWriter outfile
= null;
33 outfile
= new BufferedWriter(new FileWriter(filename
));
34 } catch (IOException e
) {
40 public static void init() {
43 boolean isTracing
= false;
45 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
46 if (traceKey
!= null) {
47 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
51 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
52 if (traceKey
!= null) {
53 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
57 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
58 if (traceKey
!= null) {
59 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
63 traceKey
= Platform
.getDebugOption(pluginID
+ "/component");
64 if (traceKey
!= null) {
65 COMPONENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
66 isTracing
|= COMPONENT
;
69 traceKey
= Platform
.getDebugOption(pluginID
+ "/request");
70 if (traceKey
!= null) {
71 REQUEST
= (Boolean
.valueOf(traceKey
)).booleanValue();
75 traceKey
= Platform
.getDebugOption(pluginID
+ "/signal");
76 if (traceKey
!= null) {
77 SIGNAL
= (Boolean
.valueOf(traceKey
)).booleanValue();
81 traceKey
= Platform
.getDebugOption(pluginID
+ "/event");
82 if (traceKey
!= null) {
83 EVENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
87 // Create trace log file if needed
89 fTraceLog
= openLogFile(LOGNAME
);
93 public static void stop() {
94 if (fTraceLog
== null)
100 } catch (IOException e
) {
106 public static boolean isErrorTraced() {
110 public static boolean isComponentTraced() {
114 public static boolean isRequestTraced() {
118 public static boolean isEventTraced() {
123 public static void trace(String msg
) {
124 long currentTime
= System
.currentTimeMillis();
125 StringBuilder message
= new StringBuilder("[");
126 message
.append(currentTime
/ 1000);
128 message
.append(currentTime
% 1000);
129 message
.append("] ");
131 // System.out.println(message);
133 if (fTraceLog
!= null) {
135 fTraceLog
.write(message
.toString());
138 } catch (IOException e
) {
144 public static void traceComponent(ITmfComponent component
, String msg
) {
145 String message
= ("[CMP] Thread=" + Thread
.currentThread().getId() + " Cmp=" + component
.getName() + " " + msg
);
149 public static void traceRequest(ITmfDataRequest
<?
> request
, String msg
) {
150 String message
= ("[REQ] Thread=" + Thread
.currentThread().getId() + " Req=" + request
.getRequestId() +
151 (request
.getExecType() == ITmfDataRequest
.ExecutionType
.BACKGROUND ?
"(BG)" : "(FG)") +
152 ", Type=" + request
.getClass().getName() +
153 ", DataType=" + request
.getDataType().getSimpleName() + " " + msg
);
157 public static void traceEvent(ITmfDataProvider
<?
> provider
, ITmfDataRequest
<?
> request
, TmfData data
) {
158 String message
= ("[EVT] Provider=" + provider
.toString() + ", Req=" + request
.getRequestId() + ", Event=" + data
.toString());
162 public static void traceError(String msg
) {
163 String message
= ("[ERR] Thread=" + Thread
.currentThread().getId() + " " + msg
);
167 public static void traceInfo(String msg
) {
168 String message
= ("[INF] Thread=" + Thread
.currentThread().getId() + " " + msg
);
This page took 0.034682 seconds and 5 git commands to generate.