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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.analysis
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.event
.PcapEvent
;
22 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.event
.TmfPacketStreamBuilder
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.protocol
.TmfPcapProtocol
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.trace
.PcapTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfExperiment
;
35 * A pcap-specific analysis that parse an entire trace to find all the streams.
37 * @author Vincent Perot
39 public class StreamListAnalysis
extends TmfAbstractAnalysisModule
{
42 * The Stream List analysis ID.
44 public static final String ID
= "org.eclipse.linuxtools.tmf.pcap.core.analysis.stream"; //$NON-NLS-1$
46 private @Nullable ITmfEventRequest fRequest
;
47 private final Map
<TmfPcapProtocol
, TmfPacketStreamBuilder
> fBuilders
;
50 * The default constructor. It initializes all variables.
52 public StreamListAnalysis() {
54 fBuilders
= new HashMap
<>();
55 for (TmfPcapProtocol protocol
: TmfPcapProtocol
.values()) {
56 if (protocol
.supportsStream()) {
57 fBuilders
.put(protocol
, new TmfPacketStreamBuilder(protocol
));
63 public boolean canExecute(ITmfTrace trace
) {
66 if (trace
instanceof PcapTrace
) {
70 // Trace is not a TmfExperiment
71 if (!(trace
instanceof TmfExperiment
)) {
75 // Trace is TmfExperiment. Check if it has a PcapTrace.
76 TmfExperiment experiment
= (TmfExperiment
) trace
;
77 ITmfTrace
[] traces
= experiment
.getTraces();
78 for (int i
= 0; i
< traces
.length
; i
++) {
79 if (traces
[i
] instanceof PcapTrace
) {
89 protected boolean executeAnalysis(@Nullable IProgressMonitor monitor
) throws TmfAnalysisException
{
90 IProgressMonitor mon
= (monitor
== null ?
new NullProgressMonitor() : monitor
);
91 ITmfTrace trace
= getTrace();
93 /* This analysis was cancelled in the meantime */
97 ITmfEventRequest request
= fRequest
;
98 if ((request
!= null) && (!request
.isCompleted())) {
102 request
= new TmfEventRequest(PcapEvent
.class,
103 TmfTimeRange
.ETERNITY
, 0L, ITmfEventRequest
.ALL_DATA
,
104 ITmfEventRequest
.ExecutionType
.BACKGROUND
) {
107 public void handleData(ITmfEvent data
) {
108 // Called for each event
109 super.handleData(data
);
110 if (!(data
instanceof PcapEvent
)) {
113 PcapEvent event
= (PcapEvent
) data
;
114 for (TmfPcapProtocol protocol
: fBuilders
.keySet()) {
115 fBuilders
.get(protocol
).addEventToStream(event
);
120 trace
.sendRequest(request
);
123 request
.waitForCompletion();
124 } catch (InterruptedException e
) {
125 // Request was canceled.
129 return !mon
.isCanceled() && !request
.isCancelled() && !request
.isFailed();
134 protected void canceling() {
135 ITmfEventRequest req
= fRequest
;
136 if ((req
!= null) && (!req
.isCompleted())) {
142 * Getter method that returns the packet builder associated to a particular
146 * The specified protocol.
147 * @return The builder.
149 public @Nullable TmfPacketStreamBuilder
getBuilder(TmfPcapProtocol protocol
) {
150 return fBuilders
.get(protocol
);
154 * Method that indicates if the analysis is still running or has finished.
156 * @return Whether the analysis is finished or not.
158 public boolean isFinished() {
159 ITmfEventRequest req
= fRequest
;
163 return req
.isCompleted();