1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * France Lapointe Nguyen - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
;
15 import org
.eclipse
.jdt
.annotation
.Nullable
;
16 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
17 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
18 import org
.eclipse
.jface
.viewers
.TableViewer
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.LatencyAnalysis
;
23 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.LatencyAnalysisListener
;
24 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
25 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
26 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
27 import org
.eclipse
.tracecompass
.segmentstore
.core
.SegmentComparators
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampFormat
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.table
.TmfSimpleTableViewer
;
43 * Displays the latency analysis data in a column table
45 * @author France Lapointe Nguyen
47 public class LatencyTableViewer
extends TmfSimpleTableViewer
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * Abstract class for the column label provider for the latency analysis
57 private abstract class LatencyTableColumnLabelProvider
extends ColumnLabelProvider
{
60 public String
getText(@Nullable Object input
) {
61 if (!(input
instanceof ISegment
)) {
62 /* Doubles as a null check */
63 return ""; //$NON-NLS-1$
65 return getTextFoITimeRange((ISegment
) input
);
68 public abstract String
getTextFoITimeRange(ISegment input
);
72 * Listener to update the model with the latency analysis results once the
73 * latency analysis is fully completed
75 private final class LatencyListener
implements LatencyAnalysisListener
{
77 public void onComplete(LatencyAnalysis activeAnalysis
, ISegmentStore
<ISegment
> data
) {
78 // Check if the active trace was changed while the analysis was
80 if (activeAnalysis
.equals(fAnalysisModule
)) {
87 * Listener to select a range in other viewers when a cell of the latency
88 * table view is selected
90 private class LatencyTableSelectionListener
extends SelectionAdapter
{
92 public void widgetSelected(@Nullable SelectionEvent e
) {
93 ISegment selectedSegment
= ((ISegment
) NonNullUtils
.checkNotNull(e
).item
.getData());
94 ITmfTimestamp start
= new TmfNanoTimestamp(selectedSegment
.getStart());
95 ITmfTimestamp end
= new TmfNanoTimestamp(selectedSegment
.getEnd());
96 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(LatencyTableViewer
.this, start
, end
));
101 * Current latency analysis module
103 private @Nullable LatencyAnalysis fAnalysisModule
= null;
106 * Latency analysis completion listener
108 private LatencyListener fListener
;
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
118 * Table viewer of the view
120 public LatencyTableViewer(TableViewer tableViewer
) {
122 // Sort order of the content provider is by start time by default
123 getTableViewer().setContentProvider(new LatencyContentProvider());
124 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
126 fAnalysisModule
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, LatencyAnalysis
.class, LatencyAnalysis
.ID
);
129 getTableViewer().getTable().addSelectionListener(new LatencyTableSelectionListener());
130 fListener
= new LatencyListener();
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 * Create columns for start time, end time and duration
140 private void createColumns() {
141 createColumn(Messages
.LatencyTableViewer_startTime
, new LatencyTableColumnLabelProvider() {
143 public String
getTextFoITimeRange(ISegment input
) {
144 return NonNullUtils
.nullToEmptyString(TmfTimestampFormat
.getDefaulTimeFormat().format(input
.getStart()));
146 }, SegmentComparators
.INTERVAL_START_COMPARATOR
);
148 createColumn(Messages
.LatencyTableViewer_endTime
, new LatencyTableColumnLabelProvider() {
150 public String
getTextFoITimeRange(ISegment input
) {
151 return NonNullUtils
.nullToEmptyString(TmfTimestampFormat
.getDefaulTimeFormat().format(input
.getEnd()));
153 }, SegmentComparators
.INTERVAL_END_COMPARATOR
);
155 createColumn(Messages
.LatencyTableViewer_duration
, new LatencyTableColumnLabelProvider() {
157 public String
getTextFoITimeRange(ISegment input
) {
158 return NonNullUtils
.nullToEmptyString(Long
.toString(input
.getLength()));
160 }, SegmentComparators
.INTERVAL_LENGTH_COMPARATOR
);
164 * Update the data in the table viewer
169 public void updateModel(final @Nullable ISegmentStore
<ISegment
> dataInput
) {
170 final TableViewer tableViewer
= getTableViewer();
171 Display
.getDefault().asyncExec(new Runnable() {
174 if (!tableViewer
.getTable().isDisposed()) {
175 // Go to the top of the table
176 tableViewer
.getTable().setTopIndex(0);
177 // Reset selected row
178 tableViewer
.setSelection(StructuredSelection
.EMPTY
);
179 if (dataInput
== null) {
180 tableViewer
.setInput(null);
181 tableViewer
.setItemCount(0);
184 tableViewer
.setInput(dataInput
);
185 LatencyContentProvider latencyContentProvider
= (LatencyContentProvider
) getTableViewer().getContentProvider();
186 tableViewer
.setItemCount(latencyContentProvider
.getSegmentCount());
193 * Set the data into the viewer. Will update model is analysis is completed
194 * or run analysis if not completed
197 * Latency analysis module
199 public void setData(@Nullable LatencyAnalysis analysis
) {
200 // Set the current latency analysis module
201 fAnalysisModule
= analysis
;
202 if (analysis
== null) {
206 ISegmentStore
<ISegment
> results
= analysis
.getResults();
207 // If results are not null, then analysis is completed and model can be
209 if (results
!= null) {
210 updateModel(results
);
213 // If results are null, then add completion listener and run analysis
215 analysis
.addListener(fListener
);
219 // ------------------------------------------------------------------------
221 // ------------------------------------------------------------------------
224 * Get current latency analysis module
226 * @return current latency analysis module
228 public @Nullable LatencyAnalysis
getAnalysisModule() {
229 return fAnalysisModule
;
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
237 * Trace selected handler
240 * Different opened trace (on which latency analysis as already
241 * been performed) has been selected
244 public void traceSelected(TmfTraceSelectedSignal signal
) {
245 ITmfTrace trace
= signal
.getTrace();
247 setData(TmfTraceUtils
.getAnalysisModuleOfClass(trace
, LatencyAnalysis
.class, LatencyAnalysis
.ID
));
252 * Trace opened handler
255 * New trace (on which latency analysis has not been performed)
259 public void traceOpened(TmfTraceOpenedSignal signal
) {
260 ITmfTrace trace
= signal
.getTrace();
262 setData(TmfTraceUtils
.getAnalysisModuleOfClass(trace
, LatencyAnalysis
.class, LatencyAnalysis
.ID
));
267 * Trace closed handler
270 * Last opened trace was closed
273 public void traceClosed(TmfTraceClosedSignal signal
) {
274 // Check if there is no more opened trace
275 if (TmfTraceManager
.getInstance().getActiveTrace() == null) {
276 if (!getTableViewer().getTable().isDisposed()) {
277 getTableViewer().setInput(null);