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
.request
.ITmfEventRequest
;
13 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignal
;
15 @SuppressWarnings("nls")
18 private static String pluginID
= TmfCorePlugin
.PLUGIN_ID
;
20 static Boolean ERROR
= Boolean
.FALSE
;
21 static Boolean WARNING
= Boolean
.FALSE
;
22 static Boolean INFO
= Boolean
.FALSE
;
24 static Boolean COMPONENT
= Boolean
.FALSE
;
25 static Boolean REQUEST
= Boolean
.FALSE
;
26 static Boolean SIGNAL
= Boolean
.FALSE
;
27 static Boolean EVENT
= Boolean
.FALSE
;
29 private static String LOGNAME
= "trace.log";
30 private static BufferedWriter fTraceLog
= null;
32 private static BufferedWriter
openLogFile(String filename
) {
33 BufferedWriter outfile
= null;
35 outfile
= new BufferedWriter(new FileWriter(filename
));
36 } catch (IOException e
) {
42 public static void init() {
45 boolean isTracing
= false;
47 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
48 if (traceKey
!= null) {
49 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
53 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
54 if (traceKey
!= null) {
55 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
59 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
60 if (traceKey
!= null) {
61 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
65 traceKey
= Platform
.getDebugOption(pluginID
+ "/component");
66 if (traceKey
!= null) {
67 COMPONENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
68 isTracing
|= COMPONENT
;
71 traceKey
= Platform
.getDebugOption(pluginID
+ "/request");
72 if (traceKey
!= null) {
73 REQUEST
= (Boolean
.valueOf(traceKey
)).booleanValue();
77 traceKey
= Platform
.getDebugOption(pluginID
+ "/signal");
78 if (traceKey
!= null) {
79 SIGNAL
= (Boolean
.valueOf(traceKey
)).booleanValue();
83 traceKey
= Platform
.getDebugOption(pluginID
+ "/event");
84 if (traceKey
!= null) {
85 EVENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
89 // Create trace log file if needed
91 fTraceLog
= openLogFile(LOGNAME
);
95 public static void stop() {
96 if (fTraceLog
== null)
102 } catch (IOException e
) {
108 public static boolean isErrorTraced() {
112 public static boolean isComponentTraced() {
116 public static boolean isRequestTraced() {
120 public static boolean isSignalTraced() {
124 public static boolean isEventTraced() {
129 public static void trace(String msg
) {
130 long currentTime
= System
.currentTimeMillis();
131 StringBuilder message
= new StringBuilder("[");
132 message
.append(currentTime
/ 1000);
134 message
.append(String
.format("%1$03d", currentTime
% 1000));
135 message
.append("] ");
137 // System.out.println(message);
139 if (fTraceLog
!= null) {
141 fTraceLog
.write(message
.toString());
144 } catch (IOException e
) {
150 public static void traceComponent(ITmfComponent component
, String msg
) {
151 String message
= ("[CMP] Thread=" + Thread
.currentThread().getId() + " Cmp=" + component
.getName() + " " + msg
);
155 public static void traceRequest(ITmfDataRequest
<?
> request
, String msg
) {
156 String message
= ("[REQ] Req=" + request
.getRequestId()
157 + (request
.getExecType() == ITmfDataRequest
.ExecutionType
.BACKGROUND ?
" (BG)" : " (FG)") + " Thread="
158 + Thread
.currentThread().getId() + " Type=" + simpleType(request
.getClass().getName()) + " Index="
159 + request
.getIndex() + " NbReq=" + request
.getNbRequested()
160 + (request
instanceof ITmfEventRequest ?
" Range=" + ((ITmfEventRequest
<?
>) request
).getRange() : "")
161 + " DataType=" + request
.getDataType().getSimpleName() + " " + msg
);
165 private static String
simpleType(String type
) {
166 return type
.substring(type
.lastIndexOf('.') + 1);
169 public static void traceSignal(TmfSignal signal
, String msg
) {
170 String message
= ("[SIG] Type=" + signal
.getClass().getSimpleName() + " Target=" + msg
);
174 public static void traceEvent(ITmfDataProvider
<?
> provider
, ITmfDataRequest
<?
> request
, TmfData data
) {
175 String message
= ("[EVT] Provider=" + provider
.toString() + ", Req=" + request
.getRequestId() + ", Event=" + data
180 public static void traceError(String msg
) {
181 String message
= ("[ERR] Thread=" + Thread
.currentThread().getId() + " " + msg
);
185 public static void traceInfo(String msg
) {
186 String message
= ("[INF] Thread=" + Thread
.currentThread().getId() + " " + msg
);
This page took 0.035591 seconds and 5 git commands to generate.