diff options
3 files changed, 72 insertions, 63 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java b/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java index b713e5e..3ac5bcc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java @@ -15,15 +15,16 @@ */ package com.android.ide.eclipse.traceview.editors; +import com.android.ide.eclipse.traceview.TraceviewPlugin; import com.android.traceview.ColorController; import com.android.traceview.DmTraceReader; import com.android.traceview.MethodData; import com.android.traceview.ProfileView; -import com.android.traceview.ProfileView.MethodHandler; import com.android.traceview.SelectionController; import com.android.traceview.TimeLineView; import com.android.traceview.TraceReader; import com.android.traceview.TraceUnits; +import com.android.traceview.ProfileView.MethodHandler; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -35,7 +36,9 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.SearchEngine; @@ -56,6 +59,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; @@ -66,6 +70,7 @@ import org.eclipse.ui.part.EditorPart; import org.eclipse.ui.part.FileEditorInput; import java.io.File; +import java.io.IOException; import java.net.URI; public class TraceviewEditor extends EditorPart implements MethodHandler { @@ -257,37 +262,46 @@ public class TraceviewEditor extends EditorPart implements MethodHandler { @Override public void createPartControl(Composite parent) { mParent = parent; - TraceReader reader = new DmTraceReader(mFilename, false); - reader.getTraceUnits().setTimeScale(TraceUnits.TimeScale.MilliSeconds); - - mContents = new Composite(mParent, SWT.NONE); - - Display display = mContents.getDisplay(); - ColorController.assignMethodColors(display, reader.getMethods()); - SelectionController selectionController = new SelectionController(); - - GridLayout gridLayout = new GridLayout(1, false); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - gridLayout.horizontalSpacing = 0; - gridLayout.verticalSpacing = 0; - mContents.setLayout(gridLayout); - - Color darkGray = display.getSystemColor(SWT.COLOR_DARK_GRAY); - - // Create a sash form to separate the timeline view (on top) - // and the profile view (on bottom) - SashForm sashForm1 = new SashForm(mContents, SWT.VERTICAL); - sashForm1.setBackground(darkGray); - sashForm1.SASH_WIDTH = 3; - GridData data = new GridData(GridData.FILL_BOTH); - sashForm1.setLayoutData(data); - - // Create the timeline view - new TimeLineView(sashForm1, reader, selectionController); - - // Create the profile view - new ProfileView(sashForm1, reader, selectionController).setMethodHandler(this); + try { + TraceReader reader = new DmTraceReader(mFilename, false); + reader.getTraceUnits().setTimeScale(TraceUnits.TimeScale.MilliSeconds); + + mContents = new Composite(mParent, SWT.NONE); + + Display display = mContents.getDisplay(); + ColorController.assignMethodColors(display, reader.getMethods()); + SelectionController selectionController = new SelectionController(); + + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + gridLayout.horizontalSpacing = 0; + gridLayout.verticalSpacing = 0; + mContents.setLayout(gridLayout); + + Color darkGray = display.getSystemColor(SWT.COLOR_DARK_GRAY); + + // Create a sash form to separate the timeline view (on top) + // and the profile view (on bottom) + SashForm sashForm1 = new SashForm(mContents, SWT.VERTICAL); + sashForm1.setBackground(darkGray); + sashForm1.SASH_WIDTH = 3; + GridData data = new GridData(GridData.FILL_BOTH); + sashForm1.setLayoutData(data); + + // Create the timeline view + new TimeLineView(sashForm1, reader, selectionController); + + // Create the profile view + new ProfileView(sashForm1, reader, selectionController).setMethodHandler(this); + } catch (IOException e) { + Label l = new Label(parent, 0); + l.setText("Failed to read the stack trace."); + + Status status = new Status(IStatus.ERROR, TraceviewPlugin.PLUGIN_ID, + "Failed to read the stack trace.", e); + TraceviewPlugin.getDefault().getLog().log(status); + } mParent.layout(); } diff --git a/traceview/src/com/android/traceview/DmTraceReader.java b/traceview/src/com/android/traceview/DmTraceReader.java index fbcd13e..ac44a09 100644 --- a/traceview/src/com/android/traceview/DmTraceReader.java +++ b/traceview/src/com/android/traceview/DmTraceReader.java @@ -70,7 +70,7 @@ public class DmTraceReader extends TraceReader { // A regex for matching the thread "id name" lines in the .key file private static final Pattern mIdNamePattern = Pattern.compile("(\\d+)\t(.*)"); //$NON-NLS-1$ - public DmTraceReader(String traceFileName, boolean regression) { + public DmTraceReader(String traceFileName, boolean regression) throws IOException { mTraceFileName = traceFileName; mRegression = regression; mPropertiesMap = new HashMap<String, String>(); @@ -87,15 +87,10 @@ public class DmTraceReader extends TraceReader { generateTrees(); } - void generateTrees() { - try { - long offset = parseKeys(); - parseData(offset); - analyzeData(); - } catch (IOException e) { - System.err.println(e.getMessage()); - System.exit(1); - } + void generateTrees() throws IOException { + long offset = parseKeys(); + parseData(offset); + analyzeData(); } @Override @@ -105,25 +100,17 @@ public class DmTraceReader extends TraceReader { return mProfileProvider; } - private MappedByteBuffer mapFile(String filename, long offset) { + private MappedByteBuffer mapFile(String filename, long offset) throws IOException { MappedByteBuffer buffer = null; - try { - FileInputStream dataFile = new FileInputStream(filename); - File file = new File(filename); - FileChannel fc = dataFile.getChannel(); - buffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, file.length() - offset); - buffer.order(ByteOrder.LITTLE_ENDIAN); - } catch (FileNotFoundException ex) { - System.err.println(ex.getMessage()); - System.exit(1); - } catch (IOException ex) { - System.err.println(ex.getMessage()); - System.exit(1); - } - + FileInputStream dataFile = new FileInputStream(filename); + File file = new File(filename); + FileChannel fc = dataFile.getChannel(); + buffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, file.length() - offset); + buffer.order(ByteOrder.LITTLE_ENDIAN); + return buffer; } - + private void readDataFileHeader(MappedByteBuffer buffer) { int magic = buffer.getInt(); if (magic != TRACE_MAGIC) { @@ -170,7 +157,7 @@ public class DmTraceReader extends TraceReader { } } - private void parseData(long offset) { + private void parseData(long offset) throws IOException { MappedByteBuffer buffer = mapFile(mTraceFileName, offset); readDataFileHeader(buffer); @@ -430,7 +417,7 @@ public class DmTraceReader extends TraceReader { if (line == null) { throw new IOException("Key section does not have an *end marker"); } - + // Calculate how much we have read from the file so far. The // extra byte is for the line ending not included by readLine(). offset += line.length() + 1; @@ -602,7 +589,7 @@ public class DmTraceReader extends TraceReader { for (Call call : mCallList) { call.updateName(); } - + if (mRegression) { dumpMethodStats(); } @@ -664,7 +651,7 @@ public class DmTraceReader extends TraceReader { call.getMethodData().getName()); } } - + private void dumpMethodStats() { System.out.print("\nMethod Stats\n"); System.out.print("Excl Cpu Incl Cpu Excl Real Incl Real Calls Method\n"); diff --git a/traceview/src/com/android/traceview/MainWindow.java b/traceview/src/com/android/traceview/MainWindow.java index cf949a6..0b07163 100644 --- a/traceview/src/com/android/traceview/MainWindow.java +++ b/traceview/src/com/android/traceview/MainWindow.java @@ -253,8 +253,16 @@ public class MainWindow extends ApplicationWindow { } } - reader = new DmTraceReader(traceName, regression); + try { + reader = new DmTraceReader(traceName, regression); + } catch (IOException e) { + System.err.printf("Failed to read the trace file"); + e.printStackTrace(); + System.exit(1); + return; + } } + reader.getTraceUnits().setTimeScale(TraceUnits.TimeScale.MilliSeconds); Display.setAppName("Traceview"); |