lttng.control: Disable Java and Python logging for older LTTng versions
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / service / LTTngControlServiceMI.java
1 /**********************************************************************
2 * Copyright (c) 2014, 2015 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 * Bernd Hufmann - Fix check for live session
12 **********************************************************************/
13
14 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.service;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18 import java.io.IOException;
19 import java.io.StringReader;
20 import java.math.BigInteger;
21 import java.net.URL;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.regex.Matcher;
26
27 import javax.xml.XMLConstants;
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.validation.SchemaFactory;
32
33 import org.eclipse.core.commands.ExecutionException;
34 import org.eclipse.core.runtime.IProgressMonitor;
35 import org.eclipse.core.runtime.Platform;
36 import org.eclipse.jdt.annotation.NonNull;
37 import org.eclipse.jdt.annotation.Nullable;
38 import org.eclipse.osgi.util.NLS;
39 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IBaseEventInfo;
40 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo;
41 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IDomainInfo;
42 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IEventInfo;
43 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IFieldInfo;
44 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ILoggerInfo;
45 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IProbeEventInfo;
46 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISessionInfo;
47 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISnapshotInfo;
48 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IUstProviderInfo;
49 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
50 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
51 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement;
52 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType;
53 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceJulLogLevel;
54 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLog4jLogLevel;
55 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
56 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TracePythonLogLevel;
57 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.BaseEventInfo;
58 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.BufferType;
59 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ChannelInfo;
60 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.DomainInfo;
61 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.EventInfo;
62 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.FieldInfo;
63 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.LoggerInfo;
64 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ProbeEventInfo;
65 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SessionInfo;
66 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SnapshotInfo;
67 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.UstProviderInfo;
68 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
69 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers.XmlMiValidationErrorHandler;
70 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
71 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
72 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
73 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
74 import org.w3c.dom.Document;
75 import org.w3c.dom.Node;
76 import org.w3c.dom.NodeList;
77 import org.xml.sax.InputSource;
78 import org.xml.sax.SAXException;
79
80 /**
81 * Service for sending LTTng trace control commands to remote host via machine
82 * interface mode.
83 *
84 * @author Jonathan Rajotte
85 */
86 public class LTTngControlServiceMI extends LTTngControlService {
87
88 /**
89 * The tracing key (.options) and System property to control whether or not schema validation should be used.
90 */
91 public static final String MI_SCHEMA_VALIDATION_KEY = Activator.PLUGIN_ID + "/mi/schema-validation"; //$NON-NLS-1$
92
93 // ------------------------------------------------------------------------
94 // Attributes
95 // ------------------------------------------------------------------------
96
97 private final DocumentBuilder fDocumentBuilder;
98
99 // ------------------------------------------------------------------------
100 // Constructors
101 // ------------------------------------------------------------------------
102
103 /**
104 * Constructor
105 *
106 * @param shell
107 * the command shell implementation to use
108 * @param version
109 * the lttng version
110 * @throws ExecutionException
111 * if the creation of the Schema and DocumentBuilder objects
112 * fails
113 */
114 public LTTngControlServiceMI(@NonNull ICommandShell shell, @Nullable LttngVersion version) throws ExecutionException {
115 super(shell);
116 setVersion(version);
117
118 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
119 docBuilderFactory.setValidating(false);
120
121 if (isSchemaValidationEnabled()) {
122 if (version != null) {
123 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
124 try {
125 URL xsdUrl = LTTngControlService.class.getResource(LTTngControlServiceConstants.MI_XSD_FILENAME);
126 if (version.compareTo(new LttngVersion(2, 8, 0, null, null, null, null, null, null)) >= 0) {
127 xsdUrl = LTTngControlService.class.getResource(LTTngControlServiceConstants.MI3_XSD_FILENAME);
128 // MI 3.0 added name spaces. It will fail to validate if this is not set to true.
129 docBuilderFactory.setNamespaceAware(true);
130 }
131 docBuilderFactory.setSchema(schemaFactory.newSchema(xsdUrl));
132 } catch (SAXException e) {
133 throw new ExecutionException(Messages.TraceControl_InvalidSchemaError, e);
134 }
135 }
136 }
137
138 try {
139 fDocumentBuilder = docBuilderFactory.newDocumentBuilder();
140 } catch (ParserConfigurationException e) {
141 throw new ExecutionException(Messages.TraceControl_XmlDocumentBuilderError, e);
142 }
143
144 fDocumentBuilder.setErrorHandler(new XmlMiValidationErrorHandler());
145
146 }
147
148 private static boolean isSchemaValidationEnabled() {
149 String schemaValidationKey = Platform.getDebugOption(MI_SCHEMA_VALIDATION_KEY);
150 String systemProperty = System.getProperty(MI_SCHEMA_VALIDATION_KEY);
151 return schemaValidationKey != null && Boolean.parseBoolean(schemaValidationKey) || systemProperty != null && Boolean.parseBoolean(systemProperty);
152 }
153
154 /**
155 * Generate a Document object from an list of Strings.
156 *
157 * @param xmlStrings
158 * list of strings representing an xml input
159 * @param documentBuilder
160 * the builder used to get the document
161 * @return Document generated from strings input
162 * @throws ExecutionException
163 * when parsing has failed
164 */
165 private static Document getDocumentFromStrings(List<String> xmlStrings, DocumentBuilder documentBuilder) throws ExecutionException {
166 StringBuilder concatenedString = new StringBuilder();
167 for (String string : xmlStrings) {
168 concatenedString.append(string);
169 }
170 InputSource stream = new InputSource(new StringReader(concatenedString.toString()));
171
172 Document document;
173 try {
174 document = documentBuilder.parse(stream);
175 } catch (SAXException | IOException e) {
176 throw new ExecutionException(Messages.TraceControl_XmlParsingError + ':' + e.toString(), e);
177 }
178 return document;
179
180 }
181
182 /**
183 * Parse LTTng version from a MI command result
184 *
185 * @param commandResult
186 * the result obtained from a MI command
187 * @return the LTTng version
188 * @throws ExecutionException
189 * when xml extraction fail
190 */
191 public static LttngVersion parseVersion(ICommandResult commandResult) throws ExecutionException {
192 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
193 DocumentBuilder documentBuilder;
194 try {
195 documentBuilder = docBuilderFactory.newDocumentBuilder();
196 } catch (ParserConfigurationException e) {
197 throw new ExecutionException(Messages.TraceControl_XmlDocumentBuilderError, e);
198 }
199
200 Document doc = getDocumentFromStrings(commandResult.getOutput(), documentBuilder);
201 NodeList element = doc.getElementsByTagName(MIStrings.VERSION);
202 if (element.getLength() != 1) {
203 throw new ExecutionException(Messages.TraceControl_UnsupportedVersionError);
204 }
205
206 int major = 0;
207 int minor = 0;
208 int patchLevel = 0;
209 String license = ""; //$NON-NLS-1$
210 String commit = ""; //$NON-NLS-1$
211 String name = ""; //$NON-NLS-1$
212 String description = ""; //$NON-NLS-1$
213 String url = ""; //$NON-NLS-1$
214 String fullVersion = ""; //$NON-NLS-1$
215 NodeList child = element.item(0).getChildNodes();
216 // Get basic information
217 for (int i = 0; i < child.getLength(); i++) {
218 Node node = child.item(i);
219 switch (node.getNodeName()) {
220 case MIStrings.VERSION_MAJOR:
221 major = Integer.parseInt(node.getTextContent());
222 break;
223 case MIStrings.VERSION_MINOR:
224 minor = Integer.parseInt(node.getTextContent());
225 break;
226 case MIStrings.VERSION_PATCH_LEVEL:
227 patchLevel = Integer.parseInt(node.getTextContent());
228 break;
229 case MIStrings.VERSION_COMMIT:
230 commit = node.getTextContent();
231 break;
232 case MIStrings.VERSION_DESCRIPTION:
233 description = node.getTextContent();
234 break;
235 case MIStrings.VERSION_LICENSE:
236 license = node.getTextContent();
237 break;
238 case MIStrings.VERSION_NAME:
239 name = node.getTextContent();
240 break;
241 case MIStrings.VERSION_STR:
242 fullVersion = node.getTextContent();
243 break;
244 case MIStrings.VERSION_WEB:
245 url = node.getTextContent();
246 break;
247 default:
248 break;
249 }
250 }
251 return new LttngVersion(major, minor, patchLevel, license, commit, name, description, url, fullVersion);
252 }
253
254 @Override
255 public List<String> getSessionNames(IProgressMonitor monitor) throws ExecutionException {
256 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
257 ICommandResult result = executeCommand(command, monitor);
258
259 Document doc = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
260
261 NodeList elements = doc.getElementsByTagName(MIStrings.NAME);
262
263 ArrayList<String> retArray = new ArrayList<>();
264 for (int i = 0; i < elements.getLength(); i++) {
265 Node node = elements.item(i);
266 if (node.getParentNode().getNodeName().equalsIgnoreCase(MIStrings.SESSION)) {
267 retArray.add(node.getTextContent());
268 }
269 }
270 return retArray;
271 }
272
273 @Override
274 public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
275 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
276 ICommandResult result = executeCommand(command, monitor);
277
278 ISessionInfo sessionInfo = new SessionInfo(sessionName);
279 Document document = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
280
281 NodeList sessionsNode = document.getElementsByTagName(MIStrings.SESSION);
282 // There should be only one session
283 if (sessionsNode.getLength() != 1) {
284 throw new ExecutionException(NLS.bind(Messages.TraceControl_MiInvalidNumberOfElementError, MIStrings.SESSION));
285 }
286
287 // Populate session information
288 Node rawSession = sessionsNode.item(0);
289 parseSession(sessionInfo, rawSession);
290
291 // Fetch the snapshot info
292 if (sessionInfo.isSnapshotSession()) {
293 ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor);
294 sessionInfo.setSnapshotInfo(snapshot);
295 }
296
297 return sessionInfo;
298 }
299
300 /**
301 * @param sessionInfo
302 * @param rawSession
303 * @throws ExecutionException
304 */
305 private void parseSession(ISessionInfo sessionInfo, Node rawSession) throws ExecutionException {
306 if (!rawSession.getNodeName().equalsIgnoreCase(MIStrings.SESSION)) {
307 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
308 }
309 NodeList rawSessionInfos = rawSession.getChildNodes();
310 for (int i = 0; i < rawSessionInfos.getLength(); i++) {
311 Node rawInfo = rawSessionInfos.item(i);
312 switch (rawInfo.getNodeName()) {
313 case MIStrings.NAME:
314 sessionInfo.setName(rawInfo.getTextContent());
315 break;
316 case MIStrings.PATH:
317 sessionInfo.setSessionPath(rawInfo.getTextContent());
318 break;
319 case MIStrings.ENABLED:
320 sessionInfo.setSessionState(rawInfo.getTextContent());
321 break;
322 case MIStrings.SNAPSHOT_MODE:
323 if (rawInfo.getTextContent().equals(LTTngControlServiceConstants.TRUE_NUMERICAL)) {
324 // real name will be set later
325 ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$
326 sessionInfo.setSnapshotInfo(snapshotInfo);
327 }
328 break;
329 case MIStrings.LIVE_TIMER_INTERVAL:
330 long liveDelay = Long.parseLong(rawInfo.getTextContent());
331 if ((liveDelay > 0 && (liveDelay <= LTTngControlServiceConstants.MAX_LIVE_TIMER_INTERVAL))) {
332 sessionInfo.setLive(true);
333 sessionInfo.setLiveUrl(SessionInfo.DEFAULT_LIVE_NETWORK_URL);
334 sessionInfo.setLivePort(SessionInfo.DEFAULT_LIVE_PORT);
335 sessionInfo.setLiveDelay(liveDelay);
336 }
337 break;
338 case MIStrings.DOMAINS:
339 // Extract the domains node
340 NodeList rawDomains = rawInfo.getChildNodes();
341 IDomainInfo domain = null;
342 for (int j = 0; j < rawDomains.getLength(); j++) {
343 if (rawDomains.item(j).getNodeName().equalsIgnoreCase(MIStrings.DOMAIN)) {
344 domain = parseDomain(rawDomains.item(j));
345 sessionInfo.addDomain(domain);
346 }
347 }
348 break;
349 default:
350 break;
351 }
352 }
353
354 if (!sessionInfo.isSnapshotSession()) {
355 Matcher matcher = LTTngControlServiceConstants.TRACE_NETWORK_PATTERN.matcher(sessionInfo.getSessionPath());
356 if (matcher.matches()) {
357 sessionInfo.setStreamedTrace(true);
358 }
359 }
360 }
361
362 /**
363 * Parse a raw domain XML node to a IDomainInfo object
364 *
365 * @param rawDomain
366 * a domain xml node
367 * @return a populated {@link DomainInfo} object
368 * @throws ExecutionException
369 * when missing required xml element (type)
370 */
371 protected IDomainInfo parseDomain(Node rawDomain) throws ExecutionException {
372 IDomainInfo domain = null;
373 // Get the type
374 Node rawType = getFirstOf(rawDomain.getChildNodes(), MIStrings.TYPE);
375 if (rawType == null) {
376 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
377 }
378 String rawTypeString = rawType.getTextContent().toLowerCase();
379 TraceDomainType domainType = TraceDomainType.valueOfString(rawTypeString);
380 switch (domainType) {
381 case KERNEL:
382 domain = new DomainInfo(Messages.TraceControl_KernelProviderDisplayName);
383 domain.setDomain(TraceDomainType.KERNEL);
384 break;
385 case UST:
386 domain = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
387 domain.setDomain(TraceDomainType.UST);
388 break;
389 case JUL:
390 domain = new DomainInfo(Messages.TraceControl_JULDomainDisplayName);
391 domain.setDomain(TraceDomainType.JUL);
392 break;
393 case LOG4J:
394 domain = new DomainInfo(Messages.TraceControl_LOG4JDomainDisplayName);
395 domain.setDomain(TraceDomainType.LOG4J);
396 break;
397 case PYTHON:
398 domain = new DomainInfo(Messages.TraceControl_PythonDomainDisplayName);
399 domain.setDomain(TraceDomainType.PYTHON);
400 break;
401 case UNKNOWN:
402 domain = new DomainInfo(Messages.TraceControl_UnknownDomainDisplayName);
403 domain.setDomain(TraceDomainType.UNKNOWN);
404 break;
405 //$CASES-OMITTED$
406 default:
407 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
408 }
409
410 NodeList rawInfos = rawDomain.getChildNodes();
411 for (int i = 0; i < rawInfos.getLength(); i++) {
412 Node rawInfo = rawInfos.item(i);
413 switch (rawInfo.getNodeName()) {
414 case MIStrings.BUFFER_TYPE:
415 BufferType bufferType = BufferType.valueOfString(rawInfo.getTextContent());
416 domain.setBufferType(bufferType);
417 break;
418 case MIStrings.CHANNELS:
419 ArrayList<IChannelInfo> channels = new ArrayList<>();
420 parseChannels(rawInfo.getChildNodes(), channels);
421 if (channels.size() > 0) {
422 domain.setChannels(channels);
423 }
424 break;
425 case MIStrings.EVENTS:
426 ArrayList<ILoggerInfo> loggers = new ArrayList<>();
427 getLoggerInfo(rawInfo.getChildNodes(), loggers, domain.getDomain());
428 domain.setLoggers(loggers);
429 break;
430 default:
431 break;
432 }
433 }
434
435 return domain;
436 }
437
438 /**
439 * Parse a list of raw channel XML node into an ArrayList of IChannelInfo
440 *
441 * @param rawChannes
442 * List of raw channel XML node
443 * @param channels
444 * the parsed channels list
445 * @throws ExecutionException
446 * when missing required xml element (type)
447 */
448 private static void parseChannels(NodeList rawChannels, ArrayList<IChannelInfo> channels) throws ExecutionException {
449 IChannelInfo channel = null;
450 for (int i = 0; i < rawChannels.getLength(); i++) {
451 Node rawChannel = rawChannels.item(i);
452 if (rawChannel.getNodeName().equalsIgnoreCase(MIStrings.CHANNEL)) {
453 channel = new ChannelInfo(""); //$NON-NLS-1$
454
455 // Populate the channel
456 NodeList rawInfos = rawChannel.getChildNodes();
457 Node rawInfo = null;
458 for (int j = 0; j < rawInfos.getLength(); j++) {
459 rawInfo = rawInfos.item(j);
460 switch (rawInfo.getNodeName()) {
461 case MIStrings.NAME:
462 channel.setName(rawInfo.getTextContent());
463 break;
464 case MIStrings.ENABLED:
465 channel.setState(TraceEnablement.valueOfString(rawInfo.getTextContent()));
466 break;
467 case MIStrings.EVENTS:
468 List<IEventInfo> events = new ArrayList<>();
469 getEventInfo(rawInfo.getChildNodes(), events);
470 channel.setEvents(events);
471 break;
472 case MIStrings.ATTRIBUTES:
473 NodeList rawAttributes = rawInfo.getChildNodes();
474 for (int k = 0; k < rawAttributes.getLength(); k++) {
475 Node attribute = rawAttributes.item(k);
476 switch (attribute.getNodeName()) {
477 case MIStrings.OVERWRITE_MODE:
478 channel.setOverwriteMode(!LTTngControlServiceConstants.OVERWRITE_MODE_ATTRIBUTE_FALSE_MI.equalsIgnoreCase(attribute.getTextContent()));
479 break;
480 case MIStrings.SUBBUF_SIZE:
481 channel.setSubBufferSize(Long.valueOf(attribute.getTextContent()));
482 break;
483 case MIStrings.NUM_SUBBUF:
484 channel.setNumberOfSubBuffers(Integer.valueOf(attribute.getTextContent()));
485 break;
486 case MIStrings.SWITCH_TIMER_INTERVAL:
487 channel.setSwitchTimer(Long.valueOf(attribute.getTextContent()));
488 break;
489 case MIStrings.READ_TIMER_INTERVAL:
490 channel.setReadTimer(Long.valueOf(attribute.getTextContent()));
491 break;
492 case MIStrings.OUTPUT_TYPE:
493 channel.setOutputType(attribute.getTextContent());
494 break;
495 case MIStrings.TRACEFILE_SIZE:
496 channel.setMaxSizeTraceFiles(Long.parseLong(attribute.getTextContent()));
497 break;
498 case MIStrings.TRACEFILE_COUNT:
499 channel.setMaxNumberTraceFiles(Integer.parseInt(attribute.getTextContent()));
500 break;
501 case MIStrings.LIVE_TIMER_INTERVAL:
502 // TODO: currently not supported by tmf
503 break;
504 case MIStrings.DISCARDED_EVENTS:
505 channel.setNumberOfDiscardedEvents(Long.parseLong(attribute.getTextContent()));
506 break;
507 case MIStrings.LOST_PACKETS:
508 channel.setNumberOfLostPackets(Long.parseLong(attribute.getTextContent()));
509 break;
510 default:
511 break;
512 }
513 }
514 break;
515 default:
516 break;
517 }
518 }
519 channels.add(channel);
520 }
521 }
522
523 }
524
525 @Override
526 public ISnapshotInfo getSnapshotInfo(String sessionName, IProgressMonitor monitor) throws ExecutionException {
527 // TODO A session can have multiple snapshot output. This need to be
528 // supported in the future.
529 // Currently the SessionInfo object does not support multiple snashot
530 // output.
531 // For now only keep the last one.
532 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_SNAPSHOT, LTTngControlServiceConstants.COMMAND_LIST_SNAPSHOT_OUTPUT, LTTngControlServiceConstants.OPTION_SESSION, sessionName);
533 ICommandResult result = executeCommand(command, monitor);
534 Document doc = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
535 NodeList rawSnapshotsOutputs = doc.getElementsByTagName(MIStrings.SNAPSHOT_OUTPUTS);
536
537 ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$
538
539 // TODO: tmf does not have a notion of a ctrl url.
540 for (int i = 0; i < rawSnapshotsOutputs.getLength(); i++) {
541 NodeList rawSnapshotOutput = rawSnapshotsOutputs.item(i).getChildNodes();
542 for (int j = 0; j < rawSnapshotOutput.getLength(); j++) {
543 Node rawInfo = rawSnapshotOutput.item(j);
544 switch (rawInfo.getNodeName()) {
545 case MIStrings.ID:
546 snapshotInfo.setId(Integer.parseInt(rawInfo.getTextContent()));
547 break;
548 case MIStrings.NAME:
549 snapshotInfo.setName(rawInfo.getTextContent());
550 break;
551 case MIStrings.SNAPSHOT_CTRL_URL:
552 // The use of the ctrl_url for the snapshot path is to assure
553 // basic support. Refactoring is necessary in lttng and
554 // tmf side.
555 // See http://bugs.lttng.org/issues/828 (+comment)
556 snapshotInfo.setSnapshotPath(rawInfo.getTextContent());
557 break;
558 default:
559 break;
560 }
561 }
562 }
563
564 // Check if the snapshot output is Streamed
565 Matcher matcher2 = LTTngControlServiceConstants.TRACE_NETWORK_PATTERN.matcher(snapshotInfo.getSnapshotPath());
566 if (matcher2.matches()) {
567 snapshotInfo.setStreamedSnapshot(true);
568 }
569
570 return snapshotInfo;
571 }
572
573 @Override
574 public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
575 // Tracepoint events
576 ICommandInput tracepointCommand = createCommand(LTTngControlServiceConstants.COMMAND_LIST, LTTngControlServiceConstants.OPTION_KERNEL);
577 ICommandResult tracepointResult = executeCommand(tracepointCommand, monitor, false);
578 List<IBaseEventInfo> events = new ArrayList<>();
579
580 if (isError(tracepointResult)) {
581 // Ignore the following 2 cases:
582 // Spawning a session daemon
583 // Error: Unable to list kernel events
584 // or:
585 // Error: Unable to list kernel events
586 if (ignoredPattern(tracepointResult.getErrorOutput(), LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN)) {
587 return events;
588 }
589 throw new ExecutionException(Messages.TraceControl_CommandError + tracepointCommand.toString());
590 }
591
592 Document tracepointDocument = getDocumentFromStrings(tracepointResult.getOutput(), fDocumentBuilder);
593 NodeList rawTracepointEvents = tracepointDocument.getElementsByTagName(MIStrings.EVENT);
594 getBaseEventInfo(rawTracepointEvents, events);
595
596 // Syscall events
597 ICommandInput syscallCommand = createCommand(LTTngControlServiceConstants.COMMAND_LIST, LTTngControlServiceConstants.OPTION_KERNEL, LTTngControlServiceConstants.OPTION_SYSCALL);
598 ICommandResult syscallResult = executeCommand(syscallCommand, monitor, false);
599 List<IBaseEventInfo> syscallEvents = new ArrayList<>();
600
601 if (isError(syscallResult)) {
602 throw new ExecutionException(Messages.TraceControl_CommandError + syscallCommand.toString());
603 }
604
605 Document syscallDocument = getDocumentFromStrings(syscallResult.getOutput(), fDocumentBuilder);
606 NodeList rawSyscallEvents = syscallDocument.getElementsByTagName(MIStrings.EVENT);
607 getBaseEventInfo(rawSyscallEvents, syscallEvents);
608
609 // Merge the tracepoint events with the syscall events (all under the Kernel provider)
610 events.addAll(syscallEvents);
611 return events;
612 }
613
614 @Override
615 public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
616 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, LTTngControlServiceConstants.OPTION_UST);
617 // Get the field too
618 command.add(LTTngControlServiceConstants.OPTION_FIELDS);
619 // Execute UST listing
620 ICommandResult result = executeCommand(command, monitor, false);
621 List<IUstProviderInfo> allProviders = new ArrayList<>();
622
623 if (isError(result)) {
624 // Ignore the following 2 cases:
625 // Spawning a session daemon
626 // Error: Unable to list UST events: Listing UST events failed
627 // or:
628 // Error: Unable to list UST events: Listing UST events failed
629 if (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN)) {
630 return allProviders;
631 }
632 throw new ExecutionException(Messages.TraceControl_CommandError + command.toString());
633 }
634
635 Document document = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
636 NodeList rawProviders = document.getElementsByTagName(MIStrings.PID);
637
638 IUstProviderInfo providerInfo = null;
639
640 for (int i = 0; i < rawProviders.getLength(); i++) {
641 Node provider = rawProviders.item(i);
642 Node name = getFirstOf(provider.getChildNodes(), MIStrings.NAME);
643 if (name == null) {
644 throw new ExecutionException(Messages.TraceControl_MiInvalidProviderError);
645 }
646 providerInfo = new UstProviderInfo(name.getTextContent());
647
648 // Populate provider
649 NodeList infos = provider.getChildNodes();
650 for (int j = 0; j < infos.getLength(); j++) {
651 Node info = infos.item(j);
652 switch (info.getNodeName()) {
653 case MIStrings.PID_ID:
654 providerInfo.setPid(Integer.parseInt(info.getTextContent()));
655 break;
656 case MIStrings.EVENTS:
657 List<IBaseEventInfo> events = new ArrayList<>();
658 NodeList rawEvents = info.getChildNodes();
659 getBaseEventInfo(rawEvents, events);
660 providerInfo.setEvents(events);
661 break;
662 default:
663 break;
664 }
665 }
666 allProviders.add(providerInfo);
667 }
668
669 if (isVersionSupported("2.6")) { //$NON-NLS-1$
670 getUstProviderLoggers(allProviders, TraceDomainType.JUL, monitor);
671 getUstProviderLoggers(allProviders, TraceDomainType.LOG4J, monitor);
672 if (isVersionSupported("2.7")) { //$NON-NLS-1$
673 getUstProviderLoggers(allProviders, TraceDomainType.PYTHON, monitor);
674 }
675 }
676
677 return allProviders;
678 }
679
680 @Override
681 public ISessionInfo createSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
682 if (sessionInfo.isStreamedTrace()) {
683 return createStreamedSession(sessionInfo, monitor);
684 }
685
686 ICommandInput command = prepareSessionCreationCommand(sessionInfo);
687 ICommandResult result = executeCommand(command, monitor);
688
689 Document document = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
690 NodeList sessions = document.getElementsByTagName(MIStrings.SESSION);
691
692 // Number of session should be equal to 1
693 if (sessions.getLength() != 1) {
694 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" //$NON-NLS-1$//$NON-NLS-2$
695 + NLS.bind(Messages.TraceControl_UnexpectedNumberOfElementError, MIStrings.SESSION) + " " + sessions.getLength()); //$NON-NLS-1$
696 }
697
698 // Fetch a session from output
699 ISessionInfo outputSession = new SessionInfo(""); //$NON-NLS-1$
700 parseSession(outputSession, sessions.item(0));
701
702 // Verify session name
703 if ((outputSession.getName().equals("")) || (!"".equals(sessionInfo.getName()) && !outputSession.getName().equals(sessionInfo.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
704 // Unexpected name returned
705 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
706 Messages.TraceControl_UnexpectedNameError + ": " + outputSession.getName()); //$NON-NLS-1$
707 }
708
709 // Verify session path
710 if (!sessionInfo.isSnapshotSession() &&
711 ((outputSession.getSessionPath() == null) || ((sessionInfo.getSessionPath() != null) && (!outputSession.getSessionPath().contains(sessionInfo.getSessionPath()))))) {
712 // Unexpected path
713 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
714 Messages.TraceControl_UnexpectedPathError + ": " + outputSession.getName()); //$NON-NLS-1$
715 }
716
717 if (sessionInfo.isSnapshotSession()) {
718 // Make it a snapshot session - content of snapshot info need to
719 // set afterwards using getSession() or getSnapshotInfo()
720 outputSession.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
721 }
722
723 return outputSession;
724 }
725
726 private @NonNull ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
727
728 ICommandInput command = prepareStreamedSessionCreationCommand(sessionInfo);
729
730 ICommandResult result = executeCommand(command, monitor);
731
732 Document document = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
733 NodeList sessions = document.getElementsByTagName(MIStrings.SESSION);
734
735 // Number of session should be equal to 1
736 if (sessions.getLength() != 1) {
737 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" //$NON-NLS-1$//$NON-NLS-2$
738 + NLS.bind(Messages.TraceControl_UnexpectedNumberOfElementError, MIStrings.SESSION) + " " + sessions.getLength()); //$NON-NLS-1$
739 }
740
741 // Fetch a session from output
742 ISessionInfo outputSession = new SessionInfo(""); //$NON-NLS-1$
743 parseSession(outputSession, sessions.item(0));
744
745 // Verify session name
746 if ((outputSession.getName().equals("")) || (!"".equals(sessionInfo.getName()) && !outputSession.getName().equals(sessionInfo.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
747 // Unexpected name returned
748 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
749 Messages.TraceControl_UnexpectedNameError + ": " + outputSession.getName()); //$NON-NLS-1$
750 }
751
752 sessionInfo.setName(outputSession.getName());
753 sessionInfo.setStreamedTrace(true);
754
755 // Verify session path
756 if (sessionInfo.getNetworkUrl() != null) {
757 if (!sessionInfo.isSnapshotSession() && (outputSession.getSessionPath() == null)) {
758 // Unexpected path
759 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
760 Messages.TraceControl_UnexpectedPathError + ": " + outputSession.getName()); //$NON-NLS-1$
761 }
762
763 if (sessionInfo.isSnapshotSession()) {
764 sessionInfo.setStreamedTrace(false);
765 } else {
766 sessionInfo.setSessionPath(outputSession.getSessionPath());
767 // Check file protocol
768 Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(outputSession.getSessionPath());
769 if (matcher.matches()) {
770 sessionInfo.setStreamedTrace(false);
771 }
772 }
773 }
774
775 // When using controlUrl and dataUrl the full session path is not known
776 // yet
777 // and will be set later on when listing the session
778 return sessionInfo;
779 }
780
781 @Override
782 public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
783 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, sessionName);
784
785 ICommandResult result = executeCommand(command, monitor, false);
786 List<String> errorOutput = result.getErrorOutput();
787
788 if (isError(result)) {
789 // Don't treat this as an error
790 if (ignoredPattern(errorOutput, LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN)) {
791 return;
792
793 }
794 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$
795 }
796
797 // Check for action effect
798 Document doc = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
799 NodeList sessions = doc.getElementsByTagName(MIStrings.SESSION);
800 if (sessions.getLength() != 1) {
801 throw new ExecutionException(NLS.bind(Messages.TraceControl_MiInvalidNumberOfElementError, MIStrings.SESSION));
802 }
803
804 Node rawSessionName = getFirstOf(sessions.item(0).getChildNodes(), MIStrings.NAME);
805 if (rawSessionName == null) {
806 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
807 }
808
809 // Validity check
810 if (!rawSessionName.getTextContent().equals(sessionName)) {
811 throw new ExecutionException(NLS.bind(Messages.TraceControl_UnexpectedValueError, rawSessionName.getTextContent(), sessionName));
812 }
813 }
814
815 @Override
816 protected ICommandInput createCommand(String... strings) {
817 ICommandInput command = getCommandShell().createCommand();
818 command.add(LTTngControlServiceConstants.CONTROL_COMMAND);
819 List<@NonNull String> groupOption = getTracingGroupOption();
820 if (!groupOption.isEmpty()) {
821 command.addAll(groupOption);
822 }
823 command.add(LTTngControlServiceConstants.CONTROL_COMMAND_MI_OPTION);
824 command.add(LTTngControlServiceConstants.CONTROL_COMMAND_MI_XML);
825 for (String string : strings) {
826 command.add(checkNotNull(string));
827 }
828 return command;
829 }
830
831 /**
832 * @param xmlBaseEvents
833 * a Node list of base xml event element
834 * @param events
835 * list of event generated by the parsing of the xml event
836 * element
837 * @throws ExecutionException
838 * when a raw event is not a complete/valid xml event
839 */
840 private static void getBaseEventInfo(NodeList xmlBaseEvents, List<IBaseEventInfo> events) throws ExecutionException {
841 IBaseEventInfo eventInfo = null;
842 for (int i = 0; i < xmlBaseEvents.getLength(); i++) {
843 NodeList rawInfos = xmlBaseEvents.item(i).getChildNodes();
844 // Search for name
845 if (xmlBaseEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
846 Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
847 if (rawName == null) {
848 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
849 }
850 eventInfo = new BaseEventInfo(rawName.getTextContent());
851
852 // Populate the event
853 for (int j = 0; j < rawInfos.getLength(); j++) {
854 Node infoNode = rawInfos.item(j);
855 switch (infoNode.getNodeName()) {
856 case MIStrings.TYPE:
857 eventInfo.setEventType(infoNode.getTextContent());
858 break;
859 case MIStrings.LOGLEVEL:
860 eventInfo.setLogLevel(infoNode.getTextContent());
861 break;
862 case MIStrings.EVENT_FIELDS:
863 List<IFieldInfo> fields = new ArrayList<>();
864 getFieldInfo(infoNode.getChildNodes(), fields);
865 eventInfo.setFields(fields);
866 break;
867 default:
868 break;
869 }
870 }
871 events.add(eventInfo);
872 }
873 }
874 }
875
876 /**
877 * @param xmlBaseEvents
878 * a Node list of xml event element linked to a session
879 * @param events
880 * list of event generated by the parsing of the xml event
881 * element
882 * @throws ExecutionException
883 * when a raw event is not a complete/valid xml event
884 */
885 static void getEventInfo(NodeList xmlEvents, List<IEventInfo> events) throws ExecutionException {
886 IEventInfo eventInfo = null;
887 for (int i = 0; i < xmlEvents.getLength(); i++) {
888 NodeList rawInfos = xmlEvents.item(i).getChildNodes();
889 // Search for name
890 if (xmlEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
891 Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
892 if (rawName == null) {
893 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
894 }
895
896 eventInfo = new EventInfo(rawName.getTextContent());
897
898 // Basic information
899 for (int j = 0; j < rawInfos.getLength(); j++) {
900 Node infoNode = rawInfos.item(j);
901 switch (infoNode.getNodeName()) {
902 case MIStrings.TYPE:
903 eventInfo.setEventType(infoNode.getTextContent());
904 break;
905 case MIStrings.LOGLEVEL_TYPE:
906 eventInfo.setLogLevelType(LogLevelType.valueOfString(infoNode.getTextContent()));
907 break;
908 case MIStrings.LOGLEVEL:
909 eventInfo.setLogLevel(TraceLogLevel.valueOfString(infoNode.getTextContent()));
910 break;
911 case MIStrings.ENABLED:
912 eventInfo.setState(TraceEnablement.valueOfString(infoNode.getTextContent()));
913 break;
914 case MIStrings.FILTER:
915 // Before LTTng 2.8: We emulate the non-mi behavior and simply put
916 // "with filter"
917 if (Boolean.TRUE.toString().equals(infoNode.getTextContent())) {
918 eventInfo.setFilterExpression(Messages.TraceControl_DefaultEventFilterString);
919 }
920 break;
921 case MIStrings.FILTER_EXPRESSION:
922 eventInfo.setFilterExpression(infoNode.getTextContent());
923 break;
924 case MIStrings.EXCLUSION:
925 // Before LTTng 2.8: We emulate the non-mi behavior and simply put
926 // "with exclude"
927 if (Boolean.TRUE.toString().equals(infoNode.getTextContent())) {
928 eventInfo.setExcludedEvents(Messages.TraceControl_DefaultEventExcludeString);
929 }
930 break;
931 case MIStrings.EXCLUSIONS:
932 StringBuilder tmpString = new StringBuilder();
933 // If there is multiple events excluded.
934 for (int k = 0; k < infoNode.getChildNodes().getLength(); k++) {
935 if (k > 0) {
936 tmpString.append(", "); //$NON-NLS-1$
937 }
938 tmpString.append(infoNode.getChildNodes().item(k).getTextContent());
939 }
940 eventInfo.setExcludedEvents(tmpString.toString());
941 break;
942 default:
943 break;
944 }
945 }
946
947 boolean isProbeFunction = (eventInfo.getEventType().equals(TraceEventType.PROBE)) || (eventInfo.getEventType().equals(TraceEventType.FUNCTION));
948 if (isProbeFunction) {
949 IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo);
950 eventInfo = probeEvent;
951
952 Node rawDataNode = null;
953 switch (probeEvent.getEventType()) {
954 case FUNCTION:
955 case PROBE: {
956 // get attributes
957 Node rawAttributes = getFirstOf(rawInfos, MIStrings.ATTRIBUTES);
958 if (rawAttributes == null) {
959 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
960 }
961 rawDataNode = getFirstOf(rawAttributes.getChildNodes(), MIStrings.PROBE_ATTRIBUTES);
962 break;
963 }
964 case SYSCALL:
965 case TRACEPOINT:
966 case UNKNOWN:
967 default:
968 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
969 }
970
971 if (rawDataNode == null) {
972 throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
973 }
974
975 // Extract info
976 NodeList rawDatas = rawDataNode.getChildNodes();
977 for (int j = 0; j < rawDatas.getLength(); j++) {
978 Node rawData = rawDatas.item(j);
979 switch (rawData.getNodeName()) {
980 case MIStrings.SYMBOL_NAME:
981 probeEvent.setSymbol(rawData.getTextContent());
982 break;
983 case MIStrings.ADDRESS:
984 probeEvent.setAddress(String.format("%#016x", new BigInteger(rawData.getTextContent()))); //$NON-NLS-1$
985 break;
986 case MIStrings.OFFSET:
987 probeEvent.setOffset(String.format("%#016x", new BigInteger(rawData.getTextContent()))); //$NON-NLS-1$
988 break;
989 default:
990 break;
991 }
992 }
993 }
994
995 // Add the event
996 events.add(eventInfo);
997 }
998 }
999 }
1000
1001 static void getLoggerInfo(NodeList xmlEvents, List<ILoggerInfo> loggers, TraceDomainType domain) throws ExecutionException {
1002 ILoggerInfo loggerInfo = null;
1003 for (int i = 0; i < xmlEvents.getLength(); i++) {
1004 NodeList rawInfos = xmlEvents.item(i).getChildNodes();
1005 // Search for name
1006 if (xmlEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
1007 Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
1008 if (rawName == null) {
1009 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
1010 }
1011
1012 loggerInfo = new LoggerInfo(rawName.getTextContent());
1013 loggerInfo.setDomain(domain);
1014
1015 // Basic information
1016 for (int j = 0; j < rawInfos.getLength(); j++) {
1017 Node infoNode = rawInfos.item(j);
1018 switch (infoNode.getNodeName()) {
1019 case MIStrings.LOGLEVEL_TYPE:
1020 loggerInfo.setLogLevelType(LogLevelType.valueOfString(infoNode.getTextContent()));
1021 break;
1022 case MIStrings.LOGLEVEL:
1023 switch (domain) {
1024 case JUL:
1025 loggerInfo.setLogLevel(TraceJulLogLevel.valueOfString(infoNode.getTextContent()));
1026 break;
1027 case LOG4J:
1028 loggerInfo.setLogLevel(TraceLog4jLogLevel.valueOfString(infoNode.getTextContent()));
1029 break;
1030 case PYTHON:
1031 loggerInfo.setLogLevel(TracePythonLogLevel.valueOfString(infoNode.getTextContent()));
1032 break;
1033 //$CASES-OMITTED$
1034 default:
1035 break;
1036 }
1037 break;
1038 case MIStrings.ENABLED:
1039 loggerInfo.setState(TraceEnablement.valueOfString(infoNode.getTextContent()));
1040 break;
1041 default:
1042 break;
1043 }
1044 }
1045 // Add the event
1046 loggers.add(loggerInfo);
1047 }
1048 }
1049 }
1050
1051 /**
1052 * @param fieldsList
1053 * a list of xml event_field element
1054 * @param fields
1055 * a list of field generated by xml parsing
1056 * @throws ExecutionException
1057 * when parsing fail or required elements are missing
1058 */
1059 private static void getFieldInfo(NodeList fieldsList, List<IFieldInfo> fields) throws ExecutionException {
1060 IFieldInfo fieldInfo = null;
1061 for (int i = 0; i < fieldsList.getLength(); i++) {
1062 Node field = fieldsList.item(i);
1063 if (field.getNodeName().equalsIgnoreCase(MIStrings.EVENT_FIELD)) {
1064 // Get name
1065 Node name = getFirstOf(field.getChildNodes(), MIStrings.NAME);
1066 if (name == null) {
1067 throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
1068 }
1069 fieldInfo = new FieldInfo(name.getTextContent());
1070
1071 // Populate the field information
1072 NodeList infos = field.getChildNodes();
1073 for (int j = 0; j < infos.getLength(); j++) {
1074 Node info = infos.item(j);
1075 switch (info.getNodeName()) {
1076 case MIStrings.TYPE:
1077 fieldInfo.setFieldType(info.getTextContent());
1078 break;
1079 default:
1080 break;
1081 }
1082 }
1083 fields.add(fieldInfo);
1084 }
1085 }
1086 }
1087
1088 /**
1089 * Retrieve the fist instance of a given node with tag name equal to tagName
1090 * parameter
1091 *
1092 * @param nodeList
1093 * the list of Node to search against
1094 * @param tagName
1095 * the tag name of the desired node
1096 * @return the first occurrence of a node with a tag name equals to tagName
1097 */
1098 private static @Nullable Node getFirstOf(NodeList nodeList, String tagName) {
1099 Node node = null;
1100 for (int i = 0; i < nodeList.getLength(); i++) {
1101 if (Objects.equals(nodeList.item(i).getNodeName(), tagName)) {
1102 node = nodeList.item(i);
1103 break;
1104 }
1105 }
1106 return node;
1107 }
1108
1109 /**
1110 * Retrieve the loggers of a certain domain type for the UST provider.
1111 *
1112 * @param allProviders
1113 * the list of UST providers
1114 * @param domain
1115 * the loggers domain
1116 * @param monitor
1117 * progress monitor
1118 * @throws ExecutionException
1119 */
1120 private void getUstProviderLoggers(List<IUstProviderInfo> allProviders, TraceDomainType domain, IProgressMonitor monitor) throws ExecutionException {
1121 // Getting the loggers information since those are under the UST provider
1122 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
1123 switch (domain) {
1124 case JUL:
1125 command.add(LTTngControlServiceConstants.OPTION_JUL);
1126 break;
1127 case LOG4J:
1128 command.add(LTTngControlServiceConstants.OPTION_LOG4J);
1129 break;
1130 case PYTHON:
1131 command.add(LTTngControlServiceConstants.OPTION_PYTHON);
1132 break;
1133 //$CASES-OMITTED$
1134 default:
1135 break;
1136 }
1137 // Execute listing
1138 ICommandResult result = executeCommand(command, monitor, false);
1139
1140 if (isError(result)) {
1141 throw new ExecutionException(Messages.TraceControl_CommandError + command.toString());
1142 }
1143
1144 Document document = getDocumentFromStrings(result.getOutput(), fDocumentBuilder);
1145 NodeList rawProviders = document.getElementsByTagName(MIStrings.PID);
1146
1147 for (int i = 0; i < rawProviders.getLength(); i++) {
1148 Node provider = rawProviders.item(i);
1149 Node name = getFirstOf(provider.getChildNodes(), MIStrings.NAME);
1150 if (name == null) {
1151 throw new ExecutionException(Messages.TraceControl_MiInvalidProviderError);
1152 }
1153
1154 Node id = getFirstOf(provider.getChildNodes(), MIStrings.PID_ID);
1155
1156 if (id != null) {
1157 for (int k = 0; k < allProviders.size(); k++) {
1158 if (allProviders.get(k).getPid() == Integer.parseInt(id.getTextContent())) {
1159 Node events = getFirstOf(provider.getChildNodes(), MIStrings.EVENTS);
1160 if (events != null) {
1161 List<ILoggerInfo> loggers = new ArrayList<>();
1162 NodeList rawEvents = events.getChildNodes();
1163 getLoggerInfo(rawEvents, loggers, domain);
1164 for (ILoggerInfo logger : loggers) {
1165 logger.setDomain(domain);
1166 }
1167 allProviders.get(k).addLoggers(loggers);
1168 }
1169 }
1170 }
1171 }
1172 }
1173 }
1174
1175 @Override
1176 public @NonNull List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
1177 if (!isVersionSupported("2.8.0")) { //$NON-NLS-1$
1178 return super.getContextList(monitor);
1179 }
1180
1181 ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT, LTTngControlServiceConstants.OPTION_LIST);
1182 ICommandResult result = executeCommand(command, monitor);
1183 return result.getOutput();
1184 }
1185 }
This page took 0.063705 seconds and 5 git commands to generate.