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