c234cf438d77b65e06de4c2c4c360273812652ad
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 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.trace
;
17 import org
.eclipse
.core
.resources
.IProject
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.core
.runtime
.QualifiedName
;
21 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.GdbTraceCorePlugin
;
22 import org
.eclipse
.linuxtools
.internal
.gdbtrace
.core
.event
.GdbTraceEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLongLocation
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
34 * GDB Tracepoint extension of TmfTrace. This class implements the necessary
35 * methods and functionalities so that a GDB tracepoint file can be used by
36 * the TMF framework as a "tracer".
39 * @author Francois Chouinard
41 public class GdbTrace
extends TmfTrace
implements ITmfEventParser
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 private static final int CACHE_SIZE
= 20;
48 private static final String GDB_EXECUTABLE
= "gdb"; //$NON-NLS-1$
50 /** The qualified name for the 'executable' persistent property */
51 public static final QualifiedName EXEC_KEY
= new QualifiedName(GdbTraceCorePlugin
.PLUGIN_ID
, "executable"); //$NON-NLS-1$
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 // Interface to access GDB Tracepoints
58 private DsfGdbAdaptor fGdbTpRef
;
59 private long fNbFrames
= 0;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
72 setCacheSize(CACHE_SIZE
);
76 public boolean validate(IProject project
, String path
) {
77 return fileExists(path
);
81 public void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
{
83 String tracedExecutable
= resource
.getPersistentProperty(EXEC_KEY
);
84 if (tracedExecutable
== null) {
85 throw new TmfTraceException("Trace executable not set"); //$NON-NLS-1$
87 fGdbTpRef
= new DsfGdbAdaptor(this, GDB_EXECUTABLE
, path
, tracedExecutable
);
88 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
89 } catch (CoreException e
) {
90 throw new TmfTraceException("Failed to initialize trace", e
); //$NON-NLS-1$
93 super.initTrace(resource
, path
, type
);
97 public synchronized void dispose() {
98 if (fGdbTpRef
!= null) {
105 * @return GDB-DSF session id
107 public String
getDsfSessionId () {
108 return fGdbTpRef
.getSessionId();
112 * @return the number of frames in current tp session
114 public long getNbFrames () {
115 fNbFrames
= fGdbTpRef
.getNumberOfFrames();
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
124 public synchronized TmfContext
seekEvent(ITmfLocation location
) {
125 fLocation
= (location
!= null) ?
((Long
) location
.getLocationInfo()) : 0;
126 return new TmfContext(new TmfLongLocation(fLocation
), fLocation
);
130 public synchronized ITmfContext
seekEvent(double ratio
) {
131 TmfContext context
= seekEvent((long) ratio
* getNbEvents());
136 public double getLocationRatio(ITmfLocation location
) {
137 if (getNbEvents() > 0 && location
instanceof TmfLongLocation
) {
138 return (double) ((TmfLongLocation
) location
).getLocationInfo() / getNbEvents();
144 public ITmfLocation
getCurrentLocation() {
145 return new TmfLongLocation(fLocation
);
149 public GdbTraceEvent
parseEvent(ITmfContext context
) {
150 if (context
.getRank() >= fNbFrames
) {
153 // work-around to ensure that the select and parse of trace frame will be atomic
154 GdbTraceEvent event
= fGdbTpRef
.selectAndReadFrame(context
.getRank());
160 public synchronized TmfContext
seekEvent(ITmfTimestamp timestamp
) {
161 long rank
= timestamp
.getValue();
162 return seekEvent(rank
);
166 public synchronized TmfContext
seekEvent(long rank
) {
168 TmfContext context
= new TmfContext(new TmfLongLocation(fLocation
), rank
);
173 * Select a frame and update the visualization
174 * @param rank the rank
176 public void selectFrame(long rank
) {
177 fGdbTpRef
.selectDataFrame(rank
, true);
This page took 0.043664 seconds and 4 git commands to generate.