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
;
15 private static String pluginID
= TmfCorePlugin
.PLUGIN_ID
;
17 static Boolean ERROR
= Boolean
.FALSE
;
18 static Boolean WARNING
= Boolean
.FALSE
;
19 static Boolean INFO
= Boolean
.FALSE
;
21 static Boolean COMPONENT
= Boolean
.FALSE
;
22 static Boolean REQUEST
= Boolean
.FALSE
;
23 static Boolean SIGNAL
= Boolean
.FALSE
;
24 static Boolean EVENT
= Boolean
.FALSE
;
26 private static String LOGNAME
= "trace.log";
27 private static BufferedWriter fTraceLog
= null;
29 private static BufferedWriter
openLogFile(String filename
) {
30 BufferedWriter outfile
= null;
32 outfile
= new BufferedWriter(new FileWriter(filename
));
33 } catch (IOException e
) {
39 public static void init() {
42 boolean isTracing
= false;
44 traceKey
= Platform
.getDebugOption(pluginID
+ "/error");
45 if (traceKey
!= null) {
46 ERROR
= (Boolean
.valueOf(traceKey
)).booleanValue();
50 traceKey
= Platform
.getDebugOption(pluginID
+ "/warning");
51 if (traceKey
!= null) {
52 WARNING
= (Boolean
.valueOf(traceKey
)).booleanValue();
56 traceKey
= Platform
.getDebugOption(pluginID
+ "/info");
57 if (traceKey
!= null) {
58 INFO
= (Boolean
.valueOf(traceKey
)).booleanValue();
62 traceKey
= Platform
.getDebugOption(pluginID
+ "/component");
63 if (traceKey
!= null) {
64 COMPONENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
65 isTracing
|= COMPONENT
;
68 traceKey
= Platform
.getDebugOption(pluginID
+ "/request");
69 if (traceKey
!= null) {
70 REQUEST
= (Boolean
.valueOf(traceKey
)).booleanValue();
74 traceKey
= Platform
.getDebugOption(pluginID
+ "/signal");
75 if (traceKey
!= null) {
76 SIGNAL
= (Boolean
.valueOf(traceKey
)).booleanValue();
80 traceKey
= Platform
.getDebugOption(pluginID
+ "/event");
81 if (traceKey
!= null) {
82 EVENT
= (Boolean
.valueOf(traceKey
)).booleanValue();
86 // Create trace log file if needed
88 fTraceLog
= openLogFile(LOGNAME
);
92 public static void stop() {
93 if (fTraceLog
== null)
99 } catch (IOException e
) {
105 public static boolean isErrorTraced() {
109 public static boolean isComponentTraced() {
113 public static boolean isRequestTraced() {
117 public static boolean isEventTraced() {
122 public static void trace(String msg
) {
123 long currentTime
= System
.currentTimeMillis();
124 StringBuilder message
= new StringBuilder("[");
125 message
.append(currentTime
/ 1000);
127 message
.append(currentTime
% 1000);
128 message
.append("] ");
130 // System.out.println(message);
132 if (fTraceLog
!= null) {
134 fTraceLog
.write(message
.toString());
137 } catch (IOException e
) {
143 public static void traceComponent(ITmfComponent component
, String msg
) {
144 String message
= ("[CMP] Thread=" + Thread
.currentThread().getId() + " Cmp=" + component
.getName() + " " + msg
);
148 public static void traceRequest(ITmfDataRequest
<?
> request
, String msg
) {
149 String message
= ("[REQ] Thread=" + Thread
.currentThread().getId() + " Req=" + request
.getRequestId() +
150 (request
.getExecType() == ITmfDataRequest
.ExecutionType
.BACKGROUND ?
"(BG)" : "(FG)") +
151 ", Type=" + request
.getClass().getName() +
152 ", DataType=" + request
.getDataType().getSimpleName() + " " + msg
);
156 public static void traceEvent(ITmfDataProvider
<?
> provider
, ITmfDataRequest
<?
> request
, TmfData data
) {
157 String message
= ("[EVT] Provider=" + provider
.toString() + ", Req=" + request
.getRequestId() + ", Event=" + data
.toString());
161 public static void traceError(String msg
) {
162 String message
= ("[ERR] Thread=" + Thread
.currentThread().getId() + " " + msg
);
166 public static void traceInfo(String msg
) {
167 String message
= ("[INF] Thread=" + Thread
.currentThread().getId() + " " + msg
);
This page took 0.034737 seconds and 6 git commands to generate.