X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.ui%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fui%2Fviewers%2Fstatistics%2FTmfStatisticsViewer.java;h=52d782a0fbbf3cc2189cc5f76dae4cfda1932bc6;hb=d6b46913ad62aa237e5c9b76b33e698d893110ed;hp=06264b523b1bb930e5eb428f3ea1c4f778abdb5b;hpb=9d63098b6017602f70baf06255ceaa9410617662;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java index 06264b523b..52d782a0fb 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java @@ -17,6 +17,7 @@ package org.eclipse.linuxtools.tmf.ui.viewers.statistics; import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; @@ -25,7 +26,6 @@ import org.eclipse.linuxtools.tmf.core.component.TmfComponent; import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.core.signal.TmfStatsUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; @@ -42,6 +42,7 @@ import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider; +import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -287,65 +288,6 @@ public class TmfStatisticsViewer extends TmfViewer { requestTimeRangeData(fTrace, timeRange); } - /** - * Whenever a trace's statistics back-end finishes computing the statistics - * for a given interval, it will send the StatsUpdated signal. This method - * will receive this signal and update the statistics view accordingly. - * - * @param sig - * The signal that is received - */ - @TmfSignalHandler - public void statsUpdated(TmfStatsUpdatedSignal sig) { - /* Only handle this signal if it's about the trace we represent. */ - if (!isListeningTo(sig.getTrace())) { - return; - } - - final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID()); - Map map = sig.getEventsPerType(); - String name = sig.getTrace().getName(); - boolean isGlobal = sig.isGlobal(); - - /* - * "Global", "partial", "total", etc., it's all very confusing... - * - * The base view shows the total count for the trace and for - * each even types, organized in columns like this: - * - * | Global | Time range | - * trace name | A | B | - * Event Type | | | - * | C | D | - * | ... | ... | - * ... | | | - * - * Here, we called the cells like this: - * A : GlobalTotal - * B : TimeRangeTotal - * C : GlobalTypeCount(s) - * D : TimeRangeTypeCount(s) - */ - - /* Fill in an the event counts (either cells C or D) */ - for (Map.Entry entry : map.entrySet()) { - statsData.setTypeCount(name, entry.getKey(), isGlobal, entry.getValue()); - } - - /* - * Calculate the totals (cell A or B, depending if isGlobal). We will - * use the results of the previous request instead of sending another - * one. - */ - long globalTotal = 0; - for (long val : map.values()) { - globalTotal += val; - } - statsData.setTotal(name, isGlobal, globalTotal); - - modelComplete(isGlobal); - } - // ------------------------------------------------------------------------ // Class methods // ------------------------------------------------------------------------ @@ -450,6 +392,7 @@ public class TmfStatisticsViewer extends TmfViewer { * * @param request * The request to be canceled + * @since 3.0 */ protected void cancelOngoingRequest(ITmfEventRequest request) { if (request != null && !request.isCompleted()) { @@ -715,7 +658,7 @@ public class TmfStatisticsViewer extends TmfViewer { * Tells if the request is for the global event count or the * partial one. */ - private void buildStatisticsTree(final ITmfTrace trace, TmfTimeRange timeRange, boolean isGlobal) { + private void buildStatisticsTree(final ITmfTrace trace, final TmfTimeRange timeRange, final boolean isGlobal) { final TmfStatisticsTreeNode statTree = TmfStatisticsTreeManager.getStatTreeRoot(getTreeID()); final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID()); if (statsData == null) { @@ -734,31 +677,98 @@ public class TmfStatisticsViewer extends TmfViewer { continue; } - /* Retrieves the statistics object */ - final ITmfStatistics stats = aTrace.getStatistics(); - if (stats == null) { - /* - * The statistics provider for this trace is not accessible - * (yet?). Try the next one. - */ + /* Retrieve the statistics object */ + final TmfStatisticsModule statsMod = aTrace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID); + if (statsMod == null) { + /* No statistics module available for this trace */ continue; } - /* The generic statistics are stored in nanoseconds, so we must make - * sure the time range is scaled correctly. */ - long start = timeRange.getStartTime().normalize(0, TIME_SCALE).getValue(); - long end = timeRange.getEndTime().normalize(0, TIME_SCALE).getValue(); + /* Run the potentially long queries in a separate thread */ + Thread statsThread = new Thread("Statistics update") { //$NON-NLS-1$ + @Override + public void run() { + /* Wait until the analysis is ready */ + if (!statsMod.waitForCompletion(new NullProgressMonitor())) { + return; + } - /* - * Send a request to update the statistics view. The result will - * be sent through a {@link TmfStatsUpdatedSignal}, and will be - * processed by the signal handler. - */ - aTrace.getStatistics().updateStats(isGlobal, start, end); + ITmfStatistics stats = statsMod.getStatistics(); + if (stats == null) { + /* It should have worked, but didn't */ + return; + } + + /* + * The generic statistics are stored in nanoseconds, so + * we must make sure the time range is scaled correctly. + */ + long start = timeRange.getStartTime().normalize(0, TIME_SCALE).getValue(); + long end = timeRange.getEndTime().normalize(0, TIME_SCALE).getValue(); + + Map map = stats.getEventTypesInRange(start, end); + updateStats(isGlobal, map); + } + }; + statsThread.start(); + return; } } } + /** + * Whenever a trace's statistics back-end finishes computing the statistics + * for a given interval, it will send the StatsUpdated signal. This method + * will receive this signal and update the statistics view accordingly. + * + * @param sig + * The signal that is received + */ + private void updateStats(boolean isGlobal, Map eventsPerType) { + + final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID()); + Map map = eventsPerType; + String name = fTrace.getName(); + + /* + * "Global", "partial", "total", etc., it's all very confusing... + * + * The base view shows the total count for the trace and for + * each even types, organized in columns like this: + * + * | Global | Time range | + * trace name | A | B | + * Event Type | | | + * | C | D | + * | ... | ... | + * ... | | | + * + * Here, we called the cells like this: + * A : GlobalTotal + * B : TimeRangeTotal + * C : GlobalTypeCount(s) + * D : TimeRangeTypeCount(s) + */ + + /* Fill in an the event counts (either cells C or D) */ + for (Map.Entry entry : map.entrySet()) { + statsData.setTypeCount(name, entry.getKey(), isGlobal, entry.getValue()); + } + + /* + * Calculate the totals (cell A or B, depending if isGlobal). We will + * use the results of the previous request instead of sending another + * one. + */ + long globalTotal = 0; + for (long val : map.values()) { + globalTotal += val; + } + statsData.setTotal(name, isGlobal, globalTotal); + + modelComplete(isGlobal); + } + /** * Resets the number of events within the time range */