2ab11b6f92dd43c06f0d1711a317c8103d9acfb7
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / service / LTTngControlServiceMI.java
1 /**********************************************************************
2 * Copyright (c) 2014 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 * Contributors:
10 * Jonathan Rajotte - Initial support for machine interface lttng 2.6
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
14
15 import java.io.IOException;
16 import java.io.StringReader;
17 import java.net.URL;
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.regex.Matcher;
21
22 import javax.xml.parsers.DocumentBuilder;
23 import javax.xml.parsers.DocumentBuilderFactory;
24 import javax.xml.parsers.ParserConfigurationException;
25
26 import org.eclipse.core.commands.ExecutionException;
27 import org.eclipse.core.runtime.IProgressMonitor;
28 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IBaseEventInfo;
29 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
30 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
31 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IEventInfo;
32 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IFieldInfo;
33 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IProbeEventInfo;
34 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
35 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
36 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IUstProviderInfo;
37 import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
38 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceDomainType;
39 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
40 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
41 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
42 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.BaseEventInfo;
43 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.BufferType;
44 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ChannelInfo;
45 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.DomainInfo;
46 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.EventInfo;
47 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.FieldInfo;
48 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ProbeEventInfo;
49 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
50 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SnapshotInfo;
51 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.UstProviderInfo;
52 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.XmlMiValidationErrorHandler;
53 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
54 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandResult;
55 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandShell;
56 import org.w3c.dom.Document;
57 import org.w3c.dom.Node;
58 import org.w3c.dom.NodeList;
59 import org.xml.sax.InputSource;
60 import org.xml.sax.SAXException;
61
62 /**
63 * Service for sending LTTng trace control commands to remote host via machine
64 * interface mode.
65 *
66 * @author Jonathan Rajotte
67 */
68 public class LTTngControlServiceMI extends LTTngControlService {
69
70 // ------------------------------------------------------------------------
71 // Attributes
72 // ------------------------------------------------------------------------
73
74 private final DocumentBuilder fDocumentBuilder;
75
76 // ------------------------------------------------------------------------
77 // Constructors
78 // ------------------------------------------------------------------------
79
80 /**
81 * Constructor
82 *
83 * @param shell
84 * the command shell implementation to use
85 * @param xsdUrl
86 * the xsd schema file for validation
87 * @throws ExecutionException
88 * if the creation of the Schema and DocumentBuilder objects
89 * fails
90 */
91 public LTTngControlServiceMI(ICommandShell shell, URL xsdUrl) throws ExecutionException {
92 super(shell);
93
94 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
95 docBuilderFactory.setValidating(false);
96
97 // TODO: Add xsd validation for machine interface via mi_lttng.xsd from LTTng
98 try {
99 fDocumentBuilder = docBuilderFactory.newDocumentBuilder();
100 } catch (ParserConfigurationException e) {
101 throw new ExecutionException(Messages.TraceControl_XmlDocumentBuilderError, e);
102 }
103
104 fDocumentBuilder.setErrorHandler(new XmlMiValidationErrorHandler());
105
106 }
107
108 /**
109 * Generate a Document object from an array of String.
110 *
111 * @param xmlStrings
112 * array of strings representing an xml input
113 * @return Document generated from strings input
114 * @throws ExecutionException
115 * when parsing has failed
116 */
117 private Document getDocumentFromStrings(String[] xmlStrings) throws ExecutionException {
118 StringBuilder concatenedString = new StringBuilder();
119 for (String string : xmlStrings) {
120 concatenedString.append(string);
121 }
122 InputSource stream = new InputSource(new StringReader(concatenedString.toString()));
123
124 Document document;
125 try {
126 document = fDocumentBuilder.parse(stream);
127 } catch (SAXException | IOException e) {
128 throw new ExecutionException(Messages.TraceControl_XmlParsingError, e);
129 }
130 return document;
131
132 }
133
134 /**
135 * Parse, populate and set the internal LTTngVersion variable
136 *
137 * @param xmlOutput
138 * the mi xml output of lttng version
139 * @throws ExecutionException
140 * when xml extraction fail
141 */
142 public void setVersion(String[] xmlOutput) throws ExecutionException {
143 Document doc = getDocumentFromStrings(xmlOutput);
144 NodeList element = doc.getElementsByTagName(MIStrings.VERSION);
145 int major = 0;
146 int minor = 0;
147 int patchLevel = 0;
148 String license = ""; //$NON-NLS-1$
149 String commit = ""; //$NON-NLS-1$
150 String name = ""; //$NON-NLS-1$
151 String description = ""; //$NON-NLS-1$
152 String url = ""; //$NON-NLS-1$
153 String fullVersion = ""; //$NON-NLS-1$
154 if (element.getLength() == 1) {
155 NodeList child = element.item(0).getChildNodes();
156 // Get basic information
157 for (int i = 0; i < child.getLength(); i++) {
158 Node node = child.item(i);
159 switch (node.getNodeName()) {
160 case MIStrings.VERSION_MAJOR:
161 major = Integer.parseInt(node.getTextContent());
162 break;
163 case MIStrings.VERSION_MINOR:
164 minor = Integer.parseInt(node.getTextContent());
165 break;
166 case MIStrings.VERSION_PATCH_LEVEL:
167 patchLevel = Integer.parseInt(node.getTextContent());
168 break;
169 case MIStrings.VERSION_COMMIT:
170 commit = node.getTextContent();
171 break;
172 case MIStrings.VERSION_DESCRIPTION:
173 description = node.getTextContent();
174 break;
175 case MIStrings.VERSION_LICENSE:
176 license = node.getTextContent();
177 break;
178 case MIStrings.VERSION_NAME:
179 name = node.getTextContent();
180 break;
181 case MIStrings.VERSION_STR:
182 fullVersion = node.getTextContent();
183 break;
184 case MIStrings.VERSION_WEB:
185 url = node.getTextContent();
186 break;
187 default:
188 break;
189 }
190 }
191 setVersion(new LttngVersion(major, minor, patchLevel, license, commit, name, description, url, fullVersion));
192 } else {
193 throw new ExecutionException(Messages.TraceControl_UnsupportedVersionError);
194 }
195 }
196
197 @Override
198 public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
199 StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
200 ICommandResult result = executeCommand(command.toString(), monitor);
201
202 Document doc = getDocumentFromStrings(result.getOutput());
203
204 NodeList elements = doc.getElementsByTagName(MIStrings.NAME);
205
206 ArrayList<String> retArray = new ArrayList<>();
207 for (int i = 0; i < elements.getLength(); i++) {
208 Node node = elements.item(i);
209 if (node.getParentNode().getNodeName().equalsIgnoreCase(MIStrings.SESSION)) {
210 retArray.add(node.getTextContent());
211 }
212 }
213 return retArray.toArray(new String[retArray.size()]);
214 }
215
216 @Override
217 public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
218 StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
219 ICommandResult result = executeCommand(command.toString(), monitor);
220
221 ISessionInfo sessionInfo = new SessionInfo(sessionName);
222 Document document = getDocumentFromStrings(result.getOutput());
223
224 NodeList sessionsNode = document.getElementsByTagName(MIStrings.SESSION);
225 // There should be only one session
226 if (sessionsNode.getLength() != 1) {
227 throw new ExecutionException(Messages.TraceControl_MiInvalidNumberOfElementError);
228 }
229
230 // Populate session information
231 NodeList rawSessionInfos = sessionsNode.item(0).getChildNodes();
232 for (int i = 0; i < rawSessionInfos.getLength(); i++) {
233 Node rawInfo = rawSessionInfos.item(i);
234 switch (rawInfo.getNodeName()) {
235 case MIStrings.PATH:
236 sessionInfo.setSessionPath(rawInfo.getTextContent());
237 break;
238 case MIStrings.ENABLED:
239 sessionInfo.setSessionState(rawInfo.getTextContent());
240 break;
241 case MIStrings.SNAPSHOT_MODE:
242 if (rawInfo.getTextContent().equals(LTTngControlServiceConstants.TRUE_NUMERICAL)) {
243 // real name will be set later
244 ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$
245 sessionInfo.setSnapshotInfo(snapshotInfo);
246 }
247 break;
248 case MIStrings.LIVE_TIMER_INTERVAL:
249 // TODO : live mode not supported yet in TMF:lttng-control
250 break;
251 case MIStrings.DOMAINS:
252 // Extract the domains node
253 NodeList rawDomains = rawInfo.getChildNodes();
254 IDomainInfo domain = null;
255 for (int j = 0; j < rawDomains.getLength(); j++) {
256 if (rawDomains.item(j).getNodeName().equalsIgnoreCase(MIStrings.DOMAIN)) {
257 domain = parseDomain(rawDomains.item(j));
258 sessionInfo.addDomain(domain);
259 }
260 }
261 break;
262 default:
263 break;
264 }
265 }
266
267 if (!sessionInfo.isSnapshotSession()) {
268 Matcher matcher = LTTngControlServiceConstants.TRACE_NETWORK_PATTERN.matcher(sessionInfo.getSessionPath());
269 if (matcher.matches()) {
270 sessionInfo.setStreamedTrace(true);
271 }
272 }
273
274
275 // Fetch the snapshot info
276 if (sessionInfo.isSnapshotSession()) {
277 ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor);
278 sessionInfo.setSnapshotInfo(snapshot);
279 }
280
281 return sessionInfo;
282 }
283
284 /**
285 * Parse a raw domain XML node to a IDomainInfo object
286 *
287 * @param rawDomain
288 * a domain xml node
289 * @return a populated {@link DomainInfo} object
290 * @throws ExecutionException
291 * when missing required xml element (type)
292 */
293 protected IDomainInfo parseDomain(Node rawDomain) throws ExecutionException {
294 IDomainInfo domain = null;
295 // Get the type
296 Node rawType = getFirstOf(rawDomain.getChildNodes(), MIStrings.TYPE);
297 if (rawType == null) {
298 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
299 }
300 String rawTypeString = rawType.getTextContent().toLowerCase();
301 TraceDomainType domainType = TraceDomainType.valueOfString(rawTypeString);
302 switch (domainType) {
303 case KERNEL:
304 domain = new DomainInfo(Messages.TraceControl_KernelProviderDisplayName);
305 domain.setIsKernel(true);
306 break;
307 case UST:
308 domain = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
309 domain.setIsKernel(false);
310 break;
311 case JUL:
312 /**
313 * TODO: Support for JUL JUL substructure and semantic is not the
314 * same as a regular UST or Kernel Domain There is no channel under
315 * JUL domain only events. The channel is activated in UST Channel
316 */
317 domain = new DomainInfo(Messages.TraceControl_JULDomainDisplayName);
318 domain.setIsKernel(false);
319 break;
320 case UNKNOWN:
321 domain = new DomainInfo(Messages.TraceControl_UnknownDomainDisplayName);
322 domain.setIsKernel(false);
323 break;
324 default:
325 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
326 }
327
328 NodeList rawInfos = rawDomain.getChildNodes();
329 for (int i = 0; i < rawInfos.getLength(); i++) {
330 Node rawInfo = rawInfos.item(i);
331 switch (rawInfo.getNodeName()) {
332 case MIStrings.BUFFER_TYPE:
333 BufferType bufferType = BufferType.valueOfString(rawInfo.getTextContent());
334 domain.setBufferType(bufferType);
335 break;
336 case MIStrings.CHANNELS:
337 ArrayList<IChannelInfo> channels = new ArrayList<>();
338 parseChannels(rawInfo.getChildNodes(), channels);
339 if (channels.size() > 0) {
340 domain.setChannels(channels);
341 }
342 break;
343 default:
344 break;
345 }
346 }
347
348 return domain;
349 }
350
351 /**
352 * Parse a list of raw channel XML node into an ArrayList of IChannelInfo
353 *
354 * @param rawChannes
355 * List of raw channel XML node
356 * @param channels
357 * the parsed channels list
358 * @throws ExecutionException
359 * when missing required xml element (type)
360 */
361 private static void parseChannels(NodeList rawChannels, ArrayList<IChannelInfo> channels) throws ExecutionException {
362 IChannelInfo channel = null;
363 for (int i = 0; i < rawChannels.getLength(); i++) {
364 Node rawChannel = rawChannels.item(i);
365 if (rawChannel.getNodeName().equalsIgnoreCase(MIStrings.CHANNEL)) {
366 channel = new ChannelInfo(""); //$NON-NLS-1$
367
368 // Populate the channel
369 NodeList rawInfos = rawChannel.getChildNodes();
370 Node rawInfo = null;
371 for (int j = 0; j < rawInfos.getLength(); j++) {
372 rawInfo = rawInfos.item(j);
373 switch (rawInfo.getNodeName()) {
374 case MIStrings.NAME:
375 channel.setName(rawInfo.getTextContent());
376 break;
377 case MIStrings.ENABLED:
378 channel.setState(TraceEnablement.valueOfString(rawInfo.getTextContent()));
379 break;
380 case MIStrings.EVENTS:
381 List<IEventInfo> events = new ArrayList<>();
382 getEventInfo(rawInfo.getChildNodes(), events);
383 channel.setEvents(events);
384 break;
385 case MIStrings.ATTRIBUTES:
386 NodeList rawAttributes = rawInfo.getChildNodes();
387 for (int k = 0; k < rawAttributes.getLength(); k++) {
388 Node attribute = rawAttributes.item(k);
389 switch (attribute.getNodeName()) {
390 case MIStrings.OVERWRITE_MODE:
391 channel.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE_MI.equalsIgnoreCase(attribute.getTextContent()));
392 break;
393 case MIStrings.SUBBUF_SIZE:
394 channel.setSubBufferSize(Long.valueOf(attribute.getTextContent()));
395 break;
396 case MIStrings.NUM_SUBBUF:
397 channel.setNumberOfSubBuffers(Integer.valueOf(attribute.getTextContent()));
398 break;
399 case MIStrings.SWITCH_TIMER_INTERVAL:
400 channel.setSwitchTimer(Long.valueOf(attribute.getTextContent()));
401 break;
402 case MIStrings.READ_TIMER_INTERVAL:
403 channel.setReadTimer(Long.valueOf(attribute.getTextContent()));
404 break;
405 case MIStrings.OUTPUT_TYPE:
406 channel.setOutputType(attribute.getTextContent());
407 break;
408 case MIStrings.TRACEFILE_SIZE:
409 channel.setMaxSizeTraceFiles(Integer.parseInt(attribute.getTextContent()));
410 break;
411 case MIStrings.TRACEFILE_COUNT:
412 channel.setMaxNumberTraceFiles(Integer.parseInt(attribute.getTextContent()));
413 break;
414 case MIStrings.LIVE_TIMER_INTERVAL:
415 // TODO: currently not supported by tmf
416 break;
417 default:
418 break;
419 }
420 }
421 break;
422 default:
423 break;
424 }
425 }
426 channels.add(channel);
427 }
428 }
429
430 }
431
432 @Override
433 public ISnapshotInfo getSnapshotInfo(String sessionName, IProgressMonitor monitor) throws ExecutionException {
434 // TODO JRJ - STUB
435 return null;
436 }
437
438 @Override
439 public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
440 StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL);
441 ICommandResult result = executeCommand(command.toString(), monitor, false);
442 List<IBaseEventInfo> events = new ArrayList<>();
443
444 if (isError(result)) {
445 return events;
446 }
447
448 Document document = getDocumentFromStrings(result.getOutput());
449 NodeList rawEvents = document.getElementsByTagName(MIStrings.EVENT);
450 getBaseEventInfo(rawEvents, events);
451 return events;
452 }
453
454 @Override
455 public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
456 StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST);
457 // Get the field to
458 command.append(LTTngControlServiceConstants.OPTION_FIELDS);
459
460 // Execute
461 ICommandResult result = executeCommand(command.toString(), monitor, false);
462 List<IUstProviderInfo> allProviders = new ArrayList<>();
463
464 if (isError(result)) {
465 return allProviders;
466 }
467
468 Document document = getDocumentFromStrings(result.getOutput());
469 NodeList rawProviders = document.getElementsByTagName(MIStrings.PID);
470
471 IUstProviderInfo providerInfo = null;
472
473 for (int i = 0; i < rawProviders.getLength(); i++) {
474 Node provider = rawProviders.item(i);
475 Node name = getFirstOf(provider.getChildNodes(), MIStrings.NAME);
476 if (name == null) {
477 throw new ExecutionException(Messages.TraceControl_MiInvalidProviderError);
478 }
479 providerInfo = new UstProviderInfo(name.getTextContent());
480
481 // Populate provider
482 NodeList infos = provider.getChildNodes();
483 for (int j = 0; j < infos.getLength(); j++) {
484 Node info = infos.item(j);
485 switch (info.getNodeName()) {
486 case MIStrings.PID_ID:
487 providerInfo.setPid(Integer.parseInt(info.getTextContent()));
488 break;
489 case MIStrings.EVENTS:
490 List<IBaseEventInfo> events = new ArrayList<>();
491 NodeList rawEvents = info.getChildNodes();
492 getBaseEventInfo(rawEvents, events);
493 providerInfo.setEvents(events);
494 break;
495 default:
496 break;
497 }
498 }
499 allProviders.add(providerInfo);
500 }
501
502 return allProviders;
503 }
504
505 @Override
506 public ISessionInfo createSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
507 // TODO Auto-generated method stub
508 return null;
509 }
510
511 @Override
512 public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
513 // TODO Auto-generated method stub
514
515 }
516
517 @Override
518 public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
519 // TODO Auto-generated method stub
520
521 }
522
523 @Override
524 public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
525 // TODO Auto-generated method stub
526
527 }
528
529 @Override
530 public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
531 // TODO Auto-generated method stub
532
533 }
534
535 @Override
536 public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
537 // TODO Auto-generated method stub
538
539 }
540
541 @Override
542 public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
543 // TODO Auto-generated method stub
544
545 }
546
547 @Override
548 public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException {
549 // TODO Auto-generated method stub
550
551 }
552
553 @Override
554 public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
555 // TODO Auto-generated method stub
556
557 }
558
559 @Override
560 public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
561 // TODO Auto-generated method stub
562
563 }
564
565 @Override
566 public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
567 // TODO Auto-generated method stub
568
569 }
570
571 @Override
572 public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
573 // TODO Auto-generated method stub
574 return null;
575 }
576
577 @Override
578 public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
579 // TODO Auto-generated method stub
580
581 }
582
583 @Override
584 public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
585 // TODO Auto-generated method stub
586
587 }
588
589 @Override
590 public void recordSnapshot(String sessionName, IProgressMonitor monitor) throws ExecutionException {
591 // TODO Auto-generated method stub
592
593 }
594
595 @Override
596 public void runCommands(IProgressMonitor monitor, List<String> commands) throws ExecutionException {
597 // TODO Auto-generated method stub
598
599 }
600
601 /**
602 * @param strings
603 * array of string that make up a command line
604 * @return string buffer with created command line
605 */
606 @Override
607 protected StringBuffer createCommand(String... strings) {
608 StringBuffer command = new StringBuffer();
609 command.append(LTTngControlServiceConstants.CONTROL_COMMAND_MI_XML);
610 command.append(getTracingGroupOption());
611 for (String string : strings) {
612 command.append(string);
613 }
614 return command;
615 }
616
617 /**
618 * @param xmlBaseEvents
619 * a Node list of base xml event element
620 * @param events
621 * list of event generated by the parsing of the xml event
622 * element
623 * @throws ExecutionException
624 * when a raw event is not a complete/valid xml event
625 */
626 private static void getBaseEventInfo(NodeList xmlBaseEvents, List<IBaseEventInfo> events) throws ExecutionException {
627 IBaseEventInfo eventInfo = null;
628 for (int i = 0; i < xmlBaseEvents.getLength(); i++) {
629 NodeList rawInfos = xmlBaseEvents.item(i).getChildNodes();
630 // Search for name
631 if (xmlBaseEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
632 Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
633 if (rawName == null) {
634 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
635 }
636 eventInfo = new BaseEventInfo(rawName.getTextContent());
637
638 // Populate the event
639 for (int j = 0; j < rawInfos.getLength(); j++) {
640 Node infoNode = rawInfos.item(j);
641 switch (infoNode.getNodeName()) {
642 case MIStrings.TYPE:
643 eventInfo.setEventType(infoNode.getTextContent());
644 break;
645 case MIStrings.LOGLEVEL:
646 eventInfo.setLogLevel(infoNode.getTextContent());
647 break;
648 case MIStrings.EVENT_FIELDS:
649 List<IFieldInfo> fields = new ArrayList<>();
650 getFieldInfo(infoNode.getChildNodes(), fields);
651 eventInfo.setFields(fields);
652 break;
653 default:
654 break;
655 }
656 }
657 events.add(eventInfo);
658 }
659 }
660 }
661
662 /**
663 * @param xmlBaseEvents
664 * a Node list of xml event element linked to a session
665 * @param events
666 * list of event generated by the parsing of the xml event
667 * element
668 * @throws ExecutionException
669 * when a raw event is not a complete/valid xml event
670 */
671 static void getEventInfo(NodeList xmlEvents, List<IEventInfo> events) throws ExecutionException {
672 IEventInfo eventInfo = null;
673 for (int i = 0; i < xmlEvents.getLength(); i++) {
674 NodeList rawInfos = xmlEvents.item(i).getChildNodes();
675 // Search for name
676 if (xmlEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
677 Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
678 if (rawName == null) {
679 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
680 }
681
682 eventInfo = new EventInfo(rawName.getTextContent());
683
684 // Basic information
685 for (int j = 0; j < rawInfos.getLength(); j++) {
686 Node infoNode = rawInfos.item(j);
687 switch (infoNode.getNodeName()) {
688 case MIStrings.TYPE:
689 eventInfo.setEventType(infoNode.getTextContent());
690 break;
691 case MIStrings.LOGLEVEL_TYPE:
692 eventInfo.setLogLevelType(LogLevelType.valueOfString(infoNode.getTextContent()));
693 break;
694 case MIStrings.LOGLEVEL:
695 eventInfo.setLogLevel(TraceLogLevel.valueOfString(infoNode.getTextContent()));
696 break;
697 case MIStrings.ENABLED:
698 eventInfo.setState(TraceEnablement.valueOfString(infoNode.getTextContent()));
699 break;
700 case MIStrings.FILTER:
701 // TODO
702 // See bug 334 http://bugs.lttng.org/issues/334 from
703 // LTTng
704 // For now we emulate the a behavior, and simply put
705 // "with filter"
706 eventInfo.setFilterExpression("with filter"); //$NON-NLS-1$
707 break;
708 case MIStrings.EXCLUSION:
709 // TODO:Currently not supported by tmf
710 // ExclusionS element is ignored
711 break;
712 default:
713 break;
714 }
715 }
716
717 boolean isProbeFunction = (eventInfo.getEventType().equals(TraceEventType.PROBE)) || (eventInfo.getEventType().equals(TraceEventType.FUNCTION));
718 if (isProbeFunction) {
719 IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo);
720 eventInfo = probeEvent;
721 // get attributes
722 Node rawAttributes = getFirstOf(rawInfos, MIStrings.ATTRIBUTES);
723 if (rawAttributes == null) {
724 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
725 }
726
727 Node rawDataNode = null;
728 switch (probeEvent.getEventType()) {
729 case PROBE:
730 rawDataNode = getFirstOf(rawAttributes.getChildNodes(), MIStrings.PROBE_ATTRIBUTES);
731 break;
732 case FUNCTION:
733 rawDataNode = getFirstOf(rawAttributes.getChildNodes(), MIStrings.FUNCTION_ATTRIBUTES);
734 break;
735 case SYSCALL:
736 case TRACEPOINT:
737 case UNKNOWN:
738 default:
739 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
740 }
741
742 if (rawDataNode == null) {
743 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
744 }
745
746 // Extract info
747 NodeList rawDatas = rawDataNode.getChildNodes();
748 for (int j = 0; j < rawDatas.getLength(); j++) {
749 Node rawData = rawDatas.item(j);
750 switch (rawData.getNodeName()) {
751 case MIStrings.SYMBOL_NAME:
752 probeEvent.setSymbol(rawData.getTextContent());
753 break;
754 case MIStrings.ADDRESS:
755 probeEvent.setAddress(rawData.getTextContent());
756 break;
757 case MIStrings.OFFSET:
758 probeEvent.setOffset(rawData.getTextContent());
759 break;
760 default:
761 break;
762 }
763 }
764 }
765
766 // Syscalls does not have name.
767 // Let put one to make sure this is user friendly via UI
768 if (eventInfo.getEventType().equals(TraceEventType.SYSCALL)) {
769 eventInfo.setName(TraceEventType.SYSCALL.getInName());
770 }
771
772 // Add the event
773 events.add(eventInfo);
774 }
775 }
776 }
777
778 /**
779 * @param fieldsList
780 * a list of xml event_field element
781 * @param fields
782 * a list of field generated by xml parsing
783 * @throws ExecutionException
784 * when parsing fail or required elements are missing
785 */
786 private static void getFieldInfo(NodeList fieldsList, List<IFieldInfo> fields) throws ExecutionException {
787 IFieldInfo fieldInfo = null;
788 for (int i = 0; i < fieldsList.getLength(); i++) {
789 Node field = fieldsList.item(i);
790 if (field.getNodeName().equalsIgnoreCase(MIStrings.EVENT_FIELD)) {
791 // Get name
792 Node name = getFirstOf(field.getChildNodes(), MIStrings.NAME);
793 if (name == null) {
794 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
795 }
796 fieldInfo = new FieldInfo(name.getTextContent());
797
798 // Populate the field information
799 NodeList infos = field.getChildNodes();
800 for (int j = 0; j < infos.getLength(); j++) {
801 Node info = infos.item(j);
802 switch (info.getNodeName()) {
803 case MIStrings.TYPE:
804 fieldInfo.setFieldType(info.getTextContent());
805 break;
806 default:
807 break;
808 }
809 }
810 fields.add(fieldInfo);
811 }
812 }
813 }
814
815 /**
816 * Retrieve the fist instance of a given node with tag name equal to tagName
817 * parameter
818 *
819 * @param nodeList
820 * the list of Node to search against
821 * @param tagName
822 * the tag name of the desired node
823 * @return the first occurrence of a node with a tag name equals to tagName
824 */
825 private static Node getFirstOf(NodeList nodeList, String tagName) {
826 Node node = null;
827 for (int i = 0; i < nodeList.getLength(); i++) {
828 if (nodeList.item(i).getNodeName() == tagName) {
829 node = nodeList.item(i);
830 break;
831 }
832 }
833 return node;
834 }
835
836 }
This page took 0.050753 seconds and 4 git commands to generate.