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
.eclipse
.osgi
.util
.NLS
;
57 import org
.w3c
.dom
.Document
;
58 import org
.w3c
.dom
.Node
;
59 import org
.w3c
.dom
.NodeList
;
60 import org
.xml
.sax
.InputSource
;
61 import org
.xml
.sax
.SAXException
;
64 * Service for sending LTTng trace control commands to remote host via machine
67 * @author Jonathan Rajotte
69 public class LTTngControlServiceMI
extends LTTngControlService
{
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 private final DocumentBuilder fDocumentBuilder
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
85 * the command shell implementation to use
87 * the xsd schema file for validation
88 * @throws ExecutionException
89 * if the creation of the Schema and DocumentBuilder objects
92 public LTTngControlServiceMI(ICommandShell shell
, URL xsdUrl
) throws ExecutionException
{
95 DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory
.newInstance();
96 docBuilderFactory
.setValidating(false);
98 // TODO: Add xsd validation for machine interface via mi_lttng.xsd from LTTng
100 fDocumentBuilder
= docBuilderFactory
.newDocumentBuilder();
101 } catch (ParserConfigurationException e
) {
102 throw new ExecutionException(Messages
.TraceControl_XmlDocumentBuilderError
, e
);
105 fDocumentBuilder
.setErrorHandler(new XmlMiValidationErrorHandler());
110 * Generate a Document object from an array of String.
113 * array of strings representing an xml input
114 * @return Document generated from strings input
115 * @throws ExecutionException
116 * when parsing has failed
118 private Document
getDocumentFromStrings(String
[] xmlStrings
) throws ExecutionException
{
119 StringBuilder concatenedString
= new StringBuilder();
120 for (String string
: xmlStrings
) {
121 concatenedString
.append(string
);
123 InputSource stream
= new InputSource(new StringReader(concatenedString
.toString()));
127 document
= fDocumentBuilder
.parse(stream
);
128 } catch (SAXException
| IOException e
) {
129 throw new ExecutionException(Messages
.TraceControl_XmlParsingError
, e
);
136 * Parse, populate and set the internal LTTngVersion variable
139 * the mi xml output of lttng version
140 * @throws ExecutionException
141 * when xml extraction fail
143 public void setVersion(String
[] xmlOutput
) throws ExecutionException
{
144 Document doc
= getDocumentFromStrings(xmlOutput
);
145 NodeList element
= doc
.getElementsByTagName(MIStrings
.VERSION
);
149 String license
= ""; //$NON-NLS-1$
150 String commit
= ""; //$NON-NLS-1$
151 String name
= ""; //$NON-NLS-1$
152 String description
= ""; //$NON-NLS-1$
153 String url
= ""; //$NON-NLS-1$
154 String fullVersion
= ""; //$NON-NLS-1$
155 if (element
.getLength() == 1) {
156 NodeList child
= element
.item(0).getChildNodes();
157 // Get basic information
158 for (int i
= 0; i
< child
.getLength(); i
++) {
159 Node node
= child
.item(i
);
160 switch (node
.getNodeName()) {
161 case MIStrings
.VERSION_MAJOR
:
162 major
= Integer
.parseInt(node
.getTextContent());
164 case MIStrings
.VERSION_MINOR
:
165 minor
= Integer
.parseInt(node
.getTextContent());
167 case MIStrings
.VERSION_PATCH_LEVEL
:
168 patchLevel
= Integer
.parseInt(node
.getTextContent());
170 case MIStrings
.VERSION_COMMIT
:
171 commit
= node
.getTextContent();
173 case MIStrings
.VERSION_DESCRIPTION
:
174 description
= node
.getTextContent();
176 case MIStrings
.VERSION_LICENSE
:
177 license
= node
.getTextContent();
179 case MIStrings
.VERSION_NAME
:
180 name
= node
.getTextContent();
182 case MIStrings
.VERSION_STR
:
183 fullVersion
= node
.getTextContent();
185 case MIStrings
.VERSION_WEB
:
186 url
= node
.getTextContent();
192 setVersion(new LttngVersion(major
, minor
, patchLevel
, license
, commit
, name
, description
, url
, fullVersion
));
194 throw new ExecutionException(Messages
.TraceControl_UnsupportedVersionError
);
199 public String
[] getSessionNames(IProgressMonitor monitor
) throws ExecutionException
{
200 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
);
201 ICommandResult result
= executeCommand(command
.toString(), monitor
);
203 Document doc
= getDocumentFromStrings(result
.getOutput());
205 NodeList elements
= doc
.getElementsByTagName(MIStrings
.NAME
);
207 ArrayList
<String
> retArray
= new ArrayList
<>();
208 for (int i
= 0; i
< elements
.getLength(); i
++) {
209 Node node
= elements
.item(i
);
210 if (node
.getParentNode().getNodeName().equalsIgnoreCase(MIStrings
.SESSION
)) {
211 retArray
.add(node
.getTextContent());
214 return retArray
.toArray(new String
[retArray
.size()]);
218 public ISessionInfo
getSession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
219 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST
, sessionName
);
220 ICommandResult result
= executeCommand(command
.toString(), monitor
);
222 ISessionInfo sessionInfo
= new SessionInfo(sessionName
);
223 Document document
= getDocumentFromStrings(result
.getOutput());
225 NodeList sessionsNode
= document
.getElementsByTagName(MIStrings
.SESSION
);
226 // There should be only one session
227 if (sessionsNode
.getLength() != 1) {
228 throw new ExecutionException(NLS
.bind(Messages
.TraceControl_MiInvalidNumberOfElementError
, MIStrings
.SESSION
));
231 // Populate session information
232 Node rawSession
= sessionsNode
.item(0);
233 parseSession(sessionInfo
, rawSession
);
235 // Fetch the snapshot info
236 if (sessionInfo
.isSnapshotSession()) {
237 ISnapshotInfo snapshot
= getSnapshotInfo(sessionName
, monitor
);
238 sessionInfo
.setSnapshotInfo(snapshot
);
247 * @throws ExecutionException
249 private void parseSession(ISessionInfo sessionInfo
, Node rawSession
) throws ExecutionException
{
250 if (!rawSession
.getNodeName().equalsIgnoreCase(MIStrings
.SESSION
)) {
251 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
253 NodeList rawSessionInfos
= rawSession
.getChildNodes();
254 for (int i
= 0; i
< rawSessionInfos
.getLength(); i
++) {
255 Node rawInfo
= rawSessionInfos
.item(i
);
256 switch (rawInfo
.getNodeName()) {
258 sessionInfo
.setName(rawInfo
.getTextContent());
261 sessionInfo
.setSessionPath(rawInfo
.getTextContent());
263 case MIStrings
.ENABLED
:
264 sessionInfo
.setSessionState(rawInfo
.getTextContent());
266 case MIStrings
.SNAPSHOT_MODE
:
267 if (rawInfo
.getTextContent().equals(LTTngControlServiceConstants
.TRUE_NUMERICAL
)) {
268 // real name will be set later
269 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
270 sessionInfo
.setSnapshotInfo(snapshotInfo
);
273 case MIStrings
.LIVE_TIMER_INTERVAL
:
274 // TODO : live mode not supported yet in TMF:lttng-control
276 case MIStrings
.DOMAINS
:
277 // Extract the domains node
278 NodeList rawDomains
= rawInfo
.getChildNodes();
279 IDomainInfo domain
= null;
280 for (int j
= 0; j
< rawDomains
.getLength(); j
++) {
281 if (rawDomains
.item(j
).getNodeName().equalsIgnoreCase(MIStrings
.DOMAIN
)) {
282 domain
= parseDomain(rawDomains
.item(j
));
283 sessionInfo
.addDomain(domain
);
292 if (!sessionInfo
.isSnapshotSession()) {
293 Matcher matcher
= LTTngControlServiceConstants
.TRACE_NETWORK_PATTERN
.matcher(sessionInfo
.getSessionPath());
294 if (matcher
.matches()) {
295 sessionInfo
.setStreamedTrace(true);
301 * Parse a raw domain XML node to a IDomainInfo object
305 * @return a populated {@link DomainInfo} object
306 * @throws ExecutionException
307 * when missing required xml element (type)
309 protected IDomainInfo
parseDomain(Node rawDomain
) throws ExecutionException
{
310 IDomainInfo domain
= null;
312 Node rawType
= getFirstOf(rawDomain
.getChildNodes(), MIStrings
.TYPE
);
313 if (rawType
== null) {
314 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
316 String rawTypeString
= rawType
.getTextContent().toLowerCase();
317 TraceDomainType domainType
= TraceDomainType
.valueOfString(rawTypeString
);
318 switch (domainType
) {
320 domain
= new DomainInfo(Messages
.TraceControl_KernelProviderDisplayName
);
321 domain
.setIsKernel(true);
324 domain
= new DomainInfo(Messages
.TraceControl_UstGlobalDomainDisplayName
);
325 domain
.setIsKernel(false);
329 * TODO: Support for JUL JUL substructure and semantic is not the
330 * same as a regular UST or Kernel Domain There is no channel under
331 * JUL domain only events. The channel is activated in UST Channel
333 domain
= new DomainInfo(Messages
.TraceControl_JULDomainDisplayName
);
334 domain
.setIsKernel(false);
337 domain
= new DomainInfo(Messages
.TraceControl_UnknownDomainDisplayName
);
338 domain
.setIsKernel(false);
341 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
344 NodeList rawInfos
= rawDomain
.getChildNodes();
345 for (int i
= 0; i
< rawInfos
.getLength(); i
++) {
346 Node rawInfo
= rawInfos
.item(i
);
347 switch (rawInfo
.getNodeName()) {
348 case MIStrings
.BUFFER_TYPE
:
349 BufferType bufferType
= BufferType
.valueOfString(rawInfo
.getTextContent());
350 domain
.setBufferType(bufferType
);
352 case MIStrings
.CHANNELS
:
353 ArrayList
<IChannelInfo
> channels
= new ArrayList
<>();
354 parseChannels(rawInfo
.getChildNodes(), channels
);
355 if (channels
.size() > 0) {
356 domain
.setChannels(channels
);
368 * Parse a list of raw channel XML node into an ArrayList of IChannelInfo
371 * List of raw channel XML node
373 * the parsed channels list
374 * @throws ExecutionException
375 * when missing required xml element (type)
377 private static void parseChannels(NodeList rawChannels
, ArrayList
<IChannelInfo
> channels
) throws ExecutionException
{
378 IChannelInfo channel
= null;
379 for (int i
= 0; i
< rawChannels
.getLength(); i
++) {
380 Node rawChannel
= rawChannels
.item(i
);
381 if (rawChannel
.getNodeName().equalsIgnoreCase(MIStrings
.CHANNEL
)) {
382 channel
= new ChannelInfo(""); //$NON-NLS-1$
384 // Populate the channel
385 NodeList rawInfos
= rawChannel
.getChildNodes();
387 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
388 rawInfo
= rawInfos
.item(j
);
389 switch (rawInfo
.getNodeName()) {
391 channel
.setName(rawInfo
.getTextContent());
393 case MIStrings
.ENABLED
:
394 channel
.setState(TraceEnablement
.valueOfString(rawInfo
.getTextContent()));
396 case MIStrings
.EVENTS
:
397 List
<IEventInfo
> events
= new ArrayList
<>();
398 getEventInfo(rawInfo
.getChildNodes(), events
);
399 channel
.setEvents(events
);
401 case MIStrings
.ATTRIBUTES
:
402 NodeList rawAttributes
= rawInfo
.getChildNodes();
403 for (int k
= 0; k
< rawAttributes
.getLength(); k
++) {
404 Node attribute
= rawAttributes
.item(k
);
405 switch (attribute
.getNodeName()) {
406 case MIStrings
.OVERWRITE_MODE
:
407 channel
.setOverwriteMode(!LTTngControlServiceConstants
.OVERWRITE_MODE_ATTRIBUTE_FALSE_MI
.equalsIgnoreCase(attribute
.getTextContent()));
409 case MIStrings
.SUBBUF_SIZE
:
410 channel
.setSubBufferSize(Long
.valueOf(attribute
.getTextContent()));
412 case MIStrings
.NUM_SUBBUF
:
413 channel
.setNumberOfSubBuffers(Integer
.valueOf(attribute
.getTextContent()));
415 case MIStrings
.SWITCH_TIMER_INTERVAL
:
416 channel
.setSwitchTimer(Long
.valueOf(attribute
.getTextContent()));
418 case MIStrings
.READ_TIMER_INTERVAL
:
419 channel
.setReadTimer(Long
.valueOf(attribute
.getTextContent()));
421 case MIStrings
.OUTPUT_TYPE
:
422 channel
.setOutputType(attribute
.getTextContent());
424 case MIStrings
.TRACEFILE_SIZE
:
425 channel
.setMaxSizeTraceFiles(Integer
.parseInt(attribute
.getTextContent()));
427 case MIStrings
.TRACEFILE_COUNT
:
428 channel
.setMaxNumberTraceFiles(Integer
.parseInt(attribute
.getTextContent()));
430 case MIStrings
.LIVE_TIMER_INTERVAL
:
431 // TODO: currently not supported by tmf
442 channels
.add(channel
);
449 public ISnapshotInfo
getSnapshotInfo(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
450 // TODO A session can have multiple snapshot output. This need to be
451 // supported in the future.
452 // Currently the SessionInfo object does not support multiple snashot
454 // For now only keep the last one.
455 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_SNAPSHOT_OUTPUT
, LTTngControlServiceConstants
.OPTION_SESSION
, sessionName
);
456 ICommandResult result
= executeCommand(command
.toString(), monitor
);
457 Document doc
= getDocumentFromStrings(result
.getOutput());
458 NodeList rawSnapshotsOutputs
= doc
.getElementsByTagName(MIStrings
.SNAPSHOT_OUTPUTS
);
460 ISnapshotInfo snapshotInfo
= new SnapshotInfo(""); //$NON-NLS-1$
462 // TODO: tmf does not have a notion of a ctrl url.
463 for (int i
= 0; i
< rawSnapshotsOutputs
.getLength(); i
++) {
464 NodeList rawSnapshotOutput
= rawSnapshotsOutputs
.item(i
).getChildNodes();
465 for (int j
= 0; j
< rawSnapshotOutput
.getLength(); j
++) {
466 Node rawInfo
= rawSnapshotOutput
.item(j
);
467 switch (rawInfo
.getNodeName()) {
469 snapshotInfo
.setId(Integer
.parseInt(rawInfo
.getTextContent()));
472 snapshotInfo
.setName(rawInfo
.getTextContent());
474 case MIStrings
.SNAPSHOT_CTRL_URL
:
475 // The use of the ctrl_url for the snapshot path is to assure
476 // basic support. Refactoring is necessary in lttng and
478 // See http://bugs.lttng.org/issues/828 (+comment)
479 snapshotInfo
.setSnapshotPath(rawInfo
.getTextContent());
487 // Check if the snapshot output is Streamed
488 Matcher matcher2
= LTTngControlServiceConstants
.TRACE_NETWORK_PATTERN
.matcher(snapshotInfo
.getSnapshotPath());
489 if (matcher2
.matches()) {
490 snapshotInfo
.setStreamedSnapshot(true);
497 public List
<IBaseEventInfo
> getKernelProvider(IProgressMonitor monitor
) throws ExecutionException
{
498 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
499 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
500 List
<IBaseEventInfo
> events
= new ArrayList
<>();
502 if (isError(result
) && result
.getErrorOutput() != null) {
503 // Ignore the following 2 cases:
504 // Spawning a session daemon
505 // Error: Unable to list kernel events
507 // Error: Unable to list kernel events
508 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN
)) {
511 throw new ExecutionException(Messages
.TraceControl_CommandError
+ LTTngControlServiceConstants
.COMMAND_LIST_KERNEL
);
514 Document document
= getDocumentFromStrings(result
.getOutput());
515 NodeList rawEvents
= document
.getElementsByTagName(MIStrings
.EVENT
);
516 getBaseEventInfo(rawEvents
, events
);
521 public List
<IUstProviderInfo
> getUstProvider(IProgressMonitor monitor
) throws ExecutionException
{
522 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_LIST_UST
);
524 command
.append(LTTngControlServiceConstants
.OPTION_FIELDS
);
527 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
528 List
<IUstProviderInfo
> allProviders
= new ArrayList
<>();
530 if (isError(result
) && result
.getErrorOutput() != null) {
531 // Ignore the following 2 cases:
532 // Spawning a session daemon
533 // Error: Unable to list UST events: Listing UST events failed
535 // Error: Unable to list UST events: Listing UST events failed
536 if (ignoredPattern(result
.getErrorOutput(), LTTngControlServiceConstants
.LIST_UST_NO_UST_PROVIDER_PATTERN
)) {
539 throw new ExecutionException(Messages
.TraceControl_CommandError
+ LTTngControlServiceConstants
.COMMAND_LIST_UST
);
542 Document document
= getDocumentFromStrings(result
.getOutput());
543 NodeList rawProviders
= document
.getElementsByTagName(MIStrings
.PID
);
545 IUstProviderInfo providerInfo
= null;
547 for (int i
= 0; i
< rawProviders
.getLength(); i
++) {
548 Node provider
= rawProviders
.item(i
);
549 Node name
= getFirstOf(provider
.getChildNodes(), MIStrings
.NAME
);
551 throw new ExecutionException(Messages
.TraceControl_MiInvalidProviderError
);
553 providerInfo
= new UstProviderInfo(name
.getTextContent());
556 NodeList infos
= provider
.getChildNodes();
557 for (int j
= 0; j
< infos
.getLength(); j
++) {
558 Node info
= infos
.item(j
);
559 switch (info
.getNodeName()) {
560 case MIStrings
.PID_ID
:
561 providerInfo
.setPid(Integer
.parseInt(info
.getTextContent()));
563 case MIStrings
.EVENTS
:
564 List
<IBaseEventInfo
> events
= new ArrayList
<>();
565 NodeList rawEvents
= info
.getChildNodes();
566 getBaseEventInfo(rawEvents
, events
);
567 providerInfo
.setEvents(events
);
573 allProviders
.add(providerInfo
);
580 public ISessionInfo
createSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
581 if (sessionInfo
.isStreamedTrace()) {
582 return createStreamedSession(sessionInfo
, monitor
);
585 StringBuffer command
= prepareSessionCreationCommand(sessionInfo
);
587 ICommandResult result
= executeCommand(command
.toString(), monitor
);
589 Document document
= getDocumentFromStrings(result
.getOutput());
590 NodeList sessions
= document
.getElementsByTagName(MIStrings
.SESSION
);
592 // Number of session should be equal to 1
593 if (sessions
.getLength() != 1) {
594 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" //$NON-NLS-1$//$NON-NLS-2$
595 + NLS
.bind(Messages
.TraceControl_UnexpectedNumberOfElementError
, MIStrings
.SESSION
) + " " + sessions
.getLength()); //$NON-NLS-1$
598 // Fetch a session from output
599 ISessionInfo outputSession
= new SessionInfo(""); //$NON-NLS-1$
600 parseSession(outputSession
, sessions
.item(0));
602 // Verify session name
603 if ((outputSession
.getName().equals("")) || (!"".equals(sessionInfo
.getName()) && !outputSession
.getName().equals(sessionInfo
.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
604 // Unexpected name returned
605 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
606 Messages
.TraceControl_UnexpectedNameError
+ ": " + outputSession
.getName()); //$NON-NLS-1$
609 // Verify session path
610 if (!sessionInfo
.isSnapshotSession() &&
611 ((outputSession
.getSessionPath() == null) || ((sessionInfo
.getSessionPath() != null) && (!outputSession
.getSessionPath().contains(sessionInfo
.getSessionPath()))))) {
613 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
614 Messages
.TraceControl_UnexpectedPathError
+ ": " + outputSession
.getName()); //$NON-NLS-1$
617 if (sessionInfo
.isSnapshotSession()) {
618 // Make it a snapshot session - content of snapshot info need to
619 // set afterwards using getSession() or getSnapshotInfo()
620 outputSession
.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
623 return outputSession
;
626 private ISessionInfo
createStreamedSession(ISessionInfo sessionInfo
, IProgressMonitor monitor
) throws ExecutionException
{
628 StringBuffer command
= prepareStreamedSessionCreationCommand(sessionInfo
);
630 ICommandResult result
= executeCommand(command
.toString(), monitor
);
632 Document document
= getDocumentFromStrings(result
.getOutput());
633 NodeList sessions
= document
.getElementsByTagName(MIStrings
.SESSION
);
635 // Number of session should be equal to 1
636 if (sessions
.getLength() != 1) {
637 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" //$NON-NLS-1$//$NON-NLS-2$
638 + NLS
.bind(Messages
.TraceControl_UnexpectedNumberOfElementError
, MIStrings
.SESSION
) + " " + sessions
.getLength()); //$NON-NLS-1$
641 // Fetch a session from output
642 ISessionInfo outputSession
= new SessionInfo(""); //$NON-NLS-1$
643 parseSession(outputSession
, sessions
.item(0));
645 // Verify session name
646 if ((outputSession
.getName().equals("")) || (!"".equals(sessionInfo
.getName()) && !outputSession
.getName().equals(sessionInfo
.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
647 // Unexpected name returned
648 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
649 Messages
.TraceControl_UnexpectedNameError
+ ": " + outputSession
.getName()); //$NON-NLS-1$
652 sessionInfo
.setName(outputSession
.getName());
653 sessionInfo
.setStreamedTrace(true);
655 // Verify session path
656 if (sessionInfo
.getNetworkUrl() != null) {
657 if (!sessionInfo
.isSnapshotSession() && (outputSession
.getSessionPath() == null)) {
659 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
+ "\n" + //$NON-NLS-1$ //$NON-NLS-2$
660 Messages
.TraceControl_UnexpectedPathError
+ ": " + outputSession
.getName()); //$NON-NLS-1$
663 if (sessionInfo
.isSnapshotSession()) {
664 sessionInfo
.setStreamedTrace(false);
666 sessionInfo
.setSessionPath(outputSession
.getSessionPath());
667 // Check file protocol
668 Matcher matcher
= LTTngControlServiceConstants
.TRACE_FILE_PROTOCOL_PATTERN
.matcher(outputSession
.getSessionPath());
669 if (matcher
.matches()) {
670 sessionInfo
.setStreamedTrace(false);
675 // When using controlUrl and dataUrl the full session path is not known
677 // and will be set later on when listing the session
683 public void destroySession(String sessionName
, IProgressMonitor monitor
) throws ExecutionException
{
684 String newName
= formatParameter(sessionName
);
686 StringBuffer command
= createCommand(LTTngControlServiceConstants
.COMMAND_DESTROY_SESSION
, newName
);
688 ICommandResult result
= executeCommand(command
.toString(), monitor
, false);
689 String
[] errorOutput
= result
.getErrorOutput();
691 if (isError(result
) && (errorOutput
!= null)) {
692 // Don't treat this as an error
693 if (ignoredPattern(errorOutput
, LTTngControlServiceConstants
.SESSION_NOT_FOUND_ERROR_PATTERN
)) {
697 throw new ExecutionException(Messages
.TraceControl_CommandError
+ " " + command
.toString() + "\n" + formatOutput(result
)); //$NON-NLS-1$ //$NON-NLS-2$
700 // Check for action effect
701 Document doc
= getDocumentFromStrings(result
.getOutput());
702 NodeList sessions
= doc
.getElementsByTagName(MIStrings
.SESSION
);
703 if (sessions
.getLength() != 1) {
704 throw new ExecutionException(NLS
.bind(Messages
.TraceControl_MiInvalidNumberOfElementError
, MIStrings
.SESSION
));
707 Node rawSessionName
= getFirstOf(sessions
.item(0).getChildNodes(), MIStrings
.NAME
);
708 if (rawSessionName
== null) {
709 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
713 if (!rawSessionName
.getTextContent().equals(sessionName
)) {
714 throw new ExecutionException(NLS
.bind(Messages
.TraceControl_UnexpectedValueError
, rawSessionName
.getTextContent(), sessionName
));
720 * array of string that make up a command line
721 * @return string buffer with created command line
724 protected StringBuffer
createCommand(String
... strings
) {
725 StringBuffer command
= new StringBuffer();
726 command
.append(LTTngControlServiceConstants
.CONTROL_COMMAND_MI_XML
);
727 command
.append(getTracingGroupOption());
728 for (String string
: strings
) {
729 command
.append(string
);
735 * @param xmlBaseEvents
736 * a Node list of base xml event element
738 * list of event generated by the parsing of the xml event
740 * @throws ExecutionException
741 * when a raw event is not a complete/valid xml event
743 private static void getBaseEventInfo(NodeList xmlBaseEvents
, List
<IBaseEventInfo
> events
) throws ExecutionException
{
744 IBaseEventInfo eventInfo
= null;
745 for (int i
= 0; i
< xmlBaseEvents
.getLength(); i
++) {
746 NodeList rawInfos
= xmlBaseEvents
.item(i
).getChildNodes();
748 if (xmlBaseEvents
.item(i
).getNodeName().equalsIgnoreCase(MIStrings
.EVENT
)) {
749 Node rawName
= getFirstOf(rawInfos
, MIStrings
.NAME
);
750 if (rawName
== null) {
751 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
753 eventInfo
= new BaseEventInfo(rawName
.getTextContent());
755 // Populate the event
756 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
757 Node infoNode
= rawInfos
.item(j
);
758 switch (infoNode
.getNodeName()) {
760 eventInfo
.setEventType(infoNode
.getTextContent());
762 case MIStrings
.LOGLEVEL
:
763 eventInfo
.setLogLevel(infoNode
.getTextContent());
765 case MIStrings
.EVENT_FIELDS
:
766 List
<IFieldInfo
> fields
= new ArrayList
<>();
767 getFieldInfo(infoNode
.getChildNodes(), fields
);
768 eventInfo
.setFields(fields
);
774 events
.add(eventInfo
);
780 * @param xmlBaseEvents
781 * a Node list of xml event element linked to a session
783 * list of event generated by the parsing of the xml event
785 * @throws ExecutionException
786 * when a raw event is not a complete/valid xml event
788 static void getEventInfo(NodeList xmlEvents
, List
<IEventInfo
> events
) throws ExecutionException
{
789 IEventInfo eventInfo
= null;
790 for (int i
= 0; i
< xmlEvents
.getLength(); i
++) {
791 NodeList rawInfos
= xmlEvents
.item(i
).getChildNodes();
793 if (xmlEvents
.item(i
).getNodeName().equalsIgnoreCase(MIStrings
.EVENT
)) {
794 Node rawName
= getFirstOf(rawInfos
, MIStrings
.NAME
);
795 if (rawName
== null) {
796 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
799 eventInfo
= new EventInfo(rawName
.getTextContent());
802 for (int j
= 0; j
< rawInfos
.getLength(); j
++) {
803 Node infoNode
= rawInfos
.item(j
);
804 switch (infoNode
.getNodeName()) {
806 eventInfo
.setEventType(infoNode
.getTextContent());
808 case MIStrings
.LOGLEVEL_TYPE
:
809 eventInfo
.setLogLevelType(LogLevelType
.valueOfString(infoNode
.getTextContent()));
811 case MIStrings
.LOGLEVEL
:
812 eventInfo
.setLogLevel(TraceLogLevel
.valueOfString(infoNode
.getTextContent()));
814 case MIStrings
.ENABLED
:
815 eventInfo
.setState(TraceEnablement
.valueOfString(infoNode
.getTextContent()));
817 case MIStrings
.FILTER
:
819 // See bug 334 http://bugs.lttng.org/issues/334 from
821 // For now we emulate the non-mi behavior and simply put
823 eventInfo
.setFilterExpression("with filter"); //$NON-NLS-1$
825 case MIStrings
.EXCLUSION
:
826 // TODO: Currently not supported by tmf
827 // ExclusionS element is ignored
834 boolean isProbeFunction
= (eventInfo
.getEventType().equals(TraceEventType
.PROBE
)) || (eventInfo
.getEventType().equals(TraceEventType
.FUNCTION
));
835 if (isProbeFunction
) {
836 IProbeEventInfo probeEvent
= new ProbeEventInfo(eventInfo
);
837 eventInfo
= probeEvent
;
839 Node rawAttributes
= getFirstOf(rawInfos
, MIStrings
.ATTRIBUTES
);
840 if (rawAttributes
== null) {
841 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
844 Node rawDataNode
= null;
845 switch (probeEvent
.getEventType()) {
847 rawDataNode
= getFirstOf(rawAttributes
.getChildNodes(), MIStrings
.PROBE_ATTRIBUTES
);
850 rawDataNode
= getFirstOf(rawAttributes
.getChildNodes(), MIStrings
.FUNCTION_ATTRIBUTES
);
856 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
859 if (rawDataNode
== null) {
860 throw new ExecutionException(Messages
.TraceControl_MiInvalidElementError
);
864 NodeList rawDatas
= rawDataNode
.getChildNodes();
865 for (int j
= 0; j
< rawDatas
.getLength(); j
++) {
866 Node rawData
= rawDatas
.item(j
);
867 switch (rawData
.getNodeName()) {
868 case MIStrings
.SYMBOL_NAME
:
869 probeEvent
.setSymbol(rawData
.getTextContent());
871 case MIStrings
.ADDRESS
:
872 probeEvent
.setAddress(rawData
.getTextContent());
874 case MIStrings
.OFFSET
:
875 probeEvent
.setOffset(rawData
.getTextContent());
883 // Syscalls does not have name.
884 // Let put one to make sure this is user friendly via UI
885 if (eventInfo
.getEventType().equals(TraceEventType
.SYSCALL
)) {
886 eventInfo
.setName(TraceEventType
.SYSCALL
.getInName());
890 events
.add(eventInfo
);
897 * a list of xml event_field element
899 * a list of field generated by xml parsing
900 * @throws ExecutionException
901 * when parsing fail or required elements are missing
903 private static void getFieldInfo(NodeList fieldsList
, List
<IFieldInfo
> fields
) throws ExecutionException
{
904 IFieldInfo fieldInfo
= null;
905 for (int i
= 0; i
< fieldsList
.getLength(); i
++) {
906 Node field
= fieldsList
.item(i
);
907 if (field
.getNodeName().equalsIgnoreCase(MIStrings
.EVENT_FIELD
)) {
909 Node name
= getFirstOf(field
.getChildNodes(), MIStrings
.NAME
);
911 throw new ExecutionException(Messages
.TraceControl_MiMissingRequiredError
);
913 fieldInfo
= new FieldInfo(name
.getTextContent());
915 // Populate the field information
916 NodeList infos
= field
.getChildNodes();
917 for (int j
= 0; j
< infos
.getLength(); j
++) {
918 Node info
= infos
.item(j
);
919 switch (info
.getNodeName()) {
921 fieldInfo
.setFieldType(info
.getTextContent());
927 fields
.add(fieldInfo
);
933 * Retrieve the fist instance of a given node with tag name equal to tagName
937 * the list of Node to search against
939 * the tag name of the desired node
940 * @return the first occurrence of a node with a tag name equals to tagName
942 private static Node
getFirstOf(NodeList nodeList
, String tagName
) {
944 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
945 if (nodeList
.item(i
).getNodeName() == tagName
) {
946 node
= nodeList
.item(i
);