1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.views
.segmentstore
.statistics
;
14 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import java
.text
.Format
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.SubSecondTimeWithUnitFormat
;
26 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.segmentstore
.statistics
.SegmentStoreStatistics
;
27 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.Activator
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.tree
.AbstractTmfTreeViewer
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.tree
.ITmfTreeColumnDataProvider
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.tree
.TmfTreeColumnData
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.tree
.TmfTreeViewerEntry
;
37 * An abstract tree viewer implementation for displaying segment store
40 * @author Bernd Hufmann
43 public abstract class AbstractSegmentStoreStatisticsViewer
extends AbstractTmfTreeViewer
{
45 private static final Format FORMATTER
= new SubSecondTimeWithUnitFormat();
48 private TmfAbstractAnalysisModule fModule
;
50 private static final String
[] COLUMN_NAMES
= new String
[] {
51 checkNotNull(Messages
.SegmentStoreStatistics_LevelLabel
),
52 checkNotNull(Messages
.SegmentStoreStatistics_Statistics_MinLabel
),
53 checkNotNull(Messages
.SegmentStoreStatistics_MaxLabel
),
54 checkNotNull(Messages
.SegmentStoreStatistics_AverageLabel
),
55 checkNotNull(Messages
.SegmentStoreStatisticsViewer_StandardDeviation
)
62 * the parent composite
64 public AbstractSegmentStoreStatisticsViewer(Composite parent
) {
66 setLabelProvider(new SegmentStoreStatisticsLabelProvider());
69 /** Provides label for the Segment Store tree viewer cells */
70 protected static class SegmentStoreStatisticsLabelProvider
extends TreeLabelProvider
{
73 public String
getColumnText(@Nullable Object element
, int columnIndex
) {
74 String value
= ""; //$NON-NLS-1$
75 if (element
instanceof HiddenTreeViewerEntry
) {
76 if (columnIndex
== 0) {
77 value
= ((HiddenTreeViewerEntry
) element
).getName();
79 } else if (element
instanceof SegmentStoreStatisticsEntry
) {
80 SegmentStoreStatisticsEntry entry
= (SegmentStoreStatisticsEntry
) element
;
81 if (columnIndex
== 0) {
82 return String
.valueOf(entry
.getName());
84 if (entry
.getEntry().getNbSegments() > 0) {
85 if (columnIndex
== 1) {
86 value
= toFormattedString(entry
.getEntry().getMin());
87 } else if (columnIndex
== 2) {
88 value
= String
.valueOf(toFormattedString(entry
.getEntry().getMax()));
89 } else if (columnIndex
== 3) {
90 value
= String
.valueOf(toFormattedString(entry
.getEntry().getAverage()));
91 } else if (columnIndex
== 4) {
92 value
= String
.valueOf(toFormattedString(entry
.getEntry().getStdDev()));
96 return checkNotNull(value
);
101 * Creates the statistics analysis module
103 * @return the statistics analysis module
106 protected abstract TmfAbstractAnalysisModule
createStatisticsAnalysiModule();
109 * Gets the statistics analysis module
111 * @return the statistics analysis module
114 public TmfAbstractAnalysisModule
getStatisticsAnalysisModule() {
119 protected ITmfTreeColumnDataProvider
getColumnDataProvider() {
120 return new ITmfTreeColumnDataProvider() {
123 public List
<@Nullable TmfTreeColumnData
> getColumnData() {
124 /* All columns are sortable */
125 List
<@Nullable TmfTreeColumnData
> columns
= new ArrayList
<>();
126 TmfTreeColumnData column
= new TmfTreeColumnData(COLUMN_NAMES
[0]);
127 column
.setAlignment(SWT
.RIGHT
);
128 column
.setComparator(new ViewerComparator() {
130 public int compare(@Nullable Viewer viewer
, @Nullable Object e1
, @Nullable Object e2
) {
131 if ((e1
== null) || (e2
== null)) {
135 SegmentStoreStatisticsEntry n1
= (SegmentStoreStatisticsEntry
) e1
;
136 SegmentStoreStatisticsEntry n2
= (SegmentStoreStatisticsEntry
) e2
;
138 return n1
.getName().compareTo(n2
.getName());
143 column
= new TmfTreeColumnData(COLUMN_NAMES
[1]);
144 column
.setAlignment(SWT
.RIGHT
);
145 column
.setComparator(new ViewerComparator() {
147 public int compare(@Nullable Viewer viewer
, @Nullable Object e1
, @Nullable Object e2
) {
148 if ((e1
== null) || (e2
== null)) {
152 SegmentStoreStatisticsEntry n1
= (SegmentStoreStatisticsEntry
) e1
;
153 SegmentStoreStatisticsEntry n2
= (SegmentStoreStatisticsEntry
) e2
;
155 return Long
.compare(n1
.getEntry().getMin(), n2
.getEntry().getMin());
160 column
= new TmfTreeColumnData(COLUMN_NAMES
[2]);
161 column
.setAlignment(SWT
.RIGHT
);
162 column
.setComparator(new ViewerComparator() {
164 public int compare(@Nullable Viewer viewer
, @Nullable Object e1
, @Nullable Object e2
) {
165 if ((e1
== null) || (e2
== null)) {
169 SegmentStoreStatisticsEntry n1
= (SegmentStoreStatisticsEntry
) e1
;
170 SegmentStoreStatisticsEntry n2
= (SegmentStoreStatisticsEntry
) e2
;
172 return Long
.compare(n1
.getEntry().getMax(), n2
.getEntry().getMax());
177 column
= new TmfTreeColumnData(COLUMN_NAMES
[3]);
178 column
.setAlignment(SWT
.RIGHT
);
179 column
.setComparator(new ViewerComparator() {
181 public int compare(@Nullable Viewer viewer
, @Nullable Object e1
, @Nullable Object e2
) {
182 if ((e1
== null) || (e2
== null)) {
186 SegmentStoreStatisticsEntry n1
= (SegmentStoreStatisticsEntry
) e1
;
187 SegmentStoreStatisticsEntry n2
= (SegmentStoreStatisticsEntry
) e2
;
189 return Double
.compare(n1
.getEntry().getAverage(), n2
.getEntry().getAverage());
194 column
= new TmfTreeColumnData(COLUMN_NAMES
[4]);
195 column
.setAlignment(SWT
.RIGHT
);
196 column
.setComparator(new ViewerComparator() {
198 public int compare(@Nullable Viewer viewer
, @Nullable Object e1
, @Nullable Object e2
) {
199 if ((e1
== null) || (e2
== null)) {
203 SegmentStoreStatisticsEntry n1
= (SegmentStoreStatisticsEntry
) e1
;
204 SegmentStoreStatisticsEntry n2
= (SegmentStoreStatisticsEntry
) e2
;
206 return Double
.compare(n1
.getEntry().getStdDev(), n2
.getEntry().getStdDev());
211 column
= new TmfTreeColumnData(""); //$NON-NLS-1$
220 public void initializeDataSource() {
221 ITmfTrace trace
= getTrace();
223 TmfAbstractAnalysisModule module
= createStatisticsAnalysiModule();
224 if (module
== null) {
228 module
.setTrace(trace
);
231 } catch (TmfAnalysisException e
) {
232 Activator
.getDefault().logError("Error initializing statistics analysis module", e
); //$NON-NLS-1$
238 * Formats a double value string
242 * @return formatted value
244 protected static String
toFormattedString(double value
) {
245 // The cast to long is needed because the formatter cannot truncate the
247 String percentageString
= String
.format("%s", FORMATTER
.format(value
)); //$NON-NLS-1$
248 return percentageString
;
252 * Class for defining an entry in the statistics tree.
254 protected class SegmentStoreStatisticsEntry
extends TmfTreeViewerEntry
{
256 private SegmentStoreStatistics fEntry
;
265 * segment store statistics object
267 public SegmentStoreStatisticsEntry(String name
, SegmentStoreStatistics entry
) {
273 * Gets the statistics object
275 * @return statistics object
277 public SegmentStoreStatistics
getEntry() {
284 * Class to define a level in the tree that doesn't have any values.
286 protected class HiddenTreeViewerEntry
extends SegmentStoreStatisticsEntry
{
291 * the name of the level
293 public HiddenTreeViewerEntry(String name
) {
294 super(name
, new SegmentStoreStatistics());