~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/LaunchStapGraph.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2009 Red Hat, Inc.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 * 
 
8
 * Contributors:
 
9
 *     Red Hat - initial API and implementation
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.internal.callgraph.launch;
 
13
 
 
14
import java.io.BufferedReader;
 
15
import java.io.File;
 
16
import java.io.FileReader;
 
17
import java.io.IOException;
 
18
import java.util.ArrayList;
 
19
 
 
20
import org.eclipse.cdt.core.model.IBinary;
 
21
import org.eclipse.core.runtime.CoreException;
 
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 
23
import org.eclipse.linuxtools.internal.callgraph.core.PluginConstants;
 
24
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages;
 
25
import org.eclipse.ui.IEditorPart;
 
26
 
 
27
public class LaunchStapGraph extends SystemTapLaunchShortcut {
 
28
 
 
29
 
 
30
        //TODO: Do not let this class persist, or otherwise change it so persistence doesn't matter.
 
31
        private String partialScriptPath;
 
32
        private String funcs;
 
33
        private ArrayList<String> exclusions;
 
34
        private String projectName;
 
35
        protected static final String ATTR_PARSER = "org.eclipse.linuxtools.callgraph.graphparser"; //$NON-NLS-1$
 
36
        protected static final String ATTR_VIEWER = "org.eclipse.linuxtools.callgraph.callgraphview";  //$NON-NLS-1$
 
37
        
 
38
        
 
39
        
 
40
        public LaunchStapGraph() {
 
41
                funcs = null;
 
42
                exclusions = new ArrayList<String>();
 
43
                projectName = null;
 
44
        }
 
45
        
 
46
 
 
47
        
 
48
        public void launch(IEditorPart ed, String mode) {
 
49
                resourceToSearchFor = ed.getTitle();
 
50
                searchForResource = true;
 
51
                
 
52
                //Note: This launch will eventually end up calling 
 
53
                //launch(IBinary bin, String mode) below 
 
54
                super.launch(ed, mode);
 
55
        }
 
56
        
 
57
        public void launch(IBinary bin, String mode) {
 
58
                launch(bin, mode, null);
 
59
        }
 
60
 
 
61
        public void launch(IBinary bin, String mode, ILaunchConfigurationWorkingCopy wc) {
 
62
                super.initialize();
 
63
                this.bin = bin;
 
64
                name = "SystemTapGraph";  //$NON-NLS-1$
 
65
                binName = getName(bin);
 
66
                partialScriptPath = PluginConstants.getPluginLocation()
 
67
                                + "parse_function_partial.stp";  //$NON-NLS-1$
 
68
 
 
69
                viewID = "org.eclipse.linuxtools.callgraph.callgraphview"; //$NON-NLS-1$
 
70
                
 
71
 
 
72
                
 
73
                projectName = bin.getCProject().getElementName();
 
74
                
 
75
                try {
 
76
                        if (wc == null)
 
77
                                wc = createConfiguration(bin, name);
 
78
                        binaryPath = bin.getResource().getLocation().toString();
 
79
                        binaryPath = escapeSpecialCharacters(binaryPath);
 
80
                        arguments = binaryPath;
 
81
                        outputPath = PluginConstants.getDefaultIOPath();
 
82
                        
 
83
                        if (writeFunctionListToScript(resourceToSearchFor) == null)
 
84
                                return;
 
85
                        if (funcs == null || funcs.length() < 0)
 
86
                                return;
 
87
 
 
88
                        needToGenerate = true;
 
89
                        finishLaunch(name, mode, wc);
 
90
 
 
91
                } catch (IOException e) {
 
92
                        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(
 
93
                                        "LaunchShortcutScriptGen",  //$NON-NLS-1$
 
94
                                        Messages.getString("LaunchStapGraph.ScriptGenErr"),   //$NON-NLS-1$
 
95
                                        Messages.getString("LaunchStapGraph.ScriptGenErrMsg"));  //$NON-NLS-1$
 
96
                        mess.schedule();
 
97
                        e.printStackTrace();
 
98
                } catch (CoreException e1) {
 
99
                        e1.printStackTrace();
 
100
                } catch (Exception e) {
 
101
                        e.printStackTrace();
 
102
                } finally {
 
103
                        resourceToSearchFor = ""; //$NON-NLS-1$
 
104
                        searchForResource = false;
 
105
                }
 
106
                
 
107
                
 
108
        }
 
109
        
 
110
        public void setFuncs(String val) {
 
111
                funcs = val;
 
112
        }
 
113
        
 
114
        /**
 
115
         * Generates the call and return function probes for the specified function
 
116
         * @param function
 
117
         * @return
 
118
         */
 
119
        private String generateProbe(String function) {
 
120
                String output = "probe process(@1).function(\"" + function + "\").call ? {      if ( ! isinstr(probefunc(), \"___STAP_MARKER___\")) { callFunction(probefunc(),tid()) }         }       probe process(@1).function(\"" + function + "\").return ? {             if ( ! isinstr(probefunc(), \"___STAP_MARKER___\")) returnFunction(probefunc(),tid())   else { printf(\"?%d,,%s\\n\", tid(), user_string(strtol(tokenize($$return, \"return=\"),16)))}}\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
121
                return output;
 
122
        }
 
123
        
 
124
        /**
 
125
         * Prompts the user for a list of functions to probe
 
126
         * 
 
127
         * @param bw
 
128
         * @return
 
129
         * @throws IOException
 
130
         */
 
131
        public String writeFunctionListToScript(String resourceToSearchFor) throws IOException {
 
132
                String toWrite = getFunctionsFromBinary(bin, resourceToSearchFor);
 
133
                
 
134
                if (toWrite == null || toWrite.length() < 1) {
 
135
                        return null;
 
136
                }
 
137
                
 
138
                StringBuffer output = new StringBuffer();
 
139
                
 
140
                for (String func : toWrite.split(" ")) { //$NON-NLS-1$
 
141
                        if (func.length() > 0) {
 
142
                                if (exclusions == null || exclusions.size() < 1 || exclusions.contains(func) ) {                                        
 
143
                                        output.append(generateProbe(func));
 
144
                                }               
 
145
                        }
 
146
                }
 
147
 
 
148
                funcs = output.toString();
 
149
                return funcs;
 
150
        }
 
151
 
 
152
        /**
 
153
         * Copies the contents of the specified partial script. You should call writeStapMarkers first
 
154
         * if you want StapMarkers to function properly. 
 
155
         * 
 
156
         * @param bw
 
157
         * @return
 
158
         * @throws IOException
 
159
         */
 
160
        private String writeFromPartialScript(String projectName) throws IOException {
 
161
                String toWrite = "";  //$NON-NLS-1$
 
162
                String temp = ""; //$NON-NLS-1$
 
163
                toWrite += "\nprobe begin{\n" + //$NON-NLS-1$
 
164
                                        "printf(\"\\nPROBE_BEGIN\\n\")\n" +  //$NON-NLS-1$
 
165
                                        "serial=1\n" +  //$NON-NLS-1$
 
166
                                        "startTime = 0;\n" + //$NON-NLS-1$
 
167
                                        "printf(\"" + projectName + "\\n\")\n" + //$NON-NLS-1$ //$NON-NLS-2$
 
168
                                        "}"; //$NON-NLS-1$
 
169
                File partialScript = new File(partialScriptPath);
 
170
                BufferedReader scriptReader = new BufferedReader(new FileReader(
 
171
                                partialScript));
 
172
                while ((temp = scriptReader.readLine()) != null) {
 
173
                        toWrite += temp + "\n";  //$NON-NLS-1$
 
174
                }
 
175
                scriptReader.close();
 
176
 
 
177
                return toWrite;
 
178
        }
 
179
        
 
180
        
 
181
        public void setExclusions(ArrayList<String> e) {
 
182
                exclusions = e;
 
183
        }
 
184
 
 
185
        @Override
 
186
        public String generateScript() throws IOException {
 
187
                
 
188
                String scriptContents = "";  //$NON-NLS-1$
 
189
 
 
190
 
 
191
//              scriptContents += writeStapMarkers();
 
192
 
 
193
                scriptContents += funcs;
 
194
                
 
195
                scriptContents += writeFromPartialScript(projectName);
 
196
                
 
197
                return scriptContents;
 
198
        }
 
199
 
 
200
        public void setPartialScriptPath(String val) {
 
201
                partialScriptPath = val;
 
202
        }
 
203
 
 
204
        @Override
 
205
        public String setScriptPath() {
 
206
                scriptPath = PluginConstants.getDefaultOutput() 
 
207
                                + "callgraphGen.stp";  //$NON-NLS-1$
 
208
                return scriptPath;
 
209
        }
 
210
 
 
211
        @Override
 
212
        public String setParserID() {
 
213
                parserID = ATTR_PARSER;
 
214
                return parserID;
 
215
        }
 
216
 
 
217
        @Override
 
218
        public String setViewID() {
 
219
                return ATTR_VIEWER;
 
220
        }
 
221
        
 
222
//      /**
 
223
//       * Determines whether or not the user wants StapMarkers and inserts them. To
 
224
//       * disable StapMarkers, simply stop calling this function. This should be called
 
225
//       * before writeFromPartialScript.
 
226
//       * 
 
227
//       * @param bw
 
228
//       * @return
 
229
//       * @throws IOException
 
230
//       */
 
231
//      private String writeStapMarkers() throws IOException {
 
232
//              String toWrite = Messages.getString("LaunchStapGraph.26"); //$NON-NLS-1$
 
233
//              if (MessageDialog.openQuestion(new Shell(),
 
234
//                              Messages.getString("LaunchStapGraph.27"), //$NON-NLS-1$
 
235
//                              Messages.getString("LaunchStapGraph.28") //$NON-NLS-1$
 
236
//                                              + Messages.getString("LaunchStapGraph.29"))) { //$NON-NLS-1$
 
237
//                      toWrite = Messages.getString("LaunchStapGraph.30") //$NON-NLS-1$
 
238
//                                      + Messages.getString("LaunchStapGraph.31") //$NON-NLS-1$
 
239
//                                      + Messages.getString("LaunchStapGraph.32") //$NON-NLS-1$
 
240
//                                      + Messages.getString("LaunchStapGraph.33") //$NON-NLS-1$
 
241
//                                      + Messages.getString("LaunchStapGraph.34") //$NON-NLS-1$
 
242
//                                      + Messages.getString("LaunchStapGraph.35") //$NON-NLS-1$
 
243
//                                      + Messages.getString("LaunchStapGraph.36") //$NON-NLS-1$
 
244
//                                      + Messages.getString("LaunchStapGraph.37") //$NON-NLS-1$
 
245
//                                      + Messages.getString("LaunchStapGraph.38") //$NON-NLS-1$
 
246
//                                      + Messages.getString("LaunchStapGraph.39") + Messages.getString("LaunchStapGraph.40"); //$NON-NLS-1$ //$NON-NLS-2$
 
247
//                      partialScriptPath = PluginConstants.getPluginLocation()
 
248
//                                      + Messages.getString("LaunchStapGraph.41"); //$NON-NLS-1$
 
249
//              }
 
250
//              
 
251
//              return toWrite;
 
252
//      }
 
253
}