tmf : Add latency statistics view for the pattern analysis
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / ui / views / latency / PatternStatisticsViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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
8 *******************************************************************************/
9 package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency;
10
11 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
12
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Map.Entry;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
21 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer;
22 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternLatencyStatisticsAnalysis;
23 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
24 import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
25 import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
26
27 /**
28 * A tree viewer implementation for displaying pattern latency statistics
29 *
30 * @author Jean-Christian Kouame
31 */
32 public class PatternStatisticsViewer extends AbstractSegmentStoreStatisticsViewer {
33
34 private String fAnalysisId;
35
36 private static final @NonNull String PATTERN_SEGMENTS_LEVEL = "Pattern Segments"; //$NON-NLS-1$
37
38 /**
39 * Constructor
40 *
41 * @param parent
42 * The parent composite
43 */
44 public PatternStatisticsViewer(@NonNull Composite parent) {
45 super(parent);
46 }
47
48 @Override
49 protected @Nullable TmfAbstractAnalysisModule createStatisticsAnalysiModule() {
50 return new XmlPatternLatencyStatisticsAnalysis(fAnalysisId);
51 }
52
53 @Override
54 protected ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
55 if (isSelection || (start == end)) {
56 return null;
57 }
58
59 TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule();
60
61 if (getTrace() == null || !(analysisModule instanceof XmlPatternLatencyStatisticsAnalysis)) {
62 return null;
63 }
64
65 XmlPatternLatencyStatisticsAnalysis module = (XmlPatternLatencyStatisticsAnalysis) analysisModule;
66
67 module.waitForCompletion();
68
69 TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
70 final SegmentStoreStatistics entry = module.getTotalStats();
71 if (entry != null) {
72
73 List<ITmfTreeViewerEntry> entryList = root.getChildren();
74
75 TmfTreeViewerEntry child = new SegmentStoreStatisticsEntry(checkNotNull("Total"), entry); //$NON-NLS-1$
76 entryList.add(child);
77 HiddenTreeViewerEntry segments = new HiddenTreeViewerEntry(PATTERN_SEGMENTS_LEVEL);
78 child.addChild(segments);
79
80 final Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = module.getPerSegmentTypeStats();
81 if (perTypeStats != null) {
82 for (Entry<@NonNull String, @NonNull SegmentStoreStatistics> statsEntry : perTypeStats.entrySet()) {
83 segments.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
84 }
85 }
86 }
87 return root;
88 }
89
90 /**
91 * Set the analysis ID and update the view
92 *
93 * @param analysisId
94 * The analysis ID
95 */
96 public void updateViewer(String analysisId) {
97 if (analysisId != null) {
98 fAnalysisId = analysisId;
99 initializeDataSource();
100 }
101 }
102
103 }
This page took 0.033546 seconds and 5 git commands to generate.