tmf : Add latency statistics view for the pattern analysis
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / tmf / analysis / xml / ui / module / TmfXmlAnalysisOutputSource.java
CommitLineData
048bde85 1/*******************************************************************************
38fad53e 2 * Copyright (c) 2016 École Polytechnique de Montréal and others
048bde85
GB
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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
048bde85
GB
14
15import java.io.File;
16import java.io.IOException;
1a23419e 17import java.util.List;
537572cd 18import java.util.Map;
048bde85
GB
19
20import javax.xml.parsers.DocumentBuilder;
21import javax.xml.parsers.DocumentBuilderFactory;
22import javax.xml.parsers.ParserConfigurationException;
23
44b06bb9 24import org.eclipse.jdt.annotation.NonNull;
38fad53e 25import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
2bdf0193
AM
26import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
27import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
38fad53e 28import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.Messages;
3b5dc745 29import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView;
38fad53e 30import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView;
c8e5d00e 31import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView;
5b901f94 32import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternStatisticsView;
2bdf0193
AM
33import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView;
34import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
35import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
36import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView;
37import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
38import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput;
39import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener;
38fad53e 40import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
048bde85 41import org.w3c.dom.Document;
1a23419e
FW
42import org.w3c.dom.Element;
43import org.w3c.dom.NodeList;
048bde85
GB
44import org.xml.sax.SAXException;
45
46/**
47 * This class searches all XML files to find outputs applicable to the newly
48 * created analysis
49 *
50 * @author Geneviève Bastien
51 */
52public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener {
53
54 /** String separating data elements for the output properties */
8ecd89fa 55 public static final @NonNull String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$
048bde85 56
2e9d15a9
GB
57 /**
58 * Enum to match the name of a view's XML element to its view ID.
59 */
44b06bb9
GB
60 public static enum ViewType {
61 /**
62 * Time graph view element
63 */
87c5447c 64 TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID),
44b06bb9
GB
65 /**
66 * XY chart view element
67 */
87c5447c 68 XY_VIEW(TmfXmlUiStrings.XY_VIEW, XmlXYView.ID);
2e9d15a9 69
44b06bb9 70 private final @NonNull String fXmlElem;
2e9d15a9
GB
71 private final String fViewId;
72
44b06bb9 73 private ViewType(@NonNull String xmlElem, String viewId) {
2e9d15a9
GB
74 fXmlElem = xmlElem;
75 fViewId = viewId;
76 }
77
44b06bb9
GB
78 /**
79 * Get the XML element corresponding to this view type
80 *
81 * @return The XML element corresponding to this type
82 */
83 public @NonNull String getXmlElem() {
2e9d15a9
GB
84 return fXmlElem;
85 }
86
44b06bb9 87 private String getViewId() {
2e9d15a9
GB
88 return fViewId;
89 }
90 }
91
38fad53e
JCK
92 /**
93 * Enum for latency view type.
94 *
95 * @author Jean-Christian Kouame
96 * @since 2.0
97 *
98 */
99 public static enum LatencyViewType {
100
101 /**
102 * Latency Table View type
103 */
c8e5d00e
JCK
104 LATENCY_TABLE(PatternLatencyTableView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyTable),
105
106 /**
107 * Latency Scatter View type
108 */
3b5dc745
JCK
109 SCATTER_GRAPH(PatternScatterGraphView.ID, Messages.TmfXmlAnalysisOutputSource_ScatterGraphTitle),
110
111 /**
112 * Latency Density View type
113 */
5b901f94
JCK
114 DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle),
115
116 /**
117 * Latency Statistic View type
118 */
119 STATISTIC_VIEW(PatternStatisticsView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle);
38fad53e
JCK
120
121 private @NonNull String fLatencyViewId;
122 private String fLatencyViewLabel;
123
124 private LatencyViewType(@NonNull String viewId, String label) {
125 fLatencyViewId = viewId;
126 fLatencyViewLabel = label;
127 }
128
129 /**
130 * Get the ID of the latency view
131 *
132 * @return The ID
133 */
134 public String getViewId() {
135 return fLatencyViewId;
136 }
137
138 /**
139 * Get the label of the view
140 *
141 * @return The label
142 */
143 public String getLabel() {
144 return fLatencyViewLabel;
145 }
146 }
87c5447c 147
048bde85
GB
148 @Override
149 public void moduleCreated(IAnalysisModule module) {
537572cd
BH
150 Map<String, File> files = XmlUtils.listFiles();
151 for (File xmlFile : files.values()) {
048bde85
GB
152 if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
153 continue;
154 }
155
156 try {
157 /* Load the XML File */
158 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
159 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
160 Document doc = dBuilder.parse(xmlFile);
161 doc.getDocumentElement().normalize();
162
163 /* get state provider views if the analysis has state systems */
38fad53e 164 if (module instanceof ITmfAnalysisModuleWithStateSystems) {
2e9d15a9
GB
165 for (ViewType viewType : ViewType.values()) {
166 NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem());
167 for (int i = 0; i < ssViewNodes.getLength(); i++) {
168 Element node = (Element) ssViewNodes.item(i);
169
170 /* Check if analysis is the right one */
171 List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD);
172 if (headNodes.size() != 1) {
173 continue;
174 }
1a23419e 175
2e9d15a9
GB
176 List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS);
177 for (Element analysis : analysisNodes) {
178 String analysisId = analysis.getAttribute(TmfXmlStrings.ID);
179 if (analysisId.equals(module.getId())) {
180 String viewId = viewType.getViewId();
44b06bb9 181 IAnalysisOutput output = new TmfXmlViewOutput(viewId, viewType);
2e9d15a9
GB
182 output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false);
183 module.registerOutput(output);
184 }
1a23419e
FW
185 }
186 }
187 }
188 }
38fad53e 189
c8e5d00e 190 // Add the latency views for pattern analysis
38fad53e
JCK
191 if (module instanceof XmlPatternAnalysis) {
192 for (LatencyViewType viewType : LatencyViewType.values()) {
193 IAnalysisOutput output = new TmfXmlLatencyViewOutput(viewType.getViewId(), viewType.getLabel());
194 output.setOutputProperty(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA, module.getId() + DATA_SEPARATOR + viewType.getLabel(), false);
195 module.registerOutput(output);
196 }
197 }
198
048bde85
GB
199 } catch (ParserConfigurationException | SAXException | IOException e) {
200 Activator.logError("Error opening XML file", e); //$NON-NLS-1$
201 }
202 }
203 }
204
205}
This page took 0.095962 seconds and 5 git commands to generate.