CallStackViewer.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.misc;
00002
00003 import java.util.ArrayList;
00004 import java.util.Vector;
00005
00006 import org.eclipse.core.commands.ExecutionException;
00007 import org.eclipse.core.commands.operations.IOperationHistoryListener;
00008 import org.eclipse.core.commands.operations.IUndoableOperation;
00009 import org.eclipse.core.commands.operations.OperationHistoryEvent;
00010 import org.eclipse.core.runtime.IStatus;
00011 import org.eclipse.jface.viewers.ColumnLabelProvider;
00012 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
00013 import org.eclipse.jface.viewers.IStructuredContentProvider;
00014 import org.eclipse.jface.viewers.TableViewer;
00015 import org.eclipse.jface.viewers.TableViewerColumn;
00016 import org.eclipse.jface.viewers.Viewer;
00017 import org.eclipse.jface.window.ToolTip;
00018 import org.eclipse.swt.SWT;
00019 import org.eclipse.swt.graphics.Image;
00020 import org.eclipse.swt.layout.GridData;
00021 import org.eclipse.swt.widgets.Composite;
00022 import org.eclipse.swt.widgets.Event;
00023 import org.eclipse.swt.widgets.Listener;
00024 import org.eclipse.swt.widgets.Table;
00025 import org.eclipse.ui.IWorkbenchWindow;
00026 import org.eclipse.ui.services.ISourceProviderService;
00027
00028 import edu.rice.cs.hpc.traceviewer.operation.BufferRefreshOperation;
00029 import edu.rice.cs.hpc.traceviewer.operation.DepthOperation;
00030 import edu.rice.cs.hpc.traceviewer.operation.PositionOperation;
00031 import edu.rice.cs.hpc.traceviewer.operation.TraceOperation;
00032 import edu.rice.cs.hpc.traceviewer.painter.ImageTraceAttributes;
00033 import edu.rice.cs.hpc.traceviewer.services.DataService;
00034 import edu.rice.cs.hpc.traceviewer.services.ProcessTimelineService;
00035 import edu.rice.cs.hpc.traceviewer.spaceTimeData.Position;
00036 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00037 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00038 import edu.rice.cs.hpc.traceviewer.data.util.Debugger;
00039
00040
00041
00042
00043
00044 public class CallStackViewer extends TableViewer
00045 implements IOperationHistoryListener
00046 {
00047 private final TableViewerColumn viewerColumn;
00048
00049 private final static String EMPTY_FUNCTION = "--------------";
00050
00051 private final ProcessTimelineService ptlService;
00052
00053 private final DataService dataService;
00054
00056 public CallStackViewer(Composite parent, final HPCCallStackView csview)
00057 {
00058 super(parent, SWT.SINGLE );
00059
00060 final IWorkbenchWindow window = (IWorkbenchWindow)csview.getSite().
00061 getWorkbenchWindow();
00062 final ISourceProviderService service = (ISourceProviderService) window.getService(ISourceProviderService.class);
00063
00064 dataService = (DataService) service.getSourceProvider(DataService.DATA_PROVIDER);
00065
00066 ptlService = (ProcessTimelineService) service.getSourceProvider(ProcessTimelineService.PROCESS_TIMELINE_PROVIDER);
00067
00068 final Table stack = this.getTable();
00069
00070 GridData data = new GridData(GridData.FILL_BOTH);
00071 stack.setLayoutData(data);
00072
00073
00074
00075
00076 this.setContentProvider( new IStructuredContentProvider(){
00077
00078 public void dispose() {}
00079
00080 public void inputChanged(Viewer viewer, Object oldInput,
00081 Object newInput) { }
00082
00083 public Object[] getElements(Object inputElement) {
00084 if (inputElement instanceof ArrayList<?>) {
00085 Object o[] = ((ArrayList<?>) inputElement).toArray();
00086 return o;
00087 }
00088 return null;
00089 }
00090
00091 });
00092
00093 stack.setVisible(false);
00094 final CallStackViewer csviewer = this;
00095 stack.addListener(SWT.Selection, new Listener(){
00096 public void handleEvent(Event event)
00097 {
00098 int depth = stack.getSelectionIndex();
00099
00100
00101 csview.depthEditor.setSelection(depth);
00102 notifyChange(depth);
00103 }
00104 });
00105
00106
00107
00108
00109
00110 final ColumnLabelProvider myLableProvider = new ColumnLabelProvider() {
00111 public Image getImage(Object element) {
00112 if (element instanceof String) {
00113 Image img = null;
00114 SpaceTimeDataController stData = dataService.getData();
00115 if (stData != null)
00116 img = stData.getColorTable().getImage((String)element);
00117 return img;
00118 }
00119
00120 return null;
00121 }
00122
00123 public String getText(Object element)
00124 {
00125 if (element instanceof String)
00126 return (String) element;
00127 return null;
00128 }
00129
00130 public String getToolTipText(Object element)
00131 {
00132 return this.getText(element);
00133 }
00134
00135 public int getToolTipDisplayDelayTime(Object object)
00136 {
00137 return 200;
00138 }
00139 };
00140 viewerColumn = new TableViewerColumn(this, SWT.NONE);
00141 viewerColumn.setLabelProvider(myLableProvider);
00142 viewerColumn.getColumn().setWidth(100);
00143
00144 ColumnViewerToolTipSupport.enableFor(csviewer, ToolTip.NO_RECREATE);
00145
00146 TraceOperation.getOperationHistory().addOperationHistoryListener(this);
00147 }
00148
00149
00150
00151
00152 public void updateView()
00153 {
00154 final SpaceTimeDataController data = dataService.getData();
00155 this.setSample(data.getAttributes().getPosition(), data.getAttributes().getDepth());
00156 this.getTable().setVisible(true);
00157 }
00158
00159
00160
00161
00162
00163
00164 public void setSample(Position position, int depth)
00165 {
00166
00167
00168
00169
00170
00171
00172
00173
00174 SpaceTimeDataController stData = dataService.getData();
00175
00176 if (stData == null) {
00177 return;
00178 }
00179
00180 final ImageTraceAttributes attributes = stData.getAttributes();
00181 int estimatedProcess = (attributes.getPosition().process - attributes.getProcessBegin());
00182 int numDisplayedProcess = ptlService.getNumProcessTimeline();
00183
00184
00185 estimatedProcess = (int) ((float)estimatedProcess*
00186 ((float)numDisplayedProcess/(attributes.getProcessInterval())));
00187
00188
00189 estimatedProcess = Math.min(estimatedProcess, numDisplayedProcess-1);
00190
00191 ProcessTimeline ptl = ptlService.getProcessTimeline(estimatedProcess);
00192 if (ptl != null) {
00193 int sample = ptl.findMidpointBefore(position.time, stData.isEnableMidpoint());
00194 final Vector<String> sampleVector;
00195 if (sample>=0)
00196 sampleVector = ptl.getCallPath(sample, depth).getFunctionNames();
00197 else
00198
00199 sampleVector = new Vector<String>();
00200
00201 if (sampleVector.size()<=depth)
00202 {
00203
00204
00205
00206 final int numOverDepth = depth-sampleVector.size()+1;
00207 for(int l = 0; l<numOverDepth; l++)
00208 sampleVector.add(EMPTY_FUNCTION);
00209 }
00210 this.setInput(new ArrayList<String>(sampleVector));
00211
00212 selectDepth(depth);
00213
00214 viewerColumn.getColumn().pack();
00215 }
00216 else
00217 {
00218 Debugger.printTrace("CSV traces: ");
00219 }
00220 }
00221
00223 public void setDepth(int _depth)
00224 {
00225 final int itemCount = this.getTable().getItemCount();
00226 if (itemCount<=_depth)
00227 {
00228
00229
00230
00231 final int overDepth = _depth - itemCount + 1;
00232 for (int i=0; i<overDepth; i++)
00233 {
00234 this.add(EMPTY_FUNCTION);
00235 }
00236 }
00237 selectDepth(_depth);
00238
00239 notifyChange(_depth);
00240 }
00241
00242
00243
00244
00245
00246
00247 private void selectDepth(final int _depth)
00248 {
00249 this.getTable().select(_depth);
00250 this.getTable().redraw();
00251 }
00252
00253
00254 private void notifyChange(int depth)
00255 {
00256 try {
00257 DepthOperation op = new DepthOperation("Set depth to "+depth, depth);
00258 IStatus status = TraceOperation.getOperationHistory().execute(
00259 op, null, null);
00260 if (status.isOK()) {
00261 op.dispose();
00262 }
00263 } catch (ExecutionException e) {
00264
00265 e.printStackTrace();
00266 }
00267 }
00268
00269
00270 @Override
00271 public void historyNotification(final OperationHistoryEvent event) {
00272 final IUndoableOperation operation = event.getOperation();
00273
00274 if (operation.hasContext(BufferRefreshOperation.context) ||
00275 operation.hasContext(PositionOperation.context)) {
00276 if (event.getEventType() == OperationHistoryEvent.DONE) {
00277 updateView();
00278 }
00279 }
00280 }
00281 }