Search in sources :

Example 1 with PMEvent

use of org.eclipse.linuxtools.internal.perf.model.PMEvent in project linuxtools by eclipse.

the class PerfCore method parseRemoteReport.

private static void parseRemoteReport(ILaunchConfiguration config, IPath workingDir, IProgressMonitor monitor, String perfDataLoc, PrintStream print, TreeParent invisibleRoot, boolean oldPerfVersion, BufferedReader input, BufferedReader error, IProject project) {
    if (monitor != null && monitor.isCanceled()) {
        return;
    }
    String line = null;
    String[] items;
    float percent;
    Process p = null;
    double samples;
    String comm, dso, symbol;
    boolean kernelFlag;
    PMEvent currentEvent = null;
    PMCommand currentCommand = null;
    PMDso currentDso = null;
    PMFile currentFile = null;
    PMSymbol currentSym = null;
    try {
        while ((line = input.readLine()) != null) {
            if (monitor != null && monitor.isCanceled()) {
                return;
            }
            // line containing report information
            if ((line.startsWith("#"))) {
                // $NON-NLS-1$
                if (line.contains("Events:") || line.contains("Samples:")) {
                    // ignore lost samples as the plugin has no logic for handling them
                    if (line.startsWith("# Total Lost Samples:")) {
                        // $NON-NLS-1$
                        continue;
                    }
                    // $NON-NLS-1$
                    String[] tmp = line.trim().split(" ");
                    String event = tmp[tmp.length - 1];
                    // In this case, the event name is single quoted
                    if (line.contains("Samples:")) {
                        // $NON-NLS-1$
                        event = event.substring(1, event.length() - 1);
                    }
                    currentEvent = new PMEvent(event);
                    invisibleRoot.addChild(currentEvent);
                    currentCommand = null;
                    currentDso = null;
                } else if (line.contains("Samples:")) {
                    // $NON-NLS-1$
                    if (print != null) {
                        print.println("WARNING: You are running an older version of Perf, please update if you can. The plugin may produce unpredictable results.");
                    }
                    // $NON-NLS-1$
                    invisibleRoot.addChild(new PMEvent("WARNING: You are running an older version of Perf, the plugin may produce unpredictable results."));
                }
            // contains profiled information
            } else {
                // using custom field separator. for default whitespace use " +" //$NON-NLS-1$
                items = line.trim().split("" + (char) 1);
                if (items.length != 5) {
                    continue;
                }
                // $NON-NLS-1$ //$NON-NLS-2$
                percent = Float.parseFloat(items[0].replace("%", ""));
                // samples column
                samples = Double.parseDouble(items[1].trim());
                // command column
                comm = items[2].trim();
                // dso column
                dso = items[3].trim();
                // symbol column
                symbol = items[4].trim();
                // $NON-NLS-1$ //$NON-NLS-2$
                kernelFlag = ("" + symbol.charAt(1)).equals("k");
                // initialize current command if it doesn't exist
                if ((currentCommand == null) || (!currentCommand.getName().equals(comm))) {
                    currentCommand = (PMCommand) currentEvent.getChild(comm);
                    if (currentCommand == null) {
                        currentCommand = new PMCommand(comm);
                        currentEvent.addChild(currentCommand);
                    }
                }
                // initialize current dso if it doesn't exist
                if ((currentDso == null) || (!currentDso.getName().equals(dso))) {
                    currentDso = (PMDso) currentCommand.getChild(dso);
                    if (currentDso == null) {
                        currentDso = new PMDso(dso, kernelFlag);
                        currentCommand.addChild(currentDso);
                    }
                }
                /*
                     *  Initialize the current file, and symbol
                     *
                     *  We won't know the name of the file containing the symbol
                     *  until we run 'perf annotate' to resolve it, so for now we
                     *  attach all symbols as children of 'Unfiled Symbols'.
                     */
                currentFile = currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols);
                currentSym = new PMSymbol(symbol, percent, samples);
                currentFile.addChild(currentSym);
            }
        }
    } catch (IOException e) {
        logException(e);
    }
    // $NON-NLS-1$
    spitStream(error, "Perf Report", print);
    boolean SourceLineNumbers = PerfPlugin.ATTR_SourceLineNumbers_default;
    boolean Kernel_SourceLineNumbers = PerfPlugin.ATTR_Kernel_SourceLineNumbers_default;
    try {
        // Check if resolving source file/line numbers is selected
        SourceLineNumbers = config.getAttribute(PerfPlugin.ATTR_SourceLineNumbers, PerfPlugin.ATTR_SourceLineNumbers_default);
        Kernel_SourceLineNumbers = config.getAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, PerfPlugin.ATTR_Kernel_SourceLineNumbers_default);
    } catch (CoreException e2) {
        SourceLineNumbers = false;
    }
    if (monitor != null && monitor.isCanceled()) {
        return;
    }
    boolean hasProfileData = invisibleRoot.getChildren().length != 0;
    if (SourceLineNumbers) {
        for (TreeParent ev : invisibleRoot.getChildren()) {
            if (!(ev instanceof PMEvent))
                continue;
            for (TreeParent cmd : ev.getChildren()) {
                if (!(cmd instanceof PMCommand))
                    continue;
                for (TreeParent d : cmd.getChildren()) {
                    if (!(d instanceof PMDso))
                        continue;
                    currentDso = (PMDso) d;
                    if ((!Kernel_SourceLineNumbers) && currentDso.isKernelDso())
                        continue;
                    for (TreeParent s : currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols).getChildren()) {
                        if (!(s instanceof PMSymbol))
                            continue;
                        if (monitor != null && monitor.isCanceled()) {
                            return;
                        }
                        currentSym = (PMSymbol) s;
                        String[] annotateCmd;
                        if (workingDir == null) {
                            annotateCmd = getAnnotateString(config, currentDso.getName(), currentSym.getName().substring(4), perfDataLoc, oldPerfVersion);
                        } else {
                            // $NON-NLS-1$
                            String perfDefaultDataLoc = workingDir + "/" + PerfPlugin.PERF_DEFAULT_DATA;
                            annotateCmd = getAnnotateString(config, currentDso.getName(), currentSym.getName().substring(4), perfDefaultDataLoc, oldPerfVersion);
                        }
                        try {
                            if (project == null) {
                                p = Runtime.getRuntime().exec(annotateCmd);
                            } else {
                                StringBuffer sb = new StringBuffer();
                                ArrayList<String> al = new ArrayList<>();
                                /*
                                     *  Wrap the whole Perf annotate line as a single argument of sh command
                                     *   so that any IO redirection will take effect. Change to working directory before run perf annotate.
                                     *  It results on a command string as 'sh', '-c', 'cd <workindir> && perf annotate <args> < /dev/null'
                                     */
                                // $NON-NLS-1$
                                al.add("sh");
                                // $NON-NLS-1$
                                al.add("-c");
                                if (workingDir != null) {
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    sb.append("cd " + workingDir.toOSString() + " && ");
                                }
                                for (int i = 0; i < annotateCmd.length; i++) {
                                    sb.append(annotateCmd[i]);
                                    // $NON-NLS-1$
                                    sb.append(" ");
                                }
                                al.add(sb.toString());
                                p = RuntimeProcessFactory.getFactory().exec(al.toArray(new String[] {}), project);
                            }
                            input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                            error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                        } catch (IOException e) {
                            logException(e);
                        }
                        PerfCore.parseAnnotation(monitor, input, workingDir, currentDso, currentSym);
                    }
                    if (currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols).getChildren().length == 0) {
                        currentDso.removeChild(currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols));
                    }
                    // $NON-NLS-1$
                    spitStream(error, "Perf Annotate", print);
                }
            }
        }
    }
    if (print != null) {
        if (hasProfileData) {
            // $NON-NLS-1$
            print.println("Profile data loaded into Perf Profile View.");
        } else {
            // $NON-NLS-1$
            print.println("No profile data generated to be displayed.");
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) PMEvent(org.eclipse.linuxtools.internal.perf.model.PMEvent) TreeParent(org.eclipse.linuxtools.internal.perf.model.TreeParent) PMDso(org.eclipse.linuxtools.internal.perf.model.PMDso) ArrayList(java.util.ArrayList) PMSymbol(org.eclipse.linuxtools.internal.perf.model.PMSymbol) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) PMCommand(org.eclipse.linuxtools.internal.perf.model.PMCommand) BufferedReader(java.io.BufferedReader) PMFile(org.eclipse.linuxtools.internal.perf.model.PMFile)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 PMCommand (org.eclipse.linuxtools.internal.perf.model.PMCommand)1 PMDso (org.eclipse.linuxtools.internal.perf.model.PMDso)1 PMEvent (org.eclipse.linuxtools.internal.perf.model.PMEvent)1 PMFile (org.eclipse.linuxtools.internal.perf.model.PMFile)1 PMSymbol (org.eclipse.linuxtools.internal.perf.model.PMSymbol)1 TreeParent (org.eclipse.linuxtools.internal.perf.model.TreeParent)1