1 /**********************************************************************
2 * Copyright (c) 2014 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 * Jonathan Rajotte - Initial support for machine interface lttng 2.6
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.service
;
15 import java
.io
.IOException
;
16 import java
.io
.StringReader
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
20 import java
.util
.regex
.Matcher
;
22 import javax
.xml
.parsers
.DocumentBuilder
;
23 import javax
.xml
.parsers
.DocumentBuilderFactory
;
24 import javax
.xml
.parsers
.ParserConfigurationException
;
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
;
63 * Service for sending LTTng trace control commands to remote host via machine
66 * @author Jonathan Rajotte
68 public class LTTngControlServiceMI
extends LTTngControlService
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
74 private final DocumentBuilder fDocumentBuilder
;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
84 * the command shell implementation to use
86 * the xsd schema file for validation
87 * @throws ExecutionException
88 * if the creation of the Schema and DocumentBuilder objects
91 public LTTngControlServiceMI(ICommandShell shell
, URL xsdUrl
) throws ExecutionException
{
94 DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory
.newInstance();
95 docBuilderFactory
.setValidating(false);
97 // TODO: Add xsd validation for machine interface via mi_lttng.xsd from LTTng
99 fDocumentBuilder
= docBuilderFactory
.newDocumentBuilder();
100 } catch (ParserConfigurationException e
) {
101 throw new ExecutionException(Messages
.TraceControl_XmlDocumentBuilderError
, e
);
104 fDocumentBuilder
.setErrorHandler(new XmlMiValidationErrorHandler());
109 * Generate a Document object from an array of String.
112 * array of strings representing an xml input
113 * @return Document generated from strings input
114 * @throws ExecutionException
115 * when parsing has failed
117 private Document
getDocumentFromStrings(String
[] xmlStrings
) throws ExecutionException
{
118 StringBuilder concatenedString
= new StringBuilder();
119 for (String string
: xmlStrings
) {
120 concatenedString
.append(string
);
122 InputSource stream
= new InputSource(new StringReader(concatenedString
.toString()));
126 document
= fDocumentBuilder
.parse(stream
);
127 } catch (SAXException
| IOException e
) {
128 throw new ExecutionException(Messages
.TraceControl_XmlParsingError
, e
);
135 * Parse, populate and set the internal LTTngVersion variable
138 * the mi xml output of lttng version
139 * @throws ExecutionException
140 * when xml extraction fail
142 public void setVersion(String
[] xmlOutput
) throws ExecutionException
{
143 Document doc
= getDocumentFromStrings(xmlOutput
);
144 NodeList element
= doc
.getElementsByTagName(MIStrings
.VERSION
);
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());
163 case MIStrings
.VERSION_MINOR
:
164 minor
= Integer
.parseInt(node
.getTextContent());
166 case MIStrings
.VERSION_PATCH_LEVEL
:
167 patchLevel
= Integer
.parseInt(node
.getTextContent());
169 case MIStrings
.VERSION_COMMIT
:
170 commit
= node
.getTextContent();
172 case MIStrings
.VERSION_DESCRIPTION
:
173 description
= node
.getTextContent();
175 case MIStrings
.VERSION_LICENSE
:
176 license
= node
.getTextContent();
178 case MIStrings
.VERSION_NAME
:
179 name
= node
.getTextContent();
181 case MIStrings
.VERSION_STR
:
182 fullVersion
= node
.getTextContent();
184 case MIStrings
.VERSION_WEB
:
185 url
= node
.getTextContent();
191 setVersion(new LttngVersion(major
, minor
, patchLevel
, license
, commit
, name
, description
, url
, fullVersion
));
193 throw new ExecutionException(Messages
.TraceControl_UnsupportedVersionError
);
198 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
199 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
200 ICommandResult result
= executeCommand(command
.toString(), monitor
);
202 Document doc
= getDocumentFromStrings(result
.getOutput());
204 NodeList elements
= doc
.getElementsByTagName(MIStrings
.NAME
);
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());
213 return retArray
.toArray(new String
[retArray
.size()]);
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
);
221 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
222 Document document
= getDocumentFromStrings(result
.getOutput());
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
);
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()) {
236 sessionInfo
.setSessionPath(rawInfo
.getTextContent());
238 case MIStrings
.ENABLED
:
239 sessionInfo
.setSessionState(rawInfo
.getTextContent());
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
);
248 case MIStrings
.LIVE_TIMER_INTERVAL
:
249 // TODO : live mode not supported yet in TMF:lttng-control
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
);
267 if (!sessionInfo
.isSnapshotSession()) {
268 Matcher matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATTERN
.matcher(sessionInfo
.getSessionPath());
269 if (matcher
.matches()) {
270 sessionInfo
.setStreamedTrace(true);
275 // Fetch the snapshot info
276 if (sessionInfo
.isSnapshotSession()) {
277 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
278 sessionInfo
.setSnapshotInfo(snapshot
);
285 * Parse a raw domain XML node to a IDomainInfo object
289 * @return a populated {@link DomainInfo} object
290 * @throws ExecutionException
291 * when missing required xml element (type)
293 protected IDomainInfo
parseDomain(Node rawDomain
) throws ExecutionException
{
294 IDomainInfo domain
= null;
296 Node rawType
= getFirstOf(rawDomain
.getChildNodes(), MIStrings
.TYPE
);
297 if (rawType
== null) {
298 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
300 String rawTypeString
= rawType
.getTextContent().toLowerCase();
301 TraceDomainType domainType
= TraceDomainType
.valueOfString(rawTypeString
);
302 switch (domainType
) {
304 domain
= new DomainInfo(Messages
.TraceControl_KernelProviderDisplayName
);
305 domain
.setIsKernel(true);
308 domain
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
309 domain
.setIsKernel(false);
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
317 domain
= new DomainInfo(Messages
.TraceControl_JULDomainDisplayName
);
318 domain
.setIsKernel(false);
321 domain
= new DomainInfo(Messages
.TraceControl_UnknownDomainDisplayName
);
322 domain
.setIsKernel(false);
325 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
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
);
336 case MIStrings
.CHANNELS
:
337 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
338 parseChannels(rawInfo
.getChildNodes(), channels
);
339 if (channels
.size() > 0) {
340 domain
.setChannels(channels
);
352 * Parse a list of raw channel XML node into an ArrayList of IChannelInfo
355 * List of raw channel XML node
357 * the parsed channels list
358 * @throws ExecutionException
359 * when missing required xml element (type)
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$
368 // Populate the channel
369 NodeList rawInfos
= rawChannel
.getChildNodes();
371 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
372 rawInfo
= rawInfos
.item(j
);
373 switch (rawInfo
.getNodeName()) {
375 channel
.setName(rawInfo
.getTextContent());
377 case MIStrings
.ENABLED
:
378 channel
.setState(TraceEnablement
.valueOfString(rawInfo
.getTextContent()));
380 case MIStrings
.EVENTS
:
381 List
<IEventInfo
> events
= new ArrayList
<>();
382 getEventInfo(rawInfo
.getChildNodes(), events
);
383 channel
.setEvents(events
);
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()));
393 case MIStrings
.SUBBUF_SIZE
:
394 channel
.setSubBufferSize(Long
.valueOf(attribute
.getTextContent()));
396 case MIStrings
.NUM_SUBBUF
:
397 channel
.setNumberOfSubBuffers(Integer
.valueOf(attribute
.getTextContent()));
399 case MIStrings
.SWITCH_TIMER_INTERVAL
:
400 channel
.setSwitchTimer(Long
.valueOf(attribute
.getTextContent()));
402 case MIStrings
.READ_TIMER_INTERVAL
:
403 channel
.setReadTimer(Long
.valueOf(attribute
.getTextContent()));
405 case MIStrings
.OUTPUT_TYPE
:
406 channel
.setOutputType(attribute
.getTextContent());
408 case MIStrings
.TRACEFILE_SIZE
:
409 channel
.setMaxSizeTraceFiles(Integer
.parseInt(attribute
.getTextContent()));
411 case MIStrings
.TRACEFILE_COUNT
:
412 channel
.setMaxNumberTraceFiles(Integer
.parseInt(attribute
.getTextContent()));
414 case MIStrings
.LIVE_TIMER_INTERVAL
:
415 // TODO: currently not supported by tmf
426 channels
.add(channel
);
433 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
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
<>();
444 if (isError(result
)) {
448 Document document
= getDocumentFromStrings(result
.getOutput());
449 NodeList rawEvents
= document
.getElementsByTagName(MIStrings
.EVENT
);
450 getBaseEventInfo(rawEvents
, events
);
455 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
456 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
458 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
461 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
462 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
464 if (isError(result
)) {
468 Document document
= getDocumentFromStrings(result
.getOutput());
469 NodeList rawProviders
= document
.getElementsByTagName(MIStrings
.PID
);
471 IUstProviderInfo providerInfo
= null;
473 for (int i
= 0; i
< rawProviders
.getLength(); i
++) {
474 Node provider
= rawProviders
.item(i
);
475 Node name
= getFirstOf(provider
.getChildNodes(), MIStrings
.NAME
);
477 throw new ExecutionException(Messages
.TraceControl_MiInvalidProviderError
);
479 providerInfo
= new UstProviderInfo(name
.getTextContent());
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()));
489 case MIStrings
.EVENTS
:
490 List
<IBaseEventInfo
> events
= new ArrayList
<>();
491 NodeList rawEvents
= info
.getChildNodes();
492 getBaseEventInfo(rawEvents
, events
);
493 providerInfo
.setEvents(events
);
499 allProviders
.add(providerInfo
);
506 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
507 // TODO Auto-generated method stub
512 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
513 // TODO Auto-generated method stub
518 public void startSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
519 // TODO Auto-generated method stub
524 public void stopSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
525 // TODO Auto-generated method stub
530 public void enableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IChannelInfo info
, IProgressMonitor monitor
) throws ExecutionException
{
531 // TODO Auto-generated method stub
536 public void disableChannels(String sessionName
, List
<String
> channelNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
537 // TODO Auto-generated method stub
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
548 public void enableSyscalls(String sessionName
, String channelName
, IProgressMonitor monitor
) throws ExecutionException
{
549 // TODO Auto-generated method stub
554 public void enableProbe(String sessionName
, String channelName
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
555 // TODO Auto-generated method stub
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
566 public void disableEvent(String sessionName
, String channelName
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
567 // TODO Auto-generated method stub
572 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
573 // TODO Auto-generated method stub
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
584 public void calibrate(boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
585 // TODO Auto-generated method stub
590 public void recordSnapshot(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
591 // TODO Auto-generated method stub
596 public void runCommands(IProgressMonitor monitor
, List
<String
> commands
) throws ExecutionException
{
597 // TODO Auto-generated method stub
603 * array of string that make up a command line
604 * @return string buffer with created command line
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
);
618 * @param xmlBaseEvents
619 * a Node list of base xml event element
621 * list of event generated by the parsing of the xml event
623 * @throws ExecutionException
624 * when a raw event is not a complete/valid xml event
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();
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
);
636 eventInfo
= new BaseEventInfo(rawName
.getTextContent());
638 // Populate the event
639 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
640 Node infoNode
= rawInfos
.item(j
);
641 switch (infoNode
.getNodeName()) {
643 eventInfo
.setEventType(infoNode
.getTextContent());
645 case MIStrings
.LOGLEVEL
:
646 eventInfo
.setLogLevel(infoNode
.getTextContent());
648 case MIStrings
.EVENT_FIELDS
:
649 List
<IFieldInfo
> fields
= new ArrayList
<>();
650 getFieldInfo(infoNode
.getChildNodes(), fields
);
651 eventInfo
.setFields(fields
);
657 events
.add(eventInfo
);
663 * @param xmlBaseEvents
664 * a Node list of xml event element linked to a session
666 * list of event generated by the parsing of the xml event
668 * @throws ExecutionException
669 * when a raw event is not a complete/valid xml event
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();
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
);
682 eventInfo
= new EventInfo(rawName
.getTextContent());
685 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
686 Node infoNode
= rawInfos
.item(j
);
687 switch (infoNode
.getNodeName()) {
689 eventInfo
.setEventType(infoNode
.getTextContent());
691 case MIStrings
.LOGLEVEL_TYPE
:
692 eventInfo
.setLogLevelType(LogLevelType
.valueOfString(infoNode
.getTextContent()));
694 case MIStrings
.LOGLEVEL
:
695 eventInfo
.setLogLevel(TraceLogLevel
.valueOfString(infoNode
.getTextContent()));
697 case MIStrings
.ENABLED
:
698 eventInfo
.setState(TraceEnablement
.valueOfString(infoNode
.getTextContent()));
700 case MIStrings
.FILTER
:
702 // See bug 334 http://bugs.lttng.org/issues/334 from
704 // For now we emulate the a behavior, and simply put
706 eventInfo
.setFilterExpression("with filter"); //$NON-NLS-1$
708 case MIStrings
.EXCLUSION
:
709 // TODO:Currently not supported by tmf
710 // ExclusionS element is ignored
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
;
722 Node rawAttributes
= getFirstOf(rawInfos
, MIStrings
.ATTRIBUTES
);
723 if (rawAttributes
== null) {
724 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
727 Node rawDataNode
= null;
728 switch (probeEvent
.getEventType()) {
730 rawDataNode
= getFirstOf(rawAttributes
.getChildNodes(), MIStrings
.PROBE_ATTRIBUTES
);
733 rawDataNode
= getFirstOf(rawAttributes
.getChildNodes(), MIStrings
.FUNCTION_ATTRIBUTES
);
739 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
742 if (rawDataNode
== null) {
743 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
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());
754 case MIStrings
.ADDRESS
:
755 probeEvent
.setAddress(rawData
.getTextContent());
757 case MIStrings
.OFFSET
:
758 probeEvent
.setOffset(rawData
.getTextContent());
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());
773 events
.add(eventInfo
);
780 * a list of xml event_field element
782 * a list of field generated by xml parsing
783 * @throws ExecutionException
784 * when parsing fail or required elements are missing
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
)) {
792 Node name
= getFirstOf(field
.getChildNodes(), MIStrings
.NAME
);
794 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
796 fieldInfo
= new FieldInfo(name
.getTextContent());
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()) {
804 fieldInfo
.setFieldType(info
.getTextContent());
810 fields
.add(fieldInfo
);
816 * Retrieve the fist instance of a given node with tag name equal to tagName
820 * the list of Node to search against
822 * the tag name of the desired node
823 * @return the first occurrence of a node with a tag name equals to tagName
825 private static Node
getFirstOf(NodeList nodeList
, String tagName
) {
827 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
828 if (nodeList
.item(i
).getNodeName() == tagName
) {
829 node
= nodeList
.item(i
);