30
30
import org.osgi.framework.Version;
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);
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);
47
protected MassifOutput output;
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());
54
monitor.beginTask(Messages.getString("MassifLaunchDelegate.Parsing_Massif_Output"), 3); //$NON-NLS-1$
56
File[] massifOutputs = outDir.toFile().listFiles(MASSIF_FILTER);
58
if (massifOutputs.length > 0) {
59
parseOutput(massifOutputs, monitor);
61
} catch (IOException e) {
63
abort(Messages.getString("MassifLaunchDelegate.Error_parsing_output"), e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
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());
78
@SuppressWarnings("unchecked")
79
public String[] getCommandArray(ILaunchConfiguration config, Version ver, IPath logDir)
80
throws CoreException {
81
ArrayList<String> opts = new ArrayList<String>();
83
opts.add(MassifCommandConstants.OPT_MASSIF_OUTFILE + EQUALS + logDir.append(OUT_FILE).toOSString());
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);
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);
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));
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));
111
return opts.toArray(new String[opts.size()]);
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]);
125
* Throws a core exception with an error status object built from the given
126
* message, lower level exception, and error code.
131
* lower level exception associated with the error, or
132
* <code>null</code> if none
136
private void abort(String message, Throwable exception, int code) throws CoreException {
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));
143
status= new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, message, null);
145
throw new CoreException(status);
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() {
37
public boolean accept(File pathname) {
38
return pathname.getName().startsWith(OUT_PREFIX);
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);
48
private MassifOutput output;
51
public void handleLaunch(ILaunchConfiguration config, ILaunch launch, IPath outDir, IProgressMonitor monitor)
52
throws CoreException {
53
MassifPlugin.getDefault().setSourceLocator(launch.getSourceLocator());
55
monitor.beginTask(Messages.getString("MassifLaunchDelegate.Parsing_Massif_Output"), 3); //$NON-NLS-1$
57
File[] massifOutputs = outDir.toFile().listFiles(MASSIF_FILTER);
59
if (massifOutputs.length > 0) {
60
parseOutput(massifOutputs, monitor);
62
} catch (IOException e) {
64
abort(Messages.getString("MassifLaunchDelegate.Error_parsing_output"), e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
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());
80
public String[] getCommandArray(ILaunchConfiguration config, Version ver, IPath logDir)
81
throws CoreException {
82
ArrayList<String> opts = new ArrayList<>();
84
opts.add(MassifCommandConstants.OPT_MASSIF_OUTFILE + EQUALS + logDir.append(OUT_FILE).toOSString());
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);
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);
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));
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));
112
return opts.toArray(new String[opts.size()]);
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]);
127
* Throws a core exception with an error status object built from the given
128
* message, lower level exception, and error code.
133
* lower level exception associated with the error, or
134
* <code>null</code> if none
138
private void abort(String message, Throwable exception, int code) throws CoreException {
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));
145
status= new Status(IStatus.ERROR, MassifPlugin.PLUGIN_ID, code, message, null);
147
throw new CoreException(status);