TMF: Add tracing capabilities for analyses
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 4 Dec 2014 03:53:03 +0000 (22:53 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 23 Dec 2014 16:41:52 +0000 (11:41 -0500)
Change-Id: Ic8eede9defc25eb604bb453f8d1efde7608a85f2
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/37599
Reviewed-by: Hudson CI
org.eclipse.tracecompass.tmf.core/.options
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/TmfCoreTracer.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAbstractAnalysisModule.java

index f9f9e5dcb21f1145c762511fdb847869fb43326f..6cb8da2da4dc04f72c52ebea6fd6db10b993906a 100644 (file)
@@ -2,3 +2,4 @@ org.eclipse.tracecompass.tmf.core/component=false
 org.eclipse.tracecompass.tmf.core/request=false
 org.eclipse.tracecompass.tmf.core/signal=false
 org.eclipse.tracecompass.tmf.core/event=false
+org.eclipse.tracecompass.tmf.core/analysis=false
index 23d62ee8cfa6f697d3e4ad78fbf2e05baad35d6c..f29f8b7d7f81736212acc4d599a775d55ad5a2bb 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
 /**
  * The TMF Core tracer, used to trace TMF internal components.
@@ -35,6 +36,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
  * <li><strong>Request</strong>: TMF requests life-cycle
  * <li><strong>Signal</strong>: TMF signals triggering and distribution
  * <li><strong>Event</strong>: TMF trace events
+ * <li><strong>Analysis</strong>: TMF analyzes
  * </ul>
  *
  * @version 1.0
@@ -54,6 +56,7 @@ public class TmfCoreTracer {
     private static final String REQUEST_TRACE_KEY   = PLUGIN_ID + "/request";
     private static final String SIGNAL_TRACE_KEY    = PLUGIN_ID + "/signal";
     private static final String EVENT_TRACE_KEY     = PLUGIN_ID + "/event";
+    private static final String ANALYSIS_TRACE_KEY     = PLUGIN_ID + "/analysis";
 
     private static final String TRACE_FILE_NAME = "TmfTrace.log";
 
@@ -66,6 +69,7 @@ public class TmfCoreTracer {
     static boolean REQUEST_CLASS_ENABLED   = false;
     static boolean SIGNAL_CLASS_ENABLED    = false;
     static boolean EVENT_CLASS_ENABLED     = false;
+    static boolean ANALYSIS_CLASS_ENABLED     = false;
 
     // Trace log file
     private static BufferedWriter fTraceFile;
@@ -106,6 +110,12 @@ public class TmfCoreTracer {
             isTracing |= EVENT_CLASS_ENABLED;
         }
 
+        traceKey = Platform.getDebugOption(ANALYSIS_TRACE_KEY);
+        if (traceKey != null) {
+            ANALYSIS_CLASS_ENABLED = (Boolean.valueOf(traceKey)).booleanValue();
+            isTracing |= ANALYSIS_CLASS_ENABLED;
+        }
+
         // Create trace log file if any of the flags was set
         if (isTracing) {
             try {
@@ -155,15 +165,21 @@ public class TmfCoreTracer {
         return EVENT_CLASS_ENABLED;
     }
 
+    @SuppressWarnings("javadoc")
+    public static boolean isAnalysisTraced() {
+        return ANALYSIS_CLASS_ENABLED;
+    }
+
     // ------------------------------------------------------------------------
     // Tracing methods
     // ------------------------------------------------------------------------
 
     /**
-     * The central tracing method. Prepends the timestamp and the thread id
-     * to the trace message.
+     * The central tracing method. Prepends the timestamp and the thread id to
+     * the trace message.
      *
-     * @param msg the trace message to log
+     * @param msg
+     *            the trace message to log
      */
     public static synchronized void trace(String msg) {
         // Leave when there is no place to write the message.
@@ -249,4 +265,22 @@ public class TmfCoreTracer {
         }
     }
 
+    /**
+     * Trace an event happening in an analysis
+     *
+     * @param analysisId
+     *            The analysis ID of the analysis being run
+     * @param trace
+     *            The trace this analysis is run on
+     * @param msg
+     *            The message to record for this analysis
+     */
+    public static void traceAnalysis(String analysisId, ITmfTrace trace, String msg) {
+        if (ANALYSIS_CLASS_ENABLED) {
+            String traceName = (trace == null) ? "" : trace.getName();
+            String message = ("[ANL] Anl=" + analysisId + " for " + traceName + " " + msg);
+            trace(message);
+        }
+    }
+
 }
index c85f589926cac683357a7f14b23263dee191c589..e8e225ef5a949ce00a6dfef4d37ed41978136d03 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
 import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
@@ -110,6 +111,8 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
             throw new TmfAnalysisException(NLS.bind(Messages.TmfAbstractAnalysisModule_TraceSetMoreThanOnce, getName()));
         }
 
+        TmfCoreTracer.traceAnalysis(getId(), trace, "setting trace for analysis"); //$NON-NLS-1$
+
         /* Check that analysis can be executed */
         if (!canExecute(trace)) {
             throw new TmfAnalysisException(NLS.bind(Messages.TmfAbstractAnalysisModule_AnalysisCannotExecute, getName()));
@@ -119,6 +122,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
         /* Get the parameter providers for this trace */
         fParameterProviders = TmfAnalysisManager.getParameterProviders(this, trace);
         for (IAnalysisParameterProvider provider : fParameterProviders) {
+            TmfCoreTracer.traceAnalysis(getId(), trace, "registered to parameter provider " + provider.getName()); //$NON-NLS-1$
             provider.registerModule(this);
         }
         resetAnalysis();
@@ -202,6 +206,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
      * Set the countdown latch back to 1 so the analysis can be executed again
      */
     protected void resetAnalysis() {
+        TmfCoreTracer.traceAnalysis(getId(), getTrace(), "reset: ready for execution"); //$NON-NLS-1$
         fFinishedLatch.countDown();
         fFinishedLatch = new CountDownLatch(1);
     }
@@ -231,9 +236,11 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
      * It has to be called inside a synchronized block
      */
     private void setAnalysisCompleted() {
-        fStarted = false;
-        fJob = null;
-        fFinishedLatch.countDown();
+        synchronized (syncObj) {
+            fStarted = false;
+            fJob = null;
+            fFinishedLatch.countDown();
+        }
     }
 
     /**
@@ -242,6 +249,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
     @Override
     public final void cancel() {
         synchronized (syncObj) {
+            TmfCoreTracer.traceAnalysis(getId(), getTrace(), "cancelled by application"); //$NON-NLS-1$
             if (fJob != null) {
                 if (fJob.cancel()) {
                     fAnalysisCancelled = true;
@@ -279,12 +287,14 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
 
         /* Do not execute if analysis has already run */
         if (fFinishedLatch.getCount() == 0) {
+            TmfCoreTracer.traceAnalysis(getId(), getTrace(), "already executed"); //$NON-NLS-1$
             return;
         }
 
         /* Do not execute if analysis already running */
         synchronized (syncObj) {
             if (fStarted) {
+                TmfCoreTracer.traceAnalysis(getId(), getTrace(), "already started, not starting again"); //$NON-NLS-1$
                 return;
             }
             fStarted = true;
@@ -310,10 +320,12 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
                 try {
                     mon.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
                     broadcast(new TmfStartAnalysisSignal(TmfAbstractAnalysisModule.this, TmfAbstractAnalysisModule.this));
+                    TmfCoreTracer.traceAnalysis(TmfAbstractAnalysisModule.this.getId(), TmfAbstractAnalysisModule.this.getTrace(), "started"); //$NON-NLS-1$
                     fAnalysisCancelled = !executeAnalysis(mon);
                     for (IAnalysisModule module : dependentAnalyses) {
                         module.waitForCompletion(mon);
                     }
+                    TmfCoreTracer.traceAnalysis(TmfAbstractAnalysisModule.this.getId(), TmfAbstractAnalysisModule.this.getTrace(), "finished"); //$NON-NLS-1$
                 } catch (TmfAnalysisException e) {
                     Activator.logError("Error executing analysis with trace " + trace.getName(), e); //$NON-NLS-1$
                 } finally {
@@ -333,6 +345,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
 
             @Override
             protected void canceling() {
+                TmfCoreTracer.traceAnalysis(getId(), getTrace(), "job cancelled"); //$NON-NLS-1$
                 TmfAbstractAnalysisModule.this.canceling();
             }
 
@@ -347,6 +360,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
             if (trace == null) {
                 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, String.format("No trace specified for analysis %s", getName())); //$NON-NLS-1$
             }
+            TmfCoreTracer.traceAnalysis(getId(), getTrace(), "scheduled"); //$NON-NLS-1$
             execute(trace);
         }
 
This page took 0.033183 seconds and 5 git commands to generate.