Internalize lttng.core APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / tracecontrol / subsystems / TraceSubSystem.java
CommitLineData
e8d771d5
BH
1/*******************************************************************************
2 * Copyright (c) 2011 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 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
12 *
13 *******************************************************************************/
14package org.eclipse.linuxtools.lttng.ui.tracecontrol.subsystems;
15
1b70b6dc 16import java.io.File;
e8d771d5
BH
17import java.util.ArrayList;
18import java.util.Arrays;
19import java.util.Vector;
20import java.util.concurrent.TimeUnit;
21
22import org.eclipse.core.runtime.IProgressMonitor;
23import org.eclipse.jface.dialogs.MessageDialog;
5945cec9
FC
24import org.eclipse.linuxtools.internal.lttng.core.LttngConstants;
25import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.ProviderResource;
26import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TargetResource;
27import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource;
28import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource.TraceState;
29import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceConfig;
30import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService;
31import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.LttControllerServiceProxy;
32import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.utility.LiveTraceManager;
e8d771d5 33import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
e8d771d5 34import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages;
1b70b6dc
PT
35import org.eclipse.linuxtools.lttng.ui.tracecontrol.TraceControlConstants;
36import org.eclipse.linuxtools.lttng.ui.tracecontrol.actions.ImportToProject;
e8d771d5
BH
37import org.eclipse.linuxtools.lttng.ui.tracecontrol.actions.PauseTrace;
38import org.eclipse.linuxtools.lttng.ui.tracecontrol.connectorservice.TraceConnectorService;
39import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
40import org.eclipse.rse.core.events.SystemResourceChangeEvent;
41import org.eclipse.rse.core.filters.ISystemFilter;
42import org.eclipse.rse.core.filters.ISystemFilterPoolReference;
43import org.eclipse.rse.core.model.IHost;
44import org.eclipse.rse.core.model.ISystemMessageObject;
45import org.eclipse.rse.core.model.ISystemRegistry;
46import org.eclipse.rse.core.model.SystemMessageObject;
47import org.eclipse.rse.core.model.SystemStartHere;
48import org.eclipse.rse.core.subsystems.CommunicationsEvent;
49import org.eclipse.rse.core.subsystems.ICommunicationsListener;
50import org.eclipse.rse.core.subsystems.IConnectorService;
51import org.eclipse.rse.core.subsystems.SubSystem;
52import org.eclipse.rse.services.clientserver.NamePatternMatcher;
53import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
54import org.eclipse.rse.ui.SystemBasePlugin;
55import org.eclipse.swt.widgets.Display;
56import org.eclipse.tm.tcf.protocol.IToken;
57import org.eclipse.tm.tcf.util.TCFTask;
58
59/**
60 * <b><u>TraceSubSystem</u></b>
61 * <p>
62 * Implementation of the trace subsystem. Provides methods to initialize connections
63 * to the remote system, connection handling, filtering and retrival of remote
64 * system configuration.
65 * </p>
66 */
67public class TraceSubSystem extends SubSystem implements ICommunicationsListener {
68
69 // ------------------------------------------------------------------------
70 // Attributes
71 // ------------------------------------------------------------------------
c6f55e56 72
e8d771d5
BH
73 private ProviderResource[] fProviders; // master list of Providers
74
75 // ------------------------------------------------------------------------
76 // Constructors
77 // ------------------------------------------------------------------------
78 /**
79 * @param host
80 * @param connectorService
81 */
82 public TraceSubSystem(IHost host, IConnectorService connectorService) {
83 super(host, connectorService);
84 }
85
86 // ------------------------------------------------------------------------
87 // Operations
88 // ------------------------------------------------------------------------
89
90 /*
91 * (non-Javadoc)
92 * @see org.eclipse.rse.core.subsystems.SubSystem#initializeSubSystem(org.eclipse.core.runtime.IProgressMonitor)
93 */
94 @Override
95 public void initializeSubSystem(IProgressMonitor monitor) {
96 getConnectorService().addCommunicationsListener(this);
97 }
98
99 /*
100 * (non-Javadoc)
101 * @see org.eclipse.rse.core.subsystems.SubSystem#uninitializeSubSystem(org.eclipse.core.runtime.IProgressMonitor)
102 */
103 @Override
104 public void uninitializeSubSystem(IProgressMonitor monitor) {
105 }
106
107 /*
108 * (non-Javadoc)
109 * @see org.eclipse.rse.core.subsystems.SubSystem#getObjectWithAbsoluteName(java.lang.String)
110 *
111 * For drag and drop, and clipboard support of remote objects.
112 *
113 * Return the remote object within the subsystem that corresponds to the specified unique ID. Because each subsystem maintains it's own objects, it's the responsability of the subsystem to determine how an ID (or key) for a given object maps to
114 * the real object. By default this returns null.
115 */
116 @Override
117 public Object getObjectWithAbsoluteName(String key) {
118 return null;
119 }
120
121 /*
122 * (non-Javadoc)
123 * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
124 */
125 @Override
126 protected Object[] internalResolveFilterString(String filterString, IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException {
127
128 ProviderResource[] allProviders;
129
130 try {
131 allProviders = getAllProviders();
132 } catch (SystemMessageException e) {
133 SystemBasePlugin.logError("TraceSubSystem", e); //$NON-NLS-1$
134 Object[] children = new SystemMessageObject[1];
135 children[0] = new SystemMessageObject(e.getSystemMessage(), ISystemMessageObject.MSGTYPE_ERROR, null);
136 return children;
137 }
138
139 // Now, subset master list, based on filter string...
140 NamePatternMatcher subsetter = new NamePatternMatcher(filterString);
141 Vector<ProviderResource> v = new Vector<ProviderResource>();
142 for (int idx = 0; idx < allProviders.length; idx++) {
143 if (subsetter.matches(allProviders[idx].getName())) {
144 v.addElement(allProviders[idx]);
145 }
146 }
147 return allProviders;
148 }
149 /*
150 * (non-Javadoc)
151 * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(java.lang.Object, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
152 */
153 @Override
154 protected Object[] internalResolveFilterString(Object parent, String filterString, IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException {
155 return null;
156 }
157
158 /* (non-Javadoc)
159 * @see org.eclipse.rse.core.subsystems.SubSystem#filterEventFilterCreated(java.lang.Object, org.eclipse.rse.core.filters.ISystemFilter)
160 */
161 @Override
162 public void filterEventFilterCreated(Object selectedObject, ISystemFilter newFilter) {
163 super.filterEventFilterCreated(selectedObject, newFilter);
164 ISystemRegistry registry = SystemStartHere.getSystemRegistry();
165 registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, null));
166 }
167
168 /* (non-Javadoc)
169 * @see org.eclipse.rse.core.subsystems.SubSystem#filterEventFilterPoolReferenceCreated(org.eclipse.rse.core.filters.ISystemFilterPoolReference)
170 */
171 @Override
172 public void filterEventFilterPoolReferenceCreated(ISystemFilterPoolReference newPoolRef) {
173 super.filterEventFilterPoolReferenceCreated(newPoolRef);
174 if (getSystemFilterPoolReferenceManager().getSystemFilterPoolReferenceCount() == 1) {
175 ISystemRegistry registry = SystemStartHere.getSystemRegistry();
176 registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, null));
177 }
178 }
179
180 /**
181 * Retrieves all provider resources from the remote system and updates local references.
182 *
183 * @return provider resources
184 * @throws SystemMessageException
185 * @throws InterruptedException
186 */
187 public ProviderResource[] getAllProviders() throws SystemMessageException, InterruptedException {
188 ProviderResource[] providers = createProviders();
189 if (fProviders == null) {
190 fProviders = providers;
191 }
192 else {
193 for (int i = 0; i < fProviders.length; i++) {
194 for (int j = 0; j < providers.length; j++) {
195 if(fProviders[i].getName().equals(providers[j].getName())) {
196 // Check if all targets already exist
197 fProviders[i].refreshTargets(providers[j].getTargets());
198 }
199 }
200 }
201 }
c6f55e56 202 return (fProviders != null) ? Arrays.copyOf(fProviders, fProviders.length) : null;
e8d771d5
BH
203 }
204
205 /**
206 * Get the list of all targets.
207 *
208 * @return targets The list of targets.
209 * @throws SystemMessageException
210 */
211 public TargetResource[] getAllTargets() throws SystemMessageException {
212 ArrayList<TargetResource> targets = new ArrayList<TargetResource>();
213 if (fProviders != null) {
214 for (int i = 0; i < fProviders.length; i++) {
215 targets.addAll(Arrays.asList(fProviders[i].getTargets()));
216 }
217 }
218 return targets.toArray(new TargetResource[0]);
219 }
220
221 /**
222 * Get the list of all traces.
223 *
224 * @return traces The list of traces.
225 * @throws SystemMessageException
226 */
227 public TraceResource[] getAllTraces() throws SystemMessageException {
228 ArrayList<TraceResource> traces = new ArrayList<TraceResource>();
229 if (fProviders != null) {
230 for (int i = 0; i < fProviders.length; i++) {
231 ProviderResource provider = fProviders[i];
232 int numTargets = provider.getTargets().length;
233 for (int j = 0; j < numTargets; j++) {
234 TargetResource target = provider.getTargets()[j];
235 if (provider.getName().equals(LttngConstants.Lttng_Provider_Kernel)) {
236 traces.addAll(Arrays.asList(target.getTraces()));
237 }
238 }
239 }
240 }
241 return traces.toArray(new TraceResource[0]);
242 }
243
244 /**
245 * Get the list of all traces for given provider and target.
246 *
247 * @param provider
248 * @param target
249 * @returns trace resources
250 */
251 public TraceResource[] getAllTraces(String providerName, String targetName) throws SystemMessageException {
252 ArrayList<TraceResource> traces = new ArrayList<TraceResource>();
253 ProviderResource selectedProvider = null;
254 if (fProviders != null) {
255 for (int i = 0; i < fProviders.length; i++) {
256 ProviderResource provider = fProviders[i];
257 if (provider.getName().equals(providerName)) {
258 selectedProvider = fProviders[i];
259 break;
260 }
261 }
262
263 if (selectedProvider != null) {
264 int numTargets = selectedProvider.getTargets().length;
265 for (int j = 0; j < numTargets; j++) {
266 TargetResource target = selectedProvider.getTargets()[j];
267 if (target.getName().equals(targetName)) {
268 traces.addAll(Arrays.asList(target.getTraces()));
269 break;
270 }
271 }
272 }
273 }
274 return traces.toArray(new TraceResource[0]);
275 }
276
277 /**
278 * Finds a trace resource within a given provider and target for a given trace name
279 *
280 * @param targetName - target name to be searched
281 * @param traceName - trace name to be searched
282 * @return trace resource or null (if not found)
283 */
284 public TraceResource findTrace(String providerName, String targetName, String traceName) {
285 TraceResource trace = null;
286 TraceResource[] traces;
287 try {
288 traces = getAllTraces(providerName, targetName);
289 for (int i = 0; i < traces.length; i++) {
290 if (traces[i].getName().equals(traceName)) {
291 trace = traces[i];
292 break;
293 }
294 }
295 } catch (SystemMessageException e) {
296 SystemBasePlugin.logError("TraceSubSystem", e); //$NON-NLS-1$
297 }
298
299 return trace;
300 }
301
302 /*
303 * Retrieves the providers from the remote system.
304 */
305 private ProviderResource[] createProviders() throws SystemMessageException {
306 ProviderResource[] providers = null;
307 try {
308
309 final ILttControllerService service = getControllerService();
310
311 // Create future task
312 providers = new TCFTask<ProviderResource[]>() {
313 @Override
314 public void run() {
315
316 // Get provider using Lttng controller service proxy
317 service.getProviders(new ILttControllerService.DoneGetProviders() {
318
319 @Override
320 public void doneGetProviders(IToken token, Exception error, String[] str) {
321 if (error != null) {
322 // Notify with error
323 error(error);
324 return;
325 }
326
327 // Create provider list
328 ProviderResource[] providers = new ProviderResource[str.length];
329
330 for (int i = 0; i < str.length; i++) {
331 ProviderResource tempProvider = new ProviderResource(TraceSubSystem.this);
332 tempProvider.setName(str[i]);
333 providers[i] = tempProvider;
334 }
335
336 // Notify with provider list
337 done(providers);
338 }
339 });
340 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
341 } catch (Exception e) {
342 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
343 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
344 }
345
346 for (int i = 0; i < providers.length; i++) {
347 createTargets(providers[i]);
348 }
349
350 return providers;
351 }
352
353 /*
354 * Retrieves the targets for given provider from the remote system.
355 */
356 private TargetResource[] createTargets(final ProviderResource provider) throws SystemMessageException {
357 TargetResource[] targets;
358 try {
359 final ILttControllerService service = getControllerService();
360
361 // Create future task
362 targets = new TCFTask<TargetResource[]>() {
363 @Override
364 public void run() {
365
366 // Get targets using Lttng controller service proxy
367 service.getTargets(provider.getName(), new ILttControllerService.DoneGetTargets() {
368
369 @Override
370 public void doneGetTargets(IToken token, Exception error, String[] str) {
371 if (error != null) {
372 // Notify with error
373 error(error);
374 return;
375 }
376
377 // Create targets
378 TargetResource[] targets = new TargetResource[str.length];
379 for (int i = 0; i < str.length; i++) {
380 TargetResource tempTarget = new TargetResource(TraceSubSystem.this);
381 tempTarget.setName(str[i]);
382 tempTarget.setParent(provider);
383 targets[i] = tempTarget;
384 }
385 // Notify with target list
386 done(targets);
387 }
388 });
389 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
390 } catch (Exception e) {
391 provider.setTargets(new TargetResource[0]);
392 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
393 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
394 }
395
396 provider.setTargets(targets);
397 for (int i = 0; i < targets.length; i++) {
398 if (targets[i].getParent().getName().equals(LttngConstants.Lttng_Provider_Kernel)) {
399 createTraces(targets[i]);
400 }
401 }
402
403 return targets;
404 }
405
406 /*
407 * Retrieves the trace instances for a given target from the remote system.
408 */
409 private TraceResource[] createTraces(final TargetResource target) throws SystemMessageException {
410 TraceResource[] traces;
411 try {
412 final ILttControllerService service = getControllerService();
413
414 // Create future task
415 traces = new TCFTask<TraceResource[]>() {
416 @Override
417 public void run() {
418 // Get targets using Lttng controller service proxy
419 service.getTraces(target.getParent().getName(), target.getName(), new ILttControllerService.DoneGetTraces() {
420
421 @Override
422 public void doneGetTraces(IToken token, Exception error, String[] str) {
423 if (error != null) {
424 // Notify with error
425 error(error);
426 return;
427 }
428
429 // Create trace list
430 TraceResource[] traces = new TraceResource[str.length];
431 for (int i = 0; i < str.length; i++) {
a79913eb 432 TraceResource trace = new TraceResource(TraceSubSystem.this, service);
e8d771d5
BH
433 trace.setName(str[i]);
434 trace.setParent(target);
435 trace.setTraceState(TraceState.CREATED);
436 traces[i] = trace;
437 }
438
439 // Notify with trace list
440 done(traces);
441 }
442 });
443 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
444 } catch (Exception e) {
445 target.setTraces(new TraceResource[0]);
446 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
447 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
448 }
449
450 target.setTraces(traces);
451
452 // get active trace information (is only supported for kernel traces)
453 createTraceConfigurations(target, traces);
454 return traces;
455 }
456
457 /*
458 * Retrieves the trace configurations for the given trace from the remote system.
459 */
460 private void createTraceConfigurations(final TargetResource target, TraceResource[] traces) throws SystemMessageException {
461 if (!target.isUst() && (traces.length > 0)) {
462 // get active traces
463 String[] activeTraceNames;
464 try {
465 final ILttControllerService service = getControllerService();
466 activeTraceNames = new TCFTask<String[]>() {
467 @Override
468 public void run() {
469 // Get targets using Lttng controller service proxy
470 service.getActiveTraces(target.getParent().getName(), target.getName(), new ILttControllerService.DoneGetActiveTraces() {
471
472 @Override
473 public void doneGetActiveTraces(IToken token, Exception error, String[] str) {
474 if (error != null) {
475 // Notify with error
476 error(error);
477 return;
478 }
479
480 // Notify with active trace list
481 done(str);
482 }
483 });
484 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
485 } catch (Exception e) {
486 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
487 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
488 }
489
490 // get active trace information
491 for (int j = 0; j < activeTraceNames.length; j++) {
492 final TraceResource trace = target.getTrace(activeTraceNames[j]);
493 if (trace != null) {
494 // get trace info
495 TraceConfig traceConfig;
496
e8d771d5
BH
497 try {
498 final ILttControllerService service = getControllerService();
499 traceConfig = new TCFTask<TraceConfig>() {
500 @Override
501 public void run() {
502 // Get targets using Lttng controller service proxy
503 service.getActiveTraceInfo(target.getParent().getName(), target.getName(), trace.getName(), new ILttControllerService.DoneGetActiveTraceInfo() {
504
505 @Override
1b70b6dc 506 public void doneGetActiveTraceInfo(IToken token, Exception error, String[] strArray) {
e8d771d5
BH
507 if (error != null) {
508 // Notify with error
509 error(error);
510 return;
511 }
512
513 TraceConfig config = new TraceConfig();
1b70b6dc
PT
514 config.setTraceName(trace.getName());
515 config.setTraceTransport(TraceControlConstants.Lttng_Trace_Transport_Relay);
e8d771d5 516 config.setIsAppend(false);
1b70b6dc
PT
517 for (String pair : strArray) {
518 String[] pairArray = pair.split(LttngConstants.Lttng_Control_GetActiveTraceInfoSeparator);
519 if (pairArray.length != 2) {
520 continue;
521 }
522 String param = pairArray[0];
523 String value = pairArray[1];
524 if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_DESTINATION)) {
525 if (value.startsWith(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_LOCAL)) {
526 config.setNetworkTrace(false);
527 config.setTracePath(value.substring(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_LOCAL.length()));
528 } else if (value.startsWith(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_NETWORK)) {
529 config.setNetworkTrace(true);
530 config.setTracePath(value.substring(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_NETWORK.length()));
531 }
532 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_NUM_THREAD)) {
533 config.setNumChannel(Integer.valueOf(value));
534 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_NORMAL_ONLY)) {
535 if (value.equals(Boolean.toString(true))) {
536 config.setMode(TraceConfig.NORMAL_MODE);
537 }
538 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_FLIGHT_ONLY)) {
539 if (value.equals(Boolean.toString(true))) {
540 config.setMode(TraceConfig.FLIGHT_RECORDER_MODE);
541 }
542 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_ENABLED)) {
543 if (value.equals(Boolean.toString(true))) {
544 trace.setTraceState(TraceState.STARTED);
545 } else {
546 trace.setTraceState(TraceState.PAUSED);
547 }
548 }
e8d771d5 549 }
e8d771d5 550
e8d771d5
BH
551 // Notify with active trace list
552 done(config);
553 }
554 });
555 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
1b70b6dc
PT
556 trace.setTraceConfig(traceConfig);
557 if (traceConfig != null) {
558 if (traceConfig.isNetworkTrace()) {
559 // stop and restart the network transfer since TCF channel may be different
560 if (fProviders == null) { // do this only on startup, not on refresh
561 restartTraceNetwork(service, trace, traceConfig);
562 }
563 LiveTraceManager.setLiveTrace(traceConfig.getTracePath(), true);
564 }
565 }
e8d771d5
BH
566 } catch (Exception e) {
567 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
568 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
569 }
e8d771d5
BH
570 }
571 }
572 }
573 }
574
575 /*
576 * (non-Javadoc)
577 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
578 */
579 @Override
580 public void communicationsStateChange(CommunicationsEvent e) {
581 switch (e.getState())
582 {
583 case CommunicationsEvent.BEFORE_CONNECT :
584 break;
585 case CommunicationsEvent.AFTER_CONNECT :
586 break;
587 case CommunicationsEvent.BEFORE_DISCONNECT :
588
589 try {
590 final TraceResource[] traces = getAllTraces();
591
592 StringBuffer traceNames = new StringBuffer(""); //$NON-NLS-1$
593 String filler = ""; //$NON-NLS-1$
594 for (int j = 0; j < traces.length; j++) {
595 // For network traces, ask user to pause tracing
596 if (traces[j].isNetworkTraceAndStarted()) {
597 traceNames.append(filler);
598 traceNames.append(traces[j].getName());
599 }
600 filler = ", "; //$NON-NLS-1$
601 }
602 if (!"".equals(traceNames.toString())) { //$NON-NLS-1$
603 final String finalTraceNames = traceNames.toString();
604 Display.getDefault().syncExec(new Runnable() {
605
606 @Override
607 public void run() {
608 MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.Ltt_ShutdownWarning, Messages.Ltt_NetworkTraceRunningWarning + ":\n" + finalTraceNames); //$NON-NLS-1$
609
610 // Pause tracing
611 PauseTrace pauseAction = new PauseTrace();
612 pauseAction.setSelectedTraces(new ArrayList<TraceResource>(Arrays.asList(traces)));
613 pauseAction.run(null);
e4dc0a9a
FC
614 try {
615 Thread.sleep(2000); // allow time for target to pause traces before disconnecting the channel
616 } catch (InterruptedException e) {
617 e.printStackTrace();
618 }
e8d771d5
BH
619 }
620 });
621 }
622
623 if (fProviders != null) {
624 // reset all providers and it's children
625 for (int i = 0; i < fProviders.length; i++) {
626 fProviders[i].removeAllTargets();
627 }
628 fProviders = null;
629 }
630
631 } catch (SystemMessageException ex) {
632 SystemBasePlugin.logError("TraceSubSystem", ex); //$NON-NLS-1$
633 }
634 break;
635 case CommunicationsEvent.AFTER_DISCONNECT :
636 getConnectorService().removeCommunicationsListener(this);
637 break;
638 case CommunicationsEvent.CONNECTION_ERROR :
639 // TODO notify user about the lost connection ?!
640 getConnectorService().removeCommunicationsListener(this);
641 try {
642 this.disconnect();
643 } catch (Exception e1) {
644 // Nothing to do
645 }
646 break;
647 default :
648 break;
649 }
650 }
651
652 /*
653 * (non-Javadoc)
654 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
655 */
656 @Override
657 public boolean isPassiveCommunicationsListener() {
658 return true;
659 }
660
661 /**
662 * Returns the trace controller service.
663 *
664 * @return trace controller service
665 * @throws Exception
666 */
667 public LttControllerServiceProxy getControllerService() throws Exception {
668 return ((TraceConnectorService)getConnectorService()).getControllerService();
669 }
1b70b6dc
PT
670
671 /*
672 * Stop and restart the network transfer. Only normal channels are written while trace is started.
673 */
674 private void restartTraceNetwork(final ILttControllerService service, final TraceResource trace, final TraceConfig traceConfig) throws Exception {
675 File newDir = new File(traceConfig.getTracePath());
676 if (!newDir.exists()) {
677 boolean created = newDir.mkdirs();
678 if (!created) {
679 throw new Exception(Messages.Lttng_Control_ErrorCreateTracePath + ": " + traceConfig.getTracePath()); //$NON-NLS-1$
680 }
681 if (traceConfig.getProject() != null) {
682 ImportToProject.linkTrace(getShell(), trace, traceConfig.getProject(), traceConfig.getTraceName());
683 }
684 }
685
686 // stop the previous lttd
687 boolean ok = new TCFTask<Boolean>() {
688 @Override
689 public void run() {
690
691 // Setup trace transport using Lttng controller service proxy
692 service.stopWriteTraceNetwork(trace.getParent().getParent().getName(),
693 trace.getParent().getName(),
694 traceConfig.getTraceName(),
695 new ILttControllerService.DoneStopWriteTraceNetwork() {
696
697 @Override
698 public void doneStopWriteTraceNetwork(IToken token, Exception error, Object str) {
699 if (error != null) {
700 // Notify with error
701 error(error);
702 return;
703 }
704
705 // Notify about success
706 done(true);
707 }
708 });
709 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
710
711 if (!ok) {
712 return;
713 }
714
715 // lttd will only perform the shutdown after stopWriteTraceNetwork
716 // when it receives the next on_read_subbuffer callback
717
718 if (trace.getTraceState() == TraceState.PAUSED) {
719 // we need to start the trace to make sure that the network transfer is stopped
720 ok = new TCFTask<Boolean>() {
721 @Override
722 public void run() {
723
724 // Start the trace
725 service.startTrace(trace.getParent().getParent().getName(),
726 trace.getParent().getName(),
727 traceConfig.getTraceName(),
728 new ILttControllerService.DoneStartTrace() {
729
730 @Override
731 public void doneStartTrace(IToken token, Exception error, Object str) {
732 if (error != null) {
733 // Notify with error
734 error(error);
735 return;
736 }
737
738 // Notify about success
739 done(true);
740 }
741 });
742 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
743
744 if (!ok) {
745 return;
746 }
747
748 trace.setTraceState(TraceState.STARTED);
749
750 // wait for the lttd shutdown
751 Thread.sleep(1000);
752
753 // return to paused state
754 ok = new TCFTask<Boolean>() {
755 @Override
756 public void run() {
757
758 // Pause the trace
759 service.pauseTrace(trace.getParent().getParent().getName(),
760 trace.getParent().getName(),
761 traceConfig.getTraceName(),
762 new ILttControllerService.DonePauseTrace() {
763
764 @Override
765 public void donePauseTrace(IToken token, Exception error, Object str) {
766 if (error != null) {
767 // Notify with error
768 error(error);
769 return;
770 }
771
772 // Notify about success
773 done(true);
774 }
775 });
776 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
777
778 if (!ok) {
779 return;
780 }
781
782 trace.setTraceState(TraceState.PAUSED);
783
784 } else {
785 // wait for the lttd shutdown
786 Thread.sleep(1000);
787 }
788
789 // start a new lttd
790 new TCFTask<Boolean>() {
791 @Override
792 public void run() {
793
794 // Setup trace transport using Lttng controller service proxy
795 service.writeTraceNetwork(trace.getParent().getParent().getName(),
796 trace.getParent().getName(),
797 traceConfig.getTraceName(),
798 traceConfig.getTracePath(),
799 traceConfig.getNumChannel(),
800 traceConfig.getIsAppend(),
801 false,
802 true, // write only normal channels
803 new ILttControllerService.DoneWriteTraceNetwork() {
804
805 @Override
806 public void doneWriteTraceNetwork(IToken token, Exception error, Object str) {
807 if (error != null) {
808 // Notify with error
809 error(error);
810 return;
811 }
812
813 // Notify about success
814 done(true);
815 }
816 });
817 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
818 }
e8d771d5 819}
This page took 0.057893 seconds and 5 git commands to generate.