~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifLaunchDelegate.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *
8
8
 * Contributors:
9
9
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
10
 
 *******************************************************************************/ 
 
10
 *******************************************************************************/
11
11
package org.eclipse.linuxtools.internal.valgrind.massif;
12
12
 
13
13
import java.io.File;
30
30
import org.osgi.framework.Version;
31
31
 
32
32
public class MassifLaunchDelegate implements IValgrindLaunchDelegate {
33
 
        protected static final String OUT_PREFIX = "massif_";    //$NON-NLS-1$
34
 
        protected static final String OUT_FILE = OUT_PREFIX + "%p.txt"; //$NON-NLS-1$
35
 
        protected static final FileFilter MASSIF_FILTER = new FileFilter() {
36
 
                public boolean accept(File pathname) {
37
 
                        return pathname.getName().startsWith(OUT_PREFIX);
38
 
                }
39
 
        };
40
 
        
41
 
        private static final String EQUALS = "="; //$NON-NLS-1$
42
 
        private static final String NO = "no"; //$NON-NLS-1$
43
 
        private static final String YES = "yes"; //$NON-NLS-1$
44
 
        private static final Version VER_3_6_0 = new Version(3, 6, 0);
45
 
 
46
 
 
47
 
        protected MassifOutput output;
48
 
 
49
 
        public void handleLaunch(ILaunchConfiguration config, ILaunch launch, IPath outDir, IProgressMonitor monitor)
50
 
        throws CoreException {
51
 
                MassifPlugin.getDefault().setConfig(config);
52
 
                MassifPlugin.getDefault().setSourceLocator(launch.getSourceLocator());
53
 
                try {
54
 
                        monitor.beginTask(Messages.getString("MassifLaunchDelegate.Parsing_Massif_Output"), 3); //$NON-NLS-1$
55
 
                        
56
 
                        File[] massifOutputs = outDir.toFile().listFiles(MASSIF_FILTER);
57
 
                        
58
 
                        if (massifOutputs.length > 0) {
59
 
                                parseOutput(massifOutputs, monitor);
60
 
                        }
61
 
                } catch (IOException e) {
62
 
                        e.printStackTrace();
63
 
                        abort(Messages.getString("MassifLaunchDelegate.Error_parsing_output"), e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
64
 
                } finally {
65
 
                        monitor.done();
66
 
                }
67
 
        }
68
 
 
69
 
        protected void parseOutput(File[] massifOutputs, IProgressMonitor monitor) throws IOException {
70
 
                output = new MassifOutput();
71
 
                for (File file : massifOutputs) {
72
 
                        MassifParser parser = new MassifParser(file);
73
 
                        output.putSnapshots(parser.getPid(), parser.getSnapshots());
74
 
                }
75
 
                monitor.worked(2);
76
 
        }
77
 
 
78
 
        @SuppressWarnings("unchecked")
79
 
        public String[] getCommandArray(ILaunchConfiguration config, Version ver, IPath logDir)
80
 
        throws CoreException {
81
 
                ArrayList<String> opts = new ArrayList<String>();
82
 
 
83
 
                opts.add(MassifCommandConstants.OPT_MASSIF_OUTFILE + EQUALS + logDir.append(OUT_FILE).toOSString());
84
 
 
85
 
                opts.add(MassifCommandConstants.OPT_HEAP + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_HEAP, MassifLaunchConstants.DEFAULT_MASSIF_HEAP) ? YES : NO));
86
 
                opts.add(MassifCommandConstants.OPT_HEAPADMIN + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_HEAPADMIN, MassifLaunchConstants.DEFAULT_MASSIF_HEAPADMIN));
87
 
                opts.add(MassifCommandConstants.OPT_STACKS + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_STACKS, MassifLaunchConstants.DEFAULT_MASSIF_STACKS) ? YES : NO));
88
 
                opts.add(MassifCommandConstants.OPT_DEPTH + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_DEPTH, MassifLaunchConstants.DEFAULT_MASSIF_DEPTH));
89
 
                List<String> allocFns = config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALLOCFN, MassifLaunchConstants.DEFAULT_MASSIF_ALLOCFN);
90
 
                for (String func : allocFns) {
91
 
                        opts.add(MassifCommandConstants.OPT_ALLOCFN + EQUALS + func);
92
 
                }
93
 
                List<String> ignoreFns = config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_IGNOREFN, MassifLaunchConstants.DEFAULT_MASSIF_IGNOREFN);
94
 
                for (String func : ignoreFns) {
95
 
                        opts.add(MassifCommandConstants.OPT_IGNOREFN + EQUALS + func);
96
 
                }
97
 
                opts.add(MassifCommandConstants.OPT_THRESHOLD + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_THRESHOLD, MassifLaunchConstants.DEFAULT_MASSIF_THRESHOLD) / 10.0);
98
 
                opts.add(MassifCommandConstants.OPT_PEAKINACCURACY + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_PEAKINACCURACY, MassifLaunchConstants.DEFAULT_MASSIF_PEAKINACCURACY) / 10.0);
99
 
                opts.add(MassifCommandConstants.OPT_TIMEUNIT + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_TIMEUNIT, MassifLaunchConstants.DEFAULT_MASSIF_TIMEUNIT));
100
 
                opts.add(MassifCommandConstants.OPT_DETAILEDFREQ + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_DETAILEDFREQ, MassifLaunchConstants.DEFAULT_MASSIF_DETAILEDFREQ));
101
 
                opts.add(MassifCommandConstants.OPT_MAXSNAPSHOTS + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_MAXSNAPSHOTS, MassifLaunchConstants.DEFAULT_MASSIF_MAXSNAPSHOTS));
102
 
                if (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALIGNMENT_BOOL, MassifLaunchConstants.DEFAULT_MASSIF_ALIGNMENT_BOOL)) {
103
 
                        opts.add(MassifCommandConstants.OPT_ALIGNMENT + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALIGNMENT_VAL, MassifLaunchConstants.DEFAULT_MASSIF_ALIGNMENT_VAL));
104
 
                }
105
 
                
106
 
                // VG >= 3.6.0
107
 
                if (ver == null || ver.compareTo(VER_3_6_0) >= 0) {
108
 
                        opts.add(MassifCommandConstants.OPT_PAGESASHEAP + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_PAGESASHEAP, MassifLaunchConstants.DEFAULT_MASSIF_PAGESASHEAP) ? YES : NO));
109
 
                }
110
 
 
111
 
                return opts.toArray(new String[opts.size()]);
112
 
        }
113
 
        
114
 
        public void initializeView(IValgrindToolView view, String contentDescription, IProgressMonitor monitor) throws CoreException {
115
 
                if (output != null && view instanceof MassifViewPart) {
116
 
                        ((MassifViewPart) view).setChartName(contentDescription);
117
 
                        ((MassifViewPart) view).setOutput(output);
118
 
                        // initialize to first pid
119
 
                        ((MassifViewPart) view).setPid(output.getPids()[0]);
120
 
                }
121
 
                monitor.worked(1);
122
 
        }
123
 
 
124
 
        /**
125
 
         * Throws a core exception with an error status object built from the given
126
 
         * message, lower level exception, and error code.
127
 
         * 
128
 
         * @param message
129
 
         *            the status message
130
 
         * @param exception
131
 
         *            lower level exception associated with the error, or
132
 
         *            <code>null</code> if none
133
 
         * @param code
134
 
         *            error code
135
 
         */
136
 
        private void abort(String message, Throwable exception, int code) throws CoreException {
137
 
                IStatus status;
138
 
                if (exception != null) {
139
 
                        MultiStatus multiStatus = new MultiStatus(MassifPlugin.PLUGIN_ID, code, message, exception);
140
 
                        multiStatus.add(new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, exception.getLocalizedMessage(), exception));
141
 
                        status= multiStatus;
142
 
                } else {
143
 
                        status= new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, message, null);
144
 
                }
145
 
                throw new CoreException(status);
146
 
        }
 
33
    protected static final String OUT_PREFIX = "massif_";     //$NON-NLS-1$
 
34
    protected static final String OUT_FILE = OUT_PREFIX + "%p.txt"; //$NON-NLS-1$
 
35
    private static final FileFilter MASSIF_FILTER = new FileFilter() {
 
36
        @Override
 
37
        public boolean accept(File pathname) {
 
38
            return pathname.getName().startsWith(OUT_PREFIX);
 
39
        }
 
40
    };
 
41
 
 
42
    private static final String EQUALS = "="; //$NON-NLS-1$
 
43
    private static final String NO = "no"; //$NON-NLS-1$
 
44
    private static final String YES = "yes"; //$NON-NLS-1$
 
45
    private static final Version VER_3_6_0 = new Version(3, 6, 0);
 
46
 
 
47
 
 
48
    private MassifOutput output;
 
49
 
 
50
    @Override
 
51
    public void handleLaunch(ILaunchConfiguration config, ILaunch launch, IPath outDir, IProgressMonitor monitor)
 
52
    throws CoreException {
 
53
        MassifPlugin.getDefault().setSourceLocator(launch.getSourceLocator());
 
54
        try {
 
55
            monitor.beginTask(Messages.getString("MassifLaunchDelegate.Parsing_Massif_Output"), 3); //$NON-NLS-1$
 
56
 
 
57
            File[] massifOutputs = outDir.toFile().listFiles(MASSIF_FILTER);
 
58
 
 
59
            if (massifOutputs.length > 0) {
 
60
                parseOutput(massifOutputs, monitor);
 
61
            }
 
62
        } catch (IOException e) {
 
63
            e.printStackTrace();
 
64
            abort(Messages.getString("MassifLaunchDelegate.Error_parsing_output"), e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
 
65
        } finally {
 
66
            monitor.done();
 
67
        }
 
68
    }
 
69
 
 
70
    private void parseOutput(File[] massifOutputs, IProgressMonitor monitor) throws IOException {
 
71
        output = new MassifOutput();
 
72
        for (File file : massifOutputs) {
 
73
            MassifParser parser = new MassifParser(file);
 
74
            output.putSnapshots(parser.getPid(), parser.getSnapshots());
 
75
        }
 
76
        monitor.worked(2);
 
77
    }
 
78
 
 
79
    @Override
 
80
    public String[] getCommandArray(ILaunchConfiguration config, Version ver, IPath logDir)
 
81
    throws CoreException {
 
82
        ArrayList<String> opts = new ArrayList<>();
 
83
 
 
84
        opts.add(MassifCommandConstants.OPT_MASSIF_OUTFILE + EQUALS + logDir.append(OUT_FILE).toOSString());
 
85
 
 
86
        opts.add(MassifCommandConstants.OPT_HEAP + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_HEAP, MassifLaunchConstants.DEFAULT_MASSIF_HEAP) ? YES : NO));
 
87
        opts.add(MassifCommandConstants.OPT_HEAPADMIN + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_HEAPADMIN, MassifLaunchConstants.DEFAULT_MASSIF_HEAPADMIN));
 
88
        opts.add(MassifCommandConstants.OPT_STACKS + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_STACKS, MassifLaunchConstants.DEFAULT_MASSIF_STACKS) ? YES : NO));
 
89
        opts.add(MassifCommandConstants.OPT_DEPTH + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_DEPTH, MassifLaunchConstants.DEFAULT_MASSIF_DEPTH));
 
90
        List<String> allocFns = config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALLOCFN, MassifLaunchConstants.DEFAULT_MASSIF_ALLOCFN);
 
91
        for (String func : allocFns) {
 
92
            opts.add(MassifCommandConstants.OPT_ALLOCFN + EQUALS + func);
 
93
        }
 
94
        List<String> ignoreFns = config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_IGNOREFN, MassifLaunchConstants.DEFAULT_MASSIF_IGNOREFN);
 
95
        for (String func : ignoreFns) {
 
96
            opts.add(MassifCommandConstants.OPT_IGNOREFN + EQUALS + func);
 
97
        }
 
98
        opts.add(MassifCommandConstants.OPT_THRESHOLD + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_THRESHOLD, MassifLaunchConstants.DEFAULT_MASSIF_THRESHOLD) / 10.0);
 
99
        opts.add(MassifCommandConstants.OPT_PEAKINACCURACY + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_PEAKINACCURACY, MassifLaunchConstants.DEFAULT_MASSIF_PEAKINACCURACY) / 10.0);
 
100
        opts.add(MassifCommandConstants.OPT_TIMEUNIT + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_TIMEUNIT, MassifLaunchConstants.DEFAULT_MASSIF_TIMEUNIT));
 
101
        opts.add(MassifCommandConstants.OPT_DETAILEDFREQ + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_DETAILEDFREQ, MassifLaunchConstants.DEFAULT_MASSIF_DETAILEDFREQ));
 
102
        opts.add(MassifCommandConstants.OPT_MAXSNAPSHOTS + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_MAXSNAPSHOTS, MassifLaunchConstants.DEFAULT_MASSIF_MAXSNAPSHOTS));
 
103
        if (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALIGNMENT_BOOL, MassifLaunchConstants.DEFAULT_MASSIF_ALIGNMENT_BOOL)) {
 
104
            opts.add(MassifCommandConstants.OPT_ALIGNMENT + EQUALS + config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_ALIGNMENT_VAL, MassifLaunchConstants.DEFAULT_MASSIF_ALIGNMENT_VAL));
 
105
        }
 
106
 
 
107
        // VG >= 3.6.0
 
108
        if (ver == null || ver.compareTo(VER_3_6_0) >= 0) {
 
109
            opts.add(MassifCommandConstants.OPT_PAGESASHEAP + EQUALS + (config.getAttribute(MassifLaunchConstants.ATTR_MASSIF_PAGESASHEAP, MassifLaunchConstants.DEFAULT_MASSIF_PAGESASHEAP) ? YES : NO));
 
110
        }
 
111
 
 
112
        return opts.toArray(new String[opts.size()]);
 
113
    }
 
114
 
 
115
    @Override
 
116
    public void initializeView(IValgrindToolView view, String contentDescription, IProgressMonitor monitor) {
 
117
        if (output != null && view instanceof MassifViewPart) {
 
118
            ((MassifViewPart) view).setChartName(contentDescription);
 
119
            ((MassifViewPart) view).setOutput(output);
 
120
            // initialize to first pid
 
121
            ((MassifViewPart) view).setPid(output.getPids()[0]);
 
122
        }
 
123
        monitor.worked(1);
 
124
    }
 
125
 
 
126
    /**
 
127
     * Throws a core exception with an error status object built from the given
 
128
     * message, lower level exception, and error code.
 
129
     *
 
130
     * @param message
 
131
     *            the status message
 
132
     * @param exception
 
133
     *            lower level exception associated with the error, or
 
134
     *            <code>null</code> if none
 
135
     * @param code
 
136
     *            error code
 
137
     */
 
138
    private void abort(String message, Throwable exception, int code) throws CoreException {
 
139
        IStatus status;
 
140
        if (exception != null) {
 
141
            MultiStatus multiStatus = new MultiStatus(MassifPlugin.PLUGIN_ID, code, message, exception);
 
142
            multiStatus.add(new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, exception.getLocalizedMessage(), exception));
 
143
            status= multiStatus;
 
144
        } else {
 
145
            status= new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, message, null);
 
146
        }
 
147
        throw new CoreException(status);
 
148
    }
147
149
}