1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 * Marc Dumais - Initial implementation
11 * Francois Chouinard - Initial API and implementation
12 * Patrick Tasse - Updated for TMF 2.0
13 * Matthew Khouzam - update validate
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.trace
;
20 import org
.eclipse
.core
.resources
.IProject
;
21 import org
.eclipse
.core
.resources
.IResource
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.QualifiedName
;
25 import org
.eclipse
.core
.runtime
.Status
;
26 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.Activator
;
27 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.GdbTraceCorePlugin
;
28 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.event
.GdbTraceEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLongLocation
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
40 * GDB Tracepoint extension of TmfTrace. This class implements the necessary
41 * methods and functionalities so that a GDB tracepoint file can be used by the
42 * TMF framework as a "tracer".
46 * @author Francois Chouinard
47 * @author Matthew Khouzam
49 public class GdbTrace
extends TmfTrace
implements ITmfEventParser
{
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 private static final int CACHE_SIZE
= 20;
56 private static final String GDB_EXECUTABLE
= "gdb"; //$NON-NLS-1$
58 /** The qualified name for the 'executable' persistent property */
59 public static final QualifiedName EXEC_KEY
= new QualifiedName(GdbTraceCorePlugin
.PLUGIN_ID
, "executable"); //$NON-NLS-1$
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 // Interface to access GDB Tracepoints
66 private DsfGdbAdaptor fGdbTpRef
;
67 private long fNbFrames
= 0;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
80 setCacheSize(CACHE_SIZE
);
84 public IStatus
validate(IProject project
, String path
) {
85 if (fileExists(path
)) {
86 if ((new File(path
)).isFile()) {
87 return Status
.OK_STATUS
;
89 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
,
90 Messages
.GdbTrace_GdbTracesMustBeAFile
+ ": " + //$NON-NLS-1$
91 path
+ " " + Messages
.GdbTrace_IsNotAFile
); //$NON-NLS-1$
93 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.GdbTrace_FileNotFound
+ ": " + path
); //$NON-NLS-1$
97 public void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
{
99 String tracedExecutable
= resource
.getPersistentProperty(EXEC_KEY
);
100 if (tracedExecutable
== null) {
101 throw new TmfTraceException(Messages
.GdbTrace_ExecutableNotSet
);
103 fGdbTpRef
= new DsfGdbAdaptor(this, GDB_EXECUTABLE
, path
, tracedExecutable
);
104 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
105 } catch (CoreException e
) {
106 throw new TmfTraceException(Messages
.GdbTrace_FailedToInitializeTrace
, e
);
109 super.initTrace(resource
, path
, type
);
113 public synchronized void dispose() {
114 if (fGdbTpRef
!= null) {
121 * @return GDB-DSF session id
123 public String
getDsfSessionId() {
124 return fGdbTpRef
.getSessionId();
128 * @return the number of frames in current tp session
130 public long getNbFrames() {
131 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
140 public synchronized TmfContext
seekEvent(ITmfLocation location
) {
141 fLocation
= (location
!= null) ?
((Long
) location
.getLocationInfo()) : 0;
142 return new TmfContext(new TmfLongLocation(fLocation
), fLocation
);
146 public synchronized ITmfContext
seekEvent(double ratio
) {
147 TmfContext context
= seekEvent((long) ratio
* getNbEvents());
152 public double getLocationRatio(ITmfLocation location
) {
153 if (getNbEvents() > 0 && location
instanceof TmfLongLocation
) {
154 return (double) ((TmfLongLocation
) location
).getLocationInfo() / getNbEvents();
160 public ITmfLocation
getCurrentLocation() {
161 return new TmfLongLocation(fLocation
);
165 public GdbTraceEvent
parseEvent(ITmfContext context
) {
166 if (context
.getRank() >= fNbFrames
) {
169 // work-around to ensure that the select and parse of trace frame will
171 GdbTraceEvent event
= fGdbTpRef
.selectAndReadFrame(context
.getRank());
177 public synchronized TmfContext
seekEvent(ITmfTimestamp timestamp
) {
178 long rank
= timestamp
.getValue();
179 return seekEvent(rank
);
183 public synchronized TmfContext
seekEvent(long rank
) {
185 TmfContext context
= new TmfContext(new TmfLongLocation(fLocation
), rank
);
190 * Select a frame and update the visualization
195 public void selectFrame(long rank
) {
196 fGdbTpRef
.selectDataFrame(rank
, true);