Search in sources :

Example 6 with IBinaryObject

use of org.eclipse.cdt.core.IBinaryParser.IBinaryObject in project linuxtools by eclipse.

the class GmonView method displayGprofView.

/**
 * Display gmon results in the GProf View. NOTE: this method has to be called from within the UI thread.
 *
 * @param binaryPath
 * @param gmonPath
 * @param instanceName
 */
public static GmonView displayGprofView(String binaryPath, String gmonPath, IProject project) {
    IBinaryObject binary = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryPath));
    if (binary == null) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        PlatformUI.getWorkbench().getDisplay().getActiveShell(), // $NON-NLS-1$
        "Invalid binary file", // $NON-NLS-1$
        binaryPath + " is not a valid binary file.");
        return null;
    } else if (binary.getCPU().equals("ppc64") && !binary.isLittleEndian()) {
        // $NON-NLS-1$
        binary = new PPC64ElfBinaryObjectWrapper(binary.getBinaryParser(), binary.getPath(), binary.getType());
    }
    GmonDecoder decoder = new GmonDecoder(binary, project);
    try {
        decoder.read(gmonPath);
    } catch (IOException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
    }
    return displayGprofView(decoder, gmonPath);
}
Also used : Path(org.eclipse.core.runtime.Path) PPC64ElfBinaryObjectWrapper(org.eclipse.linuxtools.internal.gprof.utils.PPC64ElfBinaryObjectWrapper) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) GmonDecoder(org.eclipse.linuxtools.internal.gprof.parser.GmonDecoder) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) IOException(java.io.IOException)

Example 7 with IBinaryObject

use of org.eclipse.cdt.core.IBinaryParser.IBinaryObject in project linuxtools by eclipse.

the class GmonViewer method handleOpenEvent.

@Override
protected void handleOpenEvent(OpenEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    TreeElement element = (TreeElement) selection.getFirstElement();
    if (element != null) {
        String s = element.getSourcePath();
        if (s == null || "??".equals(s)) {
            // nothing to do here.
            return;
        } else {
            int lineNumber = element.getSourceLine();
            IBinaryObject exec = ((HistRoot) element.getRoot()).decoder.getProgram();
            STLink2SourceSupport.openSourceFileAtLocation(exec, s, lineNumber);
        }
    }
}
Also used : IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeElement(org.eclipse.linuxtools.internal.gprof.view.histogram.TreeElement)

Example 8 with IBinaryObject

use of org.eclipse.cdt.core.IBinaryParser.IBinaryObject in project linuxtools by eclipse.

the class CovManager method getGCDALocations.

/**
 * Retrieve a list containing gcda paths from a binary file
 * @return
 * @throws InterruptedException
 */
public List<String> getGCDALocations() throws InterruptedException {
    IBinaryObject binaryObject = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryPath));
    String binaryPath = binaryObject.getPath().toOSString();
    STStrings strings = STSymbolManager.sharedInstance.getStrings(binaryObject, project);
    List<String> l = new LinkedList<>();
    Process p;
    p = getStringsProcess(strings.getName(), strings.getArgs(), binaryPath);
    if (p == null) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.CovManager_Retrieval_Error, new IOException());
        Activator.getDefault().getLog().log(status);
        return l;
    }
    ThreadConsumer t = new ThreadConsumer(p, l);
    t.start();
    p.waitFor();
    t.join();
    return l;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) STStrings(org.eclipse.linuxtools.binutils.utils.STStrings) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 9 with IBinaryObject

use of org.eclipse.cdt.core.IBinaryParser.IBinaryObject in project linuxtools by eclipse.

the class GprofTest method data.

@Parameters
public static Collection<Object[]> data() {
    List<Object[]> params = new ArrayList<>();
    boolean addr2line2_16 = false;
    try {
        Process p = Runtime.getRuntime().exec("addr2line --version");
        InputStream is = p.getInputStream();
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.contains("addr2line 2.16.")) {
                addr2line2_16 = true;
                break;
            }
        }
    } catch (IOException e) {
    }
    for (File testDir : STJunitUtils.getTestDirs()) {
        final File gmonFile = new File(testDir, OUTPUT_FILE);
        final File binaryFile = new File(testDir, BINARY_FILE);
        File view_cg_RefFile_default = new File(testDir, "testCallgraphView.ref");
        File view_cg_RefFile_alternate = new File(testDir, "testCallgraphView.ref.binutils-2.16");
        File view_cg2_RefFile_default = new File(testDir, "testCallgraphTimeView.ref");
        File view_cg2_RefFile_alternate = new File(testDir, "testCallgraphTimeView.ref.binutils-2.16");
        final File view_cg_RefFile;
        final File view_cg2_RefFile;
        if (addr2line2_16 && view_cg_RefFile_alternate.exists()) {
            view_cg_RefFile = view_cg_RefFile_alternate;
        } else {
            view_cg_RefFile = view_cg_RefFile_default;
        }
        if (addr2line2_16 && view_cg2_RefFile_alternate.exists()) {
            view_cg2_RefFile = view_cg2_RefFile_alternate;
        } else {
            view_cg2_RefFile = view_cg2_RefFile_default;
        }
        final File view_cg2_DumpFile = new File(testDir, "testCallgraphTimeView.dump");
        final File view_cg_DumpFile = new File(testDir, "testCallgraphView.dump");
        final File view_samplesFile_RefFile = new File(testDir, "testSampleView.ref");
        final File view_samplesFile_DumpFile = new File(testDir, "testSampleView.dump");
        final File view_samplesFileT_RefFile = new File(testDir, "testTimeView.ref");
        final File view_samplesFileT_DumpFile = new File(testDir, "testTimeView.dump");
        final File view_samplesFunction_RefFile = new File(testDir, "testFunctionSampleView.ref");
        final File view_samplesFunction_DumpFile = new File(testDir, "testFunctionSampleView.dump");
        final File view_samplesFunctionT_RefFile = new File(testDir, "testFunctionTimeView.ref");
        final File view_samplesFunctionT_DumpFile = new File(testDir, "testFunctionTimeView.dump");
        final File view_samplesFlat_RefFile = new File(testDir, "testFlatSampleView.ref");
        final File view_samplesFlat_DumpFile = new File(testDir, "testFlatSampleView.dump");
        final File view_samplesFlatT_RefFile = new File(testDir, "testFlatTimeView.ref");
        final File view_samplesFlatT_DumpFile = new File(testDir, "testFlatTimeView.dump");
        IBinaryObject binary = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryFile.getAbsolutePath()));
        final GmonDecoder gd = new GmonDecoder(binary, null);
        try {
            gd.read(gmonFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        params.add(new Object[] { gmonFile, gd, view_cg_RefFile, view_cg_DumpFile, CallGraphContentProvider.sharedInstance, false });
        params.add(new Object[] { gmonFile, gd, view_cg2_RefFile, view_cg2_DumpFile, CallGraphContentProvider.sharedInstance, true });
        params.add(new Object[] { gmonFile, gd, view_samplesFile_RefFile, view_samplesFile_DumpFile, FileHistogramContentProvider.sharedInstance, false });
        params.add(new Object[] { gmonFile, gd, view_samplesFileT_RefFile, view_samplesFileT_DumpFile, FileHistogramContentProvider.sharedInstance, true });
        params.add(new Object[] { gmonFile, gd, view_samplesFunction_RefFile, view_samplesFunction_DumpFile, FunctionHistogramContentProvider.sharedInstance, false });
        params.add(new Object[] { gmonFile, gd, view_samplesFunctionT_RefFile, view_samplesFunctionT_DumpFile, FunctionHistogramContentProvider.sharedInstance, true });
        params.add(new Object[] { gmonFile, gd, view_samplesFlat_RefFile, view_samplesFlat_DumpFile, FlatHistogramContentProvider.sharedInstance, false });
        params.add(new Object[] { gmonFile, gd, view_samplesFlatT_RefFile, view_samplesFlatT_DumpFile, FlatHistogramContentProvider.sharedInstance, true });
    }
    return params;
}
Also used : Path(org.eclipse.core.runtime.Path) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader) GmonDecoder(org.eclipse.linuxtools.internal.gprof.parser.GmonDecoder) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) File(java.io.File) Parameters(org.junit.runners.Parameterized.Parameters)

Example 10 with IBinaryObject

use of org.eclipse.cdt.core.IBinaryParser.IBinaryObject in project linuxtools by eclipse.

the class CallGraphDecoder method decodeCallGraphRecord.

/**
 * Decode call-graph record from gmon file.
 * @param stream
 * @throws IOException
 */
public void decodeCallGraphRecord(DataInput stream, boolean bsdFormat) throws IOException {
    long from_pc = readAddress(stream);
    long self_pc = readAddress(stream);
    int count = bsdFormat ? (int) readAddress(stream) : stream.readInt();
    IBinaryObject program = decoder.getProgram();
    IAddressFactory addressFactory = program.getAddressFactory();
    IAddress parentAddress = addressFactory.createAddress(Long.toString(from_pc));
    ISymbol parentSymbol = program.getSymbol(parentAddress);
    IAddress childAddress = addressFactory.createAddress(Long.toString(self_pc));
    ISymbol childSymbol = program.getSymbol(childAddress);
    if (childSymbol == null || parentSymbol == null) {
        return;
    }
    addCallArc(parentSymbol, parentAddress, childSymbol, count);
}
Also used : IAddressFactory(org.eclipse.cdt.core.IAddressFactory) ISymbol(org.eclipse.cdt.core.IBinaryParser.ISymbol) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) IAddress(org.eclipse.cdt.core.IAddress)

Aggregations

IBinaryObject (org.eclipse.cdt.core.IBinaryParser.IBinaryObject)12 Path (org.eclipse.core.runtime.Path)5 IOException (java.io.IOException)3 IAddress (org.eclipse.cdt.core.IAddress)3 IPath (org.eclipse.core.runtime.IPath)3 GmonDecoder (org.eclipse.linuxtools.internal.gprof.parser.GmonDecoder)3 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 IAddressFactory (org.eclipse.cdt.core.IAddressFactory)1 IBinaryParser (org.eclipse.cdt.core.IBinaryParser)1 ISymbol (org.eclipse.cdt.core.IBinaryParser.ISymbol)1