Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / statistics / StatisticsView.java
index 6691b98d778df5a75f5b9cbf8e197f0bffb8fd9b..4ca1fef94933f1a2536aee648ad1313015f7d0c8 100644 (file)
@@ -27,23 +27,28 @@ import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.linuxtools.lttng.control.LttngCoreProviderFactory;
-import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest;
-import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventToHandlerResolver;
+import org.eclipse.linuxtools.lttng.core.control.LttngCoreProviderFactory;
+import org.eclipse.linuxtools.lttng.core.event.LttngEvent;
+import org.eclipse.linuxtools.lttng.core.model.LTTngTreeNode;
+import org.eclipse.linuxtools.lttng.core.request.ILttngSyntEventRequest;
+import org.eclipse.linuxtools.lttng.core.state.evProcessor.AbsEventToHandlerResolver;
+import org.eclipse.linuxtools.lttng.core.state.experiment.StateManagerFactory;
 import org.eclipse.linuxtools.lttng.ui.TraceDebug;
 import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer;
 import org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView;
 import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater;
 import org.eclipse.linuxtools.lttng.ui.views.statistics.evProcessor.StatsTimeCountHandlerFactory;
+import org.eclipse.linuxtools.lttng.ui.views.statistics.model.KernelStatisticsData;
 import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeNode;
 import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeRootFactory;
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal;
-import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -88,14 +93,20 @@ public class StatisticsView extends AbsTimeUpdateView {
        private final String ELAPSED_TIME_COLUMN_TIP = Messages.StatisticsView_ElapsedTimeTip;
 
        // Level for which statistics should not be displayed.
-       private Set<String> folderLevels = new HashSet<String>(Arrays.asList(
-               new String[] { "Event Types", "Modes", "Submodes", "CPUs", "Processes", "Functions" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+    private Set<Integer> folderLevels = new HashSet<Integer>(Arrays
+                   .asList(new Integer[] { KernelStatisticsData.HEADER_CPUS_INT, 
+                                           KernelStatisticsData.HEADER_EVENT_TYPES_INT, 
+                                           KernelStatisticsData.HEADER_FUNCTIONS_INT, 
+                                           KernelStatisticsData.HEADER_MODES_INT, 
+                                           KernelStatisticsData.HEADER_PROCESSES_INT, 
+                                           KernelStatisticsData.HEADER_SUBMODES_INT }));
 
        // Levels for which sub-levels should not contain time-related statistics.
-       private Set<String> levelsWithEmptyTime = new HashSet<String>(Arrays.asList(
-               new String[] { "Event Types" })); //$NON-NLS-1$
+       private Set<Integer> levelsWithEmptyTime = new HashSet<Integer>(Arrays
+                   .asList(new Integer[] { KernelStatisticsData.HEADER_EVENT_TYPES_INT }));
 
        private DecimalFormat decimalFormat = new DecimalFormat("0.#########"); //$NON-NLS-1$
+
        private Cursor fwaitCursor = null;
 
        private static final Long STATS_INPUT_CHANGED_REFRESH = 5000L;
@@ -105,6 +116,11 @@ public class StatisticsView extends AbsTimeUpdateView {
                public double getPercentage(StatisticsTreeNode node);
        }
 
+    private boolean fStatisticsUpdateBusy = false;
+    private boolean fStatisticsUpdatePending = false;
+    private TmfTimeRange fStatisticsUpdateRange = null;
+    private final Object fStatisticsUpdateSyncObj = new Object();
+
        /**
         * Contains all the information necessary to build a column of the table.
         */
@@ -144,7 +160,12 @@ public class StatisticsView extends AbsTimeUpdateView {
                                        new ColumnLabelProvider() {
                                                @Override
                                                public String getText(Object element) {
-                                                       return ((StatisticsTreeNode) element).getKey();
+                                                   StatisticsTreeNode node = (StatisticsTreeNode) element;
+                            if (folderLevels.contains(node.getKey())) {
+                                return (KernelStatisticsData.getCategoryFromId(node.getKey().intValue()));
+                            } else {
+                                return node.getName();
+                            }
                                                }
 
                                                @Override
@@ -165,8 +186,9 @@ public class StatisticsView extends AbsTimeUpdateView {
                                                public int compare(Viewer viewer, Object e1, Object e2) {
                                                        StatisticsTreeNode n1 = (StatisticsTreeNode) e1;
                                                        StatisticsTreeNode n2 = (StatisticsTreeNode) e2;
-
-                                                       return n1.getKey().compareTo(n2.getKey());
+                                                       
+//                                                     return n1.getKey().compareTo(n2.getKey());
+                                                       return n1.compareTo(n2);
                                                }
                                        }, null),
                        new ColumnData(EVENTS_COUNT_COLUMN, 125, SWT.LEFT,
@@ -462,7 +484,11 @@ public class StatisticsView extends AbsTimeUpdateView {
                // Read current data if any available
                TmfExperiment<?> experiment = TmfExperiment.getCurrentExperiment();
                if (experiment != null) {
-                       requestData(experiment);
+                       
+                       @SuppressWarnings({ "rawtypes", "unchecked" })
+                       TmfExperimentSelectedSignal<?> signal = new TmfExperimentSelectedSignal(this, experiment);
+                       experimentSelected(signal);
+                       
                } else {
                        TraceDebug.debug("No selected experiment information available"); //$NON-NLS-1$
                }
@@ -544,7 +570,9 @@ public class StatisticsView extends AbsTimeUpdateView {
        public void ModelUpdatePrep(TmfTimeRange timeRange, boolean clearAllData) {
                Object input = treeViewer.getInput();
                if ((input != null) && (input instanceof StatisticsTreeNode) && (!treeViewer.getTree().isDisposed())) {
-                       ((StatisticsTreeNode) input).reset();
+                       if (clearAllData) {
+                               ((StatisticsTreeNode) input).reset();
+                       }
                        treeViewer.getTree().getDisplay().asyncExec(new Runnable() {
                                // @Override
                                @Override
@@ -560,7 +588,7 @@ public class StatisticsView extends AbsTimeUpdateView {
        public void modelInputChanged(ILttngSyntEventRequest request, boolean complete) {
                // Ignore update if disposed
                if (treeViewer.getTree().isDisposed()) return;
-
+               
                if(TraceDebug.isSV() && complete) {
                    // print results
 
@@ -569,7 +597,7 @@ public class StatisticsView extends AbsTimeUpdateView {
                        StatisticsTreeNode node = StatisticsTreeRootFactory.getStatTreeRoot(experiment.getName());
                        printRecursively(node);
 
-                       }
+                   }
                }
                
                treeViewer.getTree().getDisplay().asyncExec(new Runnable() {
@@ -580,18 +608,31 @@ public class StatisticsView extends AbsTimeUpdateView {
                                        treeViewer.refresh();
                        }
                });
+               
+               if (complete) {
+                       synchronized (fStatisticsUpdateSyncObj) {
+                               fStatisticsUpdateBusy = false;
+                               if (fStatisticsUpdatePending) {
+                                       fStatisticsUpdatePending = false;
+                                       requestData(TmfExperiment.getCurrentExperiment(), fStatisticsUpdateRange, false);
+                               }
+                       }
                }
+
+       }
+
        private static int level = 0;
-       private void printRecursively(StatisticsTreeNode node) {
-           String tab = ""; //$NON-NLS-1$
-           for (int i = 0; i < level; i++) {
+    private void printRecursively(StatisticsTreeNode node) {
+        String tab = ""; //$NON-NLS-1$
+        for (int i = 0; i < level; i++) {
             tab += "\t"; //$NON-NLS-1$
         }
-           level++;
+        level++;
         TraceDebug.traceSV(tab + node.getContent());
         if (node.hasChildren()) {
             LinkedList<StatisticsTreeNode> childreen = (LinkedList<StatisticsTreeNode>)node.getChildren();
             Collections.sort(childreen);
+
             for (Iterator<StatisticsTreeNode> iterator = childreen.iterator(); iterator.hasNext();) {
                 StatisticsTreeNode statisticsTreeNode = (StatisticsTreeNode) iterator.next();
                 printRecursively(statisticsTreeNode);
@@ -632,7 +673,9 @@ public class StatisticsView extends AbsTimeUpdateView {
                                StatisticsTreeNode experimentTreeNode = StatisticsTreeRootFactory.getStatTreeRoot(experimentName);
 
                                ITmfTrace[] traces = experiment.getTraces();
-
+                               
+                               LTTngTreeNode expNode = StateManagerFactory.getExperimentManager().getSelectedExperiment();
+                               
                                // check if there is partial data loaded in the experiment
                                int numTraces = experiment.getTraces().length;
                                int numNodeTraces = experimentTreeNode.getNbChildren();
@@ -643,7 +686,8 @@ public class StatisticsView extends AbsTimeUpdateView {
                                        // previously selected
                                        for (int i = 0; i < numTraces; i++) {
                                                String traceName = traces[i].getName();
-                                               if (!experimentTreeNode.containsChild(traceName)) {
+                                               LTTngTreeNode child = expNode.getChildByName(traceName);
+                                               if ((child == null) || (!experimentTreeNode.containsChild(child.getId().intValue()))) {
                                                         same = false;
                                                         break;
                                                }
@@ -652,34 +696,73 @@ public class StatisticsView extends AbsTimeUpdateView {
                                        if (same) {
                                                // no need to reload data, all traces are already loaded
                                                treeViewer.setInput(experimentTreeNode);
+                                               synchronized (fStatisticsUpdateSyncObj) {
+                                                       fStatisticsUpdateBusy = false;
+                                                       fStatisticsUpdatePending = false;
+                                               }
                                                return;
                                        }
                                }
                        }
 
+                       StatisticsTreeNode treeModelRoot = StatisticsTreeRootFactory.getStatTreeRoot(experiment.getName());
+
+                       // if the model has contents, clear to start over
+                       if (treeModelRoot.hasChildren()) {
+                               treeModelRoot.reset();
+                       }
+
+                       // set input to a clean data model
+                       treeViewer.setInput(treeModelRoot);
+
+                       synchronized (fStatisticsUpdateSyncObj) {
+                               fStatisticsUpdateBusy = false;
+                               fStatisticsUpdatePending = false;
+                       }
+
                        // if the data is not available or has changed, reload it
-                       requestData(experiment);
+                       requestData(experiment, experiment.getTimeRange(), true);
+               }
+       }
+
+       /**
+        * @param signal
+        */
+       @SuppressWarnings("unchecked")
+       @TmfSignalHandler
+       public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal) {
+               TmfExperiment<LttngEvent> experiment = (TmfExperiment<LttngEvent>) signal.getExperiment();
+               // validate
+               if (! experiment.equals(TmfExperiment.getCurrentExperiment())) {
+                       return;
                }
+
+               requestData(experiment, signal.getRange(), false);
        }
 
        /**
         * @param experiment
         */
-       private void requestData(TmfExperiment<?> experiment) {
+       private void requestData(TmfExperiment<?> experiment, TmfTimeRange range, boolean clearingData) {
                if (experiment != null) {
-                       StatisticsTreeNode treeModelRoot = StatisticsTreeRootFactory.getStatTreeRoot(experiment.getName());
-
-                       // if the model has contents, clear to start over
-                       if (treeModelRoot.hasChildren()) {
-                               treeModelRoot.reset();
+                       synchronized (fStatisticsUpdateSyncObj) {
+                               if (fStatisticsUpdateBusy) {
+                                       fStatisticsUpdatePending = true;
+                                       fStatisticsUpdateRange = range;
+                                       return;
+                               } else {
+                                       fStatisticsUpdateBusy = true;
+                               }
                        }
 
-                       // set input to a clean data model
-                       treeViewer.setInput(treeModelRoot);
-                       TmfTimeRange experimentTRange = experiment.getTimeRange();
+                       int index = 0;
+                       for (StatisticsTreeNode node : ((StatisticsTreeNode) treeViewer.getInput()).getChildren()) {
+                               index += (int) node.getValue().nbEvents;
+                       }
 
                        // send the initial request, to start filling up model
-                       dataRequest(experimentTRange, experimentTRange, true, ExecutionType.BACKGROUND);
+                       //eventRequest(fStatisticsUpdateIndex, nbRequested, fStatisticsUpdateStartTime, clearingData, ExecutionType.BACKGROUND);
+                       eventRequest(index, range, clearingData, ExecutionType.BACKGROUND);
                } else {
                        TraceDebug.debug("No selected experiment information available"); //$NON-NLS-1$
                }
@@ -726,4 +809,4 @@ public class StatisticsView extends AbsTimeUpdateView {
        protected int getProviderId() { 
            return LttngCoreProviderFactory.STATISTICS_LTTNG_SYTH_EVENT_PROVIDER; 
        }
-}
+}
\ No newline at end of file
This page took 0.026729 seconds and 5 git commands to generate.