summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorEtienne Bergeron2013-11-14 23:17:37 (EST)
committer Alexandre Montplaisir2013-11-21 18:07:38 (EST)
commitd7543438d14047efbd421a4d88c0f6707ca2ba1a (patch)
treead27d30968b810ce0c495b9ce7f9a1d1f1fe0c38
parentede747157e0e0a1320c45e13e7d4b6fdd9967be3 (diff)
downloadorg.eclipse.linuxtools-d7543438d14047efbd421a4d88c0f6707ca2ba1a.zip
org.eclipse.linuxtools-d7543438d14047efbd421a4d88c0f6707ca2ba1a.tar.gz
org.eclipse.linuxtools-d7543438d14047efbd421a4d88c0f6707ca2ba1a.tar.bz2
Shortcut string creation in tracing functions.refs/changes/53/18453/3
This quick fix avoid useless creation of the message to be logged when tracing isn't enabled. Change-Id: If1a667451c59afa67e25572f598e0826ce92f090 Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com> Reviewed-on: https://git.eclipse.org/r/18453 Reviewed-by: Fran├žois Doray <fdoray.eclipse@gmail.com> Tested-by: Hudson CI IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java18
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/TmfUiTracer.java19
2 files changed, 21 insertions, 16 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java
index ae529c6..e4a57a7 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java
@@ -167,6 +167,10 @@ public class TmfCoreTracer {
* @param msg the trace message to log
*/
public static synchronized void trace(String msg) {
+ // Leave when there is no place to write the message.
+ if (fTraceFile == null) {
+ return;
+ }
// Set the timestamp (ms resolution)
long currentTime = System.currentTimeMillis();
@@ -185,14 +189,12 @@ public class TmfCoreTracer {
message.append(msg);
// Write to file
- if (fTraceFile != null) {
- try {
- fTraceFile.write(message.toString());
- fTraceFile.newLine();
- fTraceFile.flush();
- } catch (IOException e) {
- Activator.logError("Error writing to log file", e);
- }
+ try {
+ fTraceFile.write(message.toString());
+ fTraceFile.newLine();
+ fTraceFile.flush();
+ } catch (IOException e) {
+ Activator.logError("Error writing to log file", e);
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/TmfUiTracer.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/TmfUiTracer.java
index 8ed4889..0e95b5f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/TmfUiTracer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/TmfUiTracer.java
@@ -154,6 +154,11 @@ public class TmfUiTracer {
* The event's message
*/
public static void trace(String msg) {
+ // Leave when there is no place to write the message.
+ if (fTraceLog == null) {
+ return;
+ }
+
long currentTime = System.currentTimeMillis();
StringBuilder message = new StringBuilder("[");
message.append(currentTime / 1000);
@@ -162,14 +167,12 @@ public class TmfUiTracer {
message.append("] ");
message.append(msg);
- if (fTraceLog != null) {
- try {
- fTraceLog.write(message.toString());
- fTraceLog.newLine();
- fTraceLog.flush();
- } catch (IOException e) {
- Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$
- }
+ try {
+ fTraceLog.write(message.toString());
+ fTraceLog.newLine();
+ fTraceLog.flush();
+ } catch (IOException e) {
+ Activator.getDefault().logError("Error writing to log file " + LOGNAME, e); //$NON-NLS-1$
}
}