-
Notifications
You must be signed in to change notification settings - Fork 13
/
Ros2MessageFlowAnalysis.java
159 lines (141 loc) · 6.54 KB
/
Ros2MessageFlowAnalysis.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**********************************************************************
* Copyright (c) 2022 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.messageflow;
import java.util.Arrays;
import java.util.Collections;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.incubator.internal.ros2.core.Activator;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.AbstractRos2StateSystemAnalysis;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.IRos2ModelProvider;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.messagelinks.Ros2MessageCausalLinksAnalysis;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.messages.Ros2MessagesAnalysis;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.objects.Ros2ObjectsAnalysis;
import org.eclipse.tracecompass.incubator.internal.ros2.core.model.Ros2ModelUtils;
import org.eclipse.tracecompass.incubator.internal.ros2.core.model.messageflow.Ros2FlowTargetInfo;
import org.eclipse.tracecompass.incubator.internal.ros2.core.model.messageflow.Ros2MessageFlowModel;
import org.eclipse.tracecompass.incubator.internal.ros2.core.model.messagelinks.Ros2MessageCausalLinksModel;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
/**
* ROS 2 message flow analysis.
*
* @author Christophe Bedard
*/
public class Ros2MessageFlowAnalysis extends TmfAbstractAnalysisModule implements IRos2ModelProvider<Ros2MessageFlowModel> {
/** Name for the {@link Ros2FlowTargetInfo} parameter */
public static final @NonNull String TARGET_INFO_KEY = "target.info"; //$NON-NLS-1$
private static final @NonNull String ID_SUFFIX = ".messageflow"; //$NON-NLS-1$
private @Nullable IProgressMonitor fMonitor;
private @Nullable Ros2MessageFlowModel fModel = null;
/**
* Constructor
*/
public Ros2MessageFlowAnalysis() {
super();
setId(getFullAnalysisId());
addParameter(TARGET_INFO_KEY);
}
/**
* @return the full ID of this analysis module
*/
public static @NonNull String getFullAnalysisId() {
return AbstractRos2StateSystemAnalysis.getAnalysisIdFromSuffix(ID_SUFFIX);
}
@Override
public @Nullable Ros2MessageFlowModel getModel() {
return fModel;
}
@Override
public boolean canExecute(@NonNull ITmfTrace trace) {
// See AbstractRos2StateSystemAnalysis#canExecute
return trace.getParent() == null;
}
@Override
protected boolean executeAnalysis(@NonNull IProgressMonitor monitor) {
// Get target info, do not execute if it has not been set
Object info = getParameter(TARGET_INFO_KEY);
if (!(info instanceof Ros2FlowTargetInfo)) {
Activator.getInstance().logError("No target set; not executing!"); //$NON-NLS-1$
return false;
}
Ros2FlowTargetInfo targetInfo = (Ros2FlowTargetInfo) info;
ITmfTrace trace = getTrace();
if (null == trace) {
return false;
}
// Provide objects state system
ITmfStateSystem objectsSs = Ros2ModelUtils.getStateSystemFromAnalysis(trace, Ros2ObjectsAnalysis.class, Ros2ObjectsAnalysis.getFullAnalysisId());
if (null == objectsSs) {
return false;
}
// Provides messages state system
ITmfStateSystem messagesSs = Ros2ModelUtils.getStateSystemFromAnalysis(trace, Ros2MessagesAnalysis.class, Ros2MessagesAnalysis.getFullAnalysisId());
if (null == messagesSs) {
return false;
}
// Provide the full message links model
Ros2MessageCausalLinksModel messageLinksModel = Ros2ModelUtils.getModelFromAnalysis(trace, Ros2MessageCausalLinksAnalysis.class, Ros2MessageCausalLinksAnalysis.getFullAnalysisId());
if (null == messageLinksModel) {
return false;
}
// Create and generate the model
Ros2MessageFlowModel model = new Ros2MessageFlowModel(targetInfo, objectsSs, messagesSs, messageLinksModel);
if (!monitor.isCanceled()) {
model.generateModel();
}
fModel = model;
return fModel.isDone() && !monitor.isCanceled();
}
@Override
protected void parameterChanged(@NonNull String name) {
if (name.equals(TARGET_INFO_KEY)) {
// Re-run analysis
cancel();
resetAnalysis();
schedule();
}
}
@Override
protected @NonNull Iterable<@NonNull IAnalysisModule> getDependentAnalyses() {
ITmfTrace trace = getTrace();
if (trace == null) {
return Collections.emptySet();
}
// Depends on the objects analysis
Ros2ObjectsAnalysis objectsAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, Ros2ObjectsAnalysis.class, Ros2ObjectsAnalysis.getFullAnalysisId());
if (objectsAnalysis == null) {
return Collections.emptySet();
}
// Depends on the messages analysis
Ros2MessagesAnalysis messagesAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, Ros2MessagesAnalysis.class, Ros2MessagesAnalysis.getFullAnalysisId());
if (messagesAnalysis == null) {
return Collections.emptySet();
}
// Depends on the message links analysis
Ros2MessageCausalLinksAnalysis messageLinksAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, Ros2MessageCausalLinksAnalysis.class, Ros2MessageCausalLinksAnalysis.getFullAnalysisId());
if (messageLinksAnalysis == null) {
return Collections.emptySet();
}
return Arrays.asList(objectsAnalysis, messagesAnalysis, messageLinksAnalysis);
}
@Override
protected void canceling() {
IProgressMonitor mon = fMonitor;
if ((mon != null) && (!mon.isCanceled())) {
mon.setCanceled(true);
}
}
}