gdbtrace: Use original trace type id
[deliverable/tracecompass.git] / org.eclipse.linuxtools.gdbtrace.core / src / org / eclipse / linuxtools / internal / gdbtrace / core / trace / GdbTrace.java
CommitLineData
6de2f761
PT
1/*******************************************************************************
2 * Copyright (c) 2011, 2013 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 * Marc Dumais - Initial implementation
11 * Francois Chouinard - Initial API and implementation
12 * Patrick Tasse - Updated for TMF 2.0
a94410d9 13 * Matthew Khouzam - update validate
6de2f761
PT
14 *******************************************************************************/
15
8343b1f5 16package org.eclipse.linuxtools.internal.gdbtrace.core.trace;
6de2f761 17
0eefbc92
MK
18import java.io.File;
19
6de2f761
PT
20import org.eclipse.core.resources.IProject;
21import org.eclipse.core.resources.IResource;
22import org.eclipse.core.runtime.CoreException;
a94410d9 23import org.eclipse.core.runtime.IStatus;
6de2f761 24import org.eclipse.core.runtime.QualifiedName;
a94410d9 25import org.eclipse.core.runtime.Status;
0eefbc92 26import org.eclipse.linuxtools.internal.gdbtrace.core.Activator;
8343b1f5
PT
27import org.eclipse.linuxtools.internal.gdbtrace.core.GdbTraceCorePlugin;
28import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEvent;
6de2f761
PT
29import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
30import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
31import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
32import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
33import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
6de2f761 34import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
6de2f761 35import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
a3db8436
AM
36import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
37import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
6de2f761
PT
38
39/**
a94410d9
MK
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".
6de2f761 43 * <p>
a94410d9 44 *
6de2f761
PT
45 * @author Marc Dumais
46 * @author Francois Chouinard
a94410d9 47 * @author Matthew Khouzam
6de2f761
PT
48 */
49public class GdbTrace extends TmfTrace implements ITmfEventParser {
50
51 // ------------------------------------------------------------------------
52 // Constants
53 // ------------------------------------------------------------------------
54
55 private static final int CACHE_SIZE = 20;
56 private static final String GDB_EXECUTABLE = "gdb"; //$NON-NLS-1$
57
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$
60
61 // ------------------------------------------------------------------------
62 // Attributes
63 // ------------------------------------------------------------------------
64
65 // Interface to access GDB Tracepoints
66 private DsfGdbAdaptor fGdbTpRef;
67 private long fNbFrames = 0;
68
69 // The trace location
70 long fLocation;
71
72 // ------------------------------------------------------------------------
73 // Constructor
74 // ------------------------------------------------------------------------
75
76 /**
77 * Default constructor
78 */
79 public GdbTrace() {
80 setCacheSize(CACHE_SIZE);
81 }
82
83 @Override
a94410d9
MK
84 public IStatus validate(IProject project, String path) {
85 if (fileExists(path)) {
0eefbc92
MK
86 if ((new File(path)).isFile()) {
87 return Status.OK_STATUS;
88 }
89 return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
90 Messages.GdbTrace_GdbTracesMustBeAFile + ": " + //$NON-NLS-1$
91 path + " " + Messages.GdbTrace_IsNotAFile); //$NON-NLS-1$
a94410d9
MK
92 }
93 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.GdbTrace_FileNotFound + ": " + path); //$NON-NLS-1$
6de2f761
PT
94 }
95
96 @Override
97 public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException {
98 try {
99 String tracedExecutable = resource.getPersistentProperty(EXEC_KEY);
100 if (tracedExecutable == null) {
0eefbc92 101 throw new TmfTraceException(Messages.GdbTrace_ExecutableNotSet);
6de2f761
PT
102 }
103 fGdbTpRef = new DsfGdbAdaptor(this, GDB_EXECUTABLE, path, tracedExecutable);
104 fNbFrames = fGdbTpRef.getNumberOfFrames();
105 } catch (CoreException e) {
0eefbc92 106 throw new TmfTraceException(Messages.GdbTrace_FailedToInitializeTrace, e);
6de2f761
PT
107 }
108
109 super.initTrace(resource, path, type);
110 }
111
112 @Override
113 public synchronized void dispose() {
114 if (fGdbTpRef != null) {
115 fGdbTpRef.dispose();
116 }
117 super.dispose();
118 }
119
120 /**
121 * @return GDB-DSF session id
122 */
a94410d9 123 public String getDsfSessionId() {
6de2f761
PT
124 return fGdbTpRef.getSessionId();
125 }
126
127 /**
128 * @return the number of frames in current tp session
129 */
a94410d9
MK
130 public long getNbFrames() {
131 fNbFrames = fGdbTpRef.getNumberOfFrames();
6de2f761
PT
132 return fNbFrames;
133 }
134
135 // ------------------------------------------------------------------------
136 // TmfTrace
137 // ------------------------------------------------------------------------
138
139 @Override
140 public synchronized TmfContext seekEvent(ITmfLocation location) {
141 fLocation = (location != null) ? ((Long) location.getLocationInfo()) : 0;
142 return new TmfContext(new TmfLongLocation(fLocation), fLocation);
143 }
144
145 @Override
146 public synchronized ITmfContext seekEvent(double ratio) {
147 TmfContext context = seekEvent((long) ratio * getNbEvents());
148 return context;
149 }
150
151 @Override
152 public double getLocationRatio(ITmfLocation location) {
153 if (getNbEvents() > 0 && location instanceof TmfLongLocation) {
154 return (double) ((TmfLongLocation) location).getLocationInfo() / getNbEvents();
155 }
156 return 0;
157 }
158
159 @Override
160 public ITmfLocation getCurrentLocation() {
161 return new TmfLongLocation(fLocation);
162 }
163
164 @Override
165 public GdbTraceEvent parseEvent(ITmfContext context) {
166 if (context.getRank() >= fNbFrames) {
167 return null;
168 }
a94410d9
MK
169 // work-around to ensure that the select and parse of trace frame will
170 // be atomic
6de2f761
PT
171 GdbTraceEvent event = fGdbTpRef.selectAndReadFrame(context.getRank());
172 fLocation++;
173 return event;
174 }
175
176 @Override
177 public synchronized TmfContext seekEvent(ITmfTimestamp timestamp) {
178 long rank = timestamp.getValue();
179 return seekEvent(rank);
180 }
181
182 @Override
183 public synchronized TmfContext seekEvent(long rank) {
184 fLocation = rank;
185 TmfContext context = new TmfContext(new TmfLongLocation(fLocation), rank);
186 return context;
187 }
188
189 /**
190 * Select a frame and update the visualization
a94410d9
MK
191 *
192 * @param rank
193 * the rank
6de2f761
PT
194 */
195 public void selectFrame(long rank) {
196 fGdbTpRef.selectDataFrame(rank, true);
197 }
198}
This page took 0.038595 seconds and 5 git commands to generate.