~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
2
 * Copyright (c) 2011, 20112 Ericsson
3
 
 * 
 
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
6
 * accompanies this distribution, and is available at
7
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 
 * 
 
8
 *
9
9
 * Contributors:
10
10
 *   Mathieu Denis  (mathieu.denis@polymtl.ca)  - Generalized version based on LTTng
11
11
 *   Bernd Hufmann - Updated to use trace reference in TmfEvent and streaming
12
 
 *   
 
12
 *
13
13
 *******************************************************************************/
14
14
 
15
15
package org.eclipse.linuxtools.tmf.ui.views.statistics;
22
22
import org.eclipse.jface.viewers.ViewerComparator;
23
23
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
24
24
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
25
 
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
26
25
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
27
26
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
28
27
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
30
29
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
31
30
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
32
31
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
 
32
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal;
33
33
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
34
34
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
35
35
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
55
55
 
56
56
/**
57
57
 * The generic Statistics View displays statistics for any kind of traces.
58
 
 * 
 
58
 *
59
59
 * It is implemented according to the MVC pattern. - The model is a TmfStatisticsTreeNode built by the State Manager. - The view is built with a
60
60
 * TreeViewer. - The controller that keeps model and view synchronized is an observer of the model.
61
61
 * </p>
62
 
 * 
 
62
 *
63
63
 * @version 1.0
64
64
 * @author @author Mathieu Denis
65
65
 */
73
73
     */
74
74
    public static final String TMF_STATISTICS_VIEW = "StatisticsView"; //$NON-NLS-1$
75
75
    /**
76
 
     *  Refresh frequency 
 
76
     *  Refresh frequency
77
77
     */
78
78
    protected static final Long STATS_INPUT_CHANGED_REFRESH = 5000L;
79
79
    /**
107
107
    /**
108
108
     *  Flag to force request the data from trace
109
109
     */
110
 
    protected boolean fRequestData = false; 
 
110
    protected boolean fRequestData = false;
111
111
    /**
112
112
     *  Object to store the cursor while waiting for the experiment to load
113
113
     */
114
114
    private Cursor fWaitCursor = null;
115
115
    /**
116
 
     *  View instance counter (for multiple statistic views) 
 
116
     *  View instance counter (for multiple statistic views)
117
117
     */
118
118
    private static int fCountInstance = 0;
119
119
    /**
120
120
     * Number of this instance. Used as an instance ID.
121
121
     */
122
 
    private int fInstanceNb;
 
122
    private final int fInstanceNb;
123
123
 
124
124
    /**
125
125
     * Constructor of a statistics view.
126
 
     * 
 
126
     *
127
127
     * @param viewName
128
128
     *            The name to give to the view.
129
129
     */
246
246
            fWaitCursor.dispose();
247
247
        }
248
248
 
 
249
        // Make sure there is no request running before removing the statistics tree
 
250
        cancelOngoingRequest();
249
251
        // clean the model
250
252
        TmfStatisticsTreeRootFactory.removeAll();
251
253
    }
261
263
 
262
264
    /**
263
265
     * Refresh the view.
 
266
     *
 
267
     * @param complete
 
268
     *            Should a pending update be sent afterwards or not
264
269
     */
265
270
    public void modelInputChanged(boolean complete) {
266
271
        // Ignore update if disposed
267
 
        if (fTreeViewer.getTree().isDisposed())
 
272
        if (fTreeViewer.getTree().isDisposed()) {
268
273
            return;
 
274
        }
269
275
 
270
276
        fTreeViewer.getTree().getDisplay().asyncExec(new Runnable() {
271
277
            @Override
272
278
            public void run() {
273
 
                if (!fTreeViewer.getTree().isDisposed())
 
279
                if (!fTreeViewer.getTree().isDisposed()) {
274
280
                    fTreeViewer.refresh();
 
281
                }
275
282
            }
276
283
        });
277
 
        
 
284
 
278
285
        if (complete) {
279
286
            sendPendingUpdate();
280
287
        }
282
289
 
283
290
    /**
284
291
     * Called when an experiment request has failed or has been canceled Remove the data retrieved from the experiment from the statistics tree.
285
 
     * 
 
292
     *
286
293
     * @param name The experiment name
287
294
     */
288
295
    public void modelIncomplete(String name) {
301
308
 
302
309
    /**
303
310
     * Handles the signal about disposal of the current experiment.
304
 
     * 
 
311
     *
305
312
     * @param signal The disposed signal
306
313
     */
307
314
    @TmfSignalHandler
313
320
    }
314
321
 
315
322
    /**
316
 
     * Handler called when an experiment is selected. Checks if the experiment has changed 
 
323
     * Handler called when an experiment is selected. Checks if the experiment has changed
317
324
     * and requests the selected experiment if it has not yet been cached.
318
 
     * 
 
325
     *
319
326
     * @param signal Contains the information about the selection.
320
327
     */
321
328
    @TmfSignalHandler
350
357
                    if (same) {
351
358
                        // no need to reload data, all traces are already loaded
352
359
                        fTreeViewer.setInput(experimentTreeNode);
353
 
                        
 
360
 
354
361
                        resetUpdateSynchronization();
355
362
 
356
363
                        return;
372
379
 
373
380
            // set input to a clean data model
374
381
            fTreeViewer.setInput(treeModelRoot);
375
 
            
 
382
 
376
383
            if (fRequestData) {
377
384
                requestData(experiment, experiment.getTimeRange());
378
385
                fRequestData = false;
396
403
        requestData(experiment, signal.getRange());
397
404
    }
398
405
 
399
 
    
 
406
    /**
 
407
     * Handles the experiment updated signal. This will detect new events
 
408
     * in case the indexing is not coalesced with a statistics request.
 
409
     * @param signal The experiment updated signal
 
410
     *
 
411
     * @since 1.1
 
412
     */
 
413
    @TmfSignalHandler
 
414
    public void experimentUpdated(TmfExperimentUpdatedSignal signal) {
 
415
        TmfExperiment<?> experiment = signal.getExperiment();
 
416
        if (! experiment.equals(TmfExperiment.getCurrentExperiment())) {
 
417
            return;
 
418
        }
 
419
 
 
420
        int nbEvents = 0;
 
421
        for (TmfStatisticsTreeNode node : ((TmfStatisticsTreeNode) fTreeViewer.getInput()).getChildren()) {
 
422
            nbEvents += (int) node.getValue().nbEvents;
 
423
        }
 
424
 
 
425
        // In the normal case, the statistics request is coalesced with indexing
 
426
        // and the number of events are the same, there is nothing to do.
 
427
        // But if its not the case, trigger a new request to count the new events.
 
428
        if (nbEvents < experiment.getNbEvents()) {
 
429
            requestData(experiment, experiment.getTimeRange());
 
430
        }
 
431
    }
 
432
 
400
433
    /**
401
434
     * Return the size of the request when performing background request.
402
 
     * 
 
435
     *
403
436
     * @return the block size for background request.
404
437
     */
405
438
    protected int getIndexPageSize() {
408
441
 
409
442
    /**
410
443
     * Returns the quantity of data to retrieve before a refresh of the view is performed
411
 
     * 
 
444
     *
412
445
     * @return the quantity of data to retrieve before a refresh of the view is performed.
413
446
     */
414
447
    protected long getInputChangedRefresh() {
417
450
 
418
451
    /**
419
452
     * This method can be overridden to implement another way to represent the statistics data and to retrieve the information for display.
420
 
     * 
 
453
     *
421
454
     * @return a TmfStatisticsData object.
422
455
     */
423
456
    protected AbsTmfStatisticsTree getStatisticData() {
426
459
 
427
460
    /**
428
461
     * This method can be overridden to change the representation of the data in the columns.
429
 
     * 
 
462
     *
430
463
     * @return an object implementing ITmfBaseColumnDataProvider.
431
464
     */
432
465
    protected ITmfColumnDataProvider getColumnDataProvider() {
435
468
 
436
469
    /**
437
470
     * Constructs the ID based on the experiment name and <code>fInstanceNb</code>
438
 
     * 
439
 
     * @param experimentName the name of the trace name to show in the view 
 
471
     *
 
472
     * @param experimentName the name of the trace name to show in the view
440
473
     * @return a view ID
441
474
     */
442
475
    protected String getTreeID(String experimentName) {
445
478
 
446
479
    /**
447
480
     * When the experiment is loading the cursor will be different so the user know the processing is not finished yet.
448
 
     * 
 
481
     *
449
482
     * @param waitInd Indicates if we need to show the waiting cursor, or the default one
450
483
     */
451
484
    protected void waitCursor(final boolean waitInd) {
475
508
 
476
509
    /**
477
510
     * Perform the request for an experiment and populates the statistics tree with event.
478
 
     * 
 
511
     *
479
512
     * @param experiment experiment for which we need the statistics data.
480
513
     * @param timeRange to request
481
514
     */
496
529
            // Preparation of the event request
497
530
            fRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index, TmfDataRequest.ALL_DATA, getIndexPageSize(), ExecutionType.BACKGROUND) {
498
531
 
 
532
                private final AbsTmfStatisticsTree statisticsData = TmfStatisticsTreeRootFactory.getStatTree(getTreeID(experiment.getName()));
 
533
 
499
534
                @Override
500
535
                public void handleData(ITmfEvent data) {
501
536
                    super.handleData(data);
502
537
                    if (data != null) {
503
 
                        AbsTmfStatisticsTree statisticsData = TmfStatisticsTreeRootFactory.getStatTree(getTreeID(experiment.getName()));
504
 
                        
505
538
                        final String traceName = data.getTrace().getName();
506
539
                        ITmfExtraEventInfo extraInfo = new ITmfExtraEventInfo() {
507
540
                            @Override
540
573
                    modelIncomplete(experiment.getName());
541
574
                }
542
575
            };
543
 
            ((TmfExperiment<ITmfEvent>) experiment).sendRequest((ITmfDataRequest<ITmfEvent>) fRequest);
 
576
            ((TmfExperiment<ITmfEvent>) experiment).sendRequest(fRequest);
544
577
            waitCursor(true);
545
578
        }
546
579
    }
553
586
            fRequest.cancel();
554
587
        }
555
588
    }
556
 
    
 
589
 
557
590
    /**
558
591
     * Reset update synchronization information
559
592
     */
561
594
        synchronized (fStatisticsUpdateSyncObj) {
562
595
            fStatisticsUpdateBusy = false;
563
596
            fStatisticsUpdatePending = false;
 
597
            fStatisticsUpdateRange = null;
564
598
        }
565
599
    }
566
600
 
567
601
    /**
568
 
     * Checks if statistic update is ongoing. If it is ongoing the new time range is stored as pending 
569
 
     * 
 
602
     * Checks if statistic update is ongoing. If it is ongoing the new time range is stored as pending
 
603
     *
570
604
     * @param timeRange - new time range
571
 
     * @return true if statistic update is ongoing else false 
 
605
     * @return true if statistic update is ongoing else false
572
606
     */
573
607
    protected boolean checkUpdateBusy(TmfTimeRange timeRange) {
574
608
        synchronized (fStatisticsUpdateSyncObj) {
575
609
            if (fStatisticsUpdateBusy) {
576
610
                fStatisticsUpdatePending = true;
577
 
                fStatisticsUpdateRange = timeRange;
 
611
                if (fStatisticsUpdateRange == null || timeRange.getEndTime().compareTo(fStatisticsUpdateRange.getEndTime()) > 0) {
 
612
                    fStatisticsUpdateRange = timeRange;
 
613
                }
578
614
                return true;
579
 
            } 
 
615
            }
580
616
            fStatisticsUpdateBusy = true;
581
617
            return false;
582
618
        }
591
627
            if (fStatisticsUpdatePending) {
592
628
                fStatisticsUpdatePending = false;
593
629
                requestData(TmfExperiment.getCurrentExperiment(), fStatisticsUpdateRange);
 
630
                fStatisticsUpdateRange = null;
594
631
            }
595
632
        }
596
633
    }