Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: runtime/bin/main.cc

Issue 10831005: Emit symbol maps for compiled code for use by the Linux perf tool. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: pre-review changes Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/process.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 17 matching lines...) Expand all
28 28
29 // Global state that stores the original working directory.. 29 // Global state that stores the original working directory..
30 static const char* original_working_directory = NULL; 30 static const char* original_working_directory = NULL;
31 31
32 32
33 // Global state that stores the import URL map specified on the 33 // Global state that stores the import URL map specified on the
34 // command line. 34 // command line.
35 static CommandLineOptions* import_map_options = NULL; 35 static CommandLineOptions* import_map_options = NULL;
36 36
37 37
38 // Global state that indicates whether perf_events symbol information
39 // is to be generated or not.
40 static File* perf_events_symbols_file = NULL;
41
42
38 // Global state that indicates whether pprof symbol information is 43 // Global state that indicates whether pprof symbol information is
39 // to be generated or not. 44 // to be generated or not.
40 static const char* generate_pprof_symbols_filename = NULL; 45 static const char* generate_pprof_symbols_filename = NULL;
41 46
42 47
43 // Global state that stores a file name for flow graph debugging output. 48 // Global state that stores a file name for flow graph debugging output.
44 // NULL if no output is generated. 49 // NULL if no output is generated.
45 static File* flow_graph_file = NULL; 50 static File* flow_graph_file = NULL;
46 51
47 // Global state that indicates whether there is a debug breakpoint. 52 // Global state that indicates whether there is a debug breakpoint.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (debug_port == 0) { 126 if (debug_port == 0) {
122 fprintf(stderr, "unrecognized --debug option syntax. " 127 fprintf(stderr, "unrecognized --debug option syntax. "
123 "Use --debug[:<port number>]\n"); 128 "Use --debug[:<port number>]\n");
124 return; 129 return;
125 } 130 }
126 breakpoint_at = "main"; 131 breakpoint_at = "main";
127 start_debugger = true; 132 start_debugger = true;
128 } 133 }
129 134
130 135
136 static void ProcessPerfEventsOption(const char* option) {
137 ASSERT(option != NULL);
138 if (perf_events_symbols_file == NULL) {
139 #if defined(TARGET_OS_LINUX)
140 const char* format = "/tmp/perf-%ld.map";
141 intptr_t pid = Process::CurrentProcessId();
142 intptr_t len = snprintf(NULL, 0, format, pid);
143 char* filename = new char[len + 1];
144 snprintf(filename, len + 1, format, pid);
145 perf_events_symbols_file = File::Open(filename, File::kWriteTruncate);
146 ASSERT(perf_events_symbols_file != NULL);
147 delete[] filename;
148 #endif
siva 2012/07/25 22:25:23 Could you abstract this away into os.h as OpenPerf
cshapiro 2012/07/25 22:52:54 I do not feel good about that as Linux is the only
siva 2012/07/25 23:19:52 Sorry I meant platform.h which is in the 'bin' dir
cshapiro 2012/07/26 00:14:19 Per our off-line conversation, I will add a TODO r
149 }
150 }
151
152
131 static void ProcessPprofOption(const char* filename) { 153 static void ProcessPprofOption(const char* filename) {
132 ASSERT(filename != NULL); 154 ASSERT(filename != NULL);
133 generate_pprof_symbols_filename = filename; 155 generate_pprof_symbols_filename = filename;
134 } 156 }
135 157
136 158
137 static void ProcessFlowGraphOption(const char* flowgraph_option) { 159 static void ProcessFlowGraphOption(const char* flowgraph_option) {
138 ASSERT(flowgraph_option != NULL); 160 ASSERT(flowgraph_option != NULL);
139 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); 161 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate);
140 ASSERT(flow_graph_file != NULL); 162 ASSERT(flow_graph_file != NULL);
141 } 163 }
142 164
143 165
144 static void ProcessImportMapOption(const char* map) { 166 static void ProcessImportMapOption(const char* map) {
145 ASSERT(map != NULL); 167 ASSERT(map != NULL);
146 import_map_options->AddArgument(map); 168 import_map_options->AddArgument(map);
147 } 169 }
148 170
149 171
150 static struct { 172 static struct {
151 const char* option_name; 173 const char* option_name;
152 void (*process)(const char* option); 174 void (*process)(const char* option);
153 } main_options[] = { 175 } main_options[] = {
154 { "--break_at=", ProcessBreakpointOption }, 176 { "--break_at=", ProcessBreakpointOption },
155 { "--compile_all", ProcessCompileAllOption }, 177 { "--compile_all", ProcessCompileAllOption },
156 { "--debug", ProcessDebugOption }, 178 { "--debug", ProcessDebugOption },
179 { "--generate_perf_events_symbols", ProcessPerfEventsOption },
157 { "--generate_pprof_symbols=", ProcessPprofOption }, 180 { "--generate_pprof_symbols=", ProcessPprofOption },
158 { "--import_map=", ProcessImportMapOption }, 181 { "--import_map=", ProcessImportMapOption },
159 { "--package-root=", ProcessPackageRootOption }, 182 { "--package-root=", ProcessPackageRootOption },
160 { "--generate_flow_graph", ProcessFlowGraphOption }, 183 { "--generate_flow_graph", ProcessFlowGraphOption },
161 { NULL, NULL } 184 { NULL, NULL }
162 }; 185 };
163 186
164 187
165 static bool ProcessMainOptions(const char* option) { 188 static bool ProcessMainOptions(const char* option) {
166 int i = 0; 189 int i = 0;
167 const char* name = main_options[0].option_name; 190 const char* name = main_options[0].option_name;
168 while (name != NULL) { 191 while (name != NULL) {
169 int length = strlen(name); 192 int length = strlen(name);
170 if (strncmp(option, name, length) == 0) { 193 if (strncmp(option, name, length) == 0) {
171 main_options[i].process(option + length); 194 main_options[i].process(option + length);
172 return true; 195 return true;
173 } 196 }
174 i += 1; 197 i += 1;
175 name = main_options[i].option_name; 198 name = main_options[i].option_name;
176 } 199 }
177 return false; 200 return false;
178 } 201 }
179 202
180 203
204 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) {
205 ASSERT(perf_events_symbols_file != NULL);
206 perf_events_symbols_file->WriteFully(buffer, num_bytes);
207 }
208
209
181 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) { 210 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) {
182 ASSERT(flow_graph_file != NULL); 211 ASSERT(flow_graph_file != NULL);
183 flow_graph_file->WriteFully(buffer, num_bytes); 212 flow_graph_file->WriteFully(buffer, num_bytes);
184 } 213 }
185 214
186 215
187 // Parse out the command line arguments. Returns -1 if the arguments 216 // Parse out the command line arguments. Returns -1 if the arguments
188 // are incorrect, 0 otherwise. 217 // are incorrect, 0 otherwise.
189 static int ParseArguments(int argc, 218 static int ParseArguments(int argc,
190 char** argv, 219 char** argv,
(...skipping 19 matching lines...) Expand all
210 const char* kPrintFlags1 = "--print-flags"; 239 const char* kPrintFlags1 = "--print-flags";
211 const char* kPrintFlags2 = "--print_flags"; 240 const char* kPrintFlags2 = "--print_flags";
212 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || 241 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) ||
213 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { 242 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) {
214 *print_flags_seen = true; 243 *print_flags_seen = true;
215 } 244 }
216 vm_options->AddArgument(argv[i]); 245 vm_options->AddArgument(argv[i]);
217 i++; 246 i++;
218 } 247 }
219 } 248 }
249
250 if (perf_events_symbols_file != NULL) {
251 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile);
252 }
253
220 if (generate_pprof_symbols_filename != NULL) { 254 if (generate_pprof_symbols_filename != NULL) {
221 Dart_InitPprofSupport(); 255 Dart_InitPprofSupport();
222 } 256 }
223 257
224 if (flow_graph_file != NULL) { 258 if (flow_graph_file != NULL) {
225 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile); 259 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile);
226 } 260 }
227 261
228 // Get the script name. 262 // Get the script name.
229 if (i < argc) { 263 if (i < argc) {
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 DumpPprofSymbolInfo(); 851 DumpPprofSymbolInfo();
818 // Shutdown the isolate. 852 // Shutdown the isolate.
819 Dart_ShutdownIsolate(); 853 Dart_ShutdownIsolate();
820 // Terminate process exit-code handler. 854 // Terminate process exit-code handler.
821 Process::TerminateExitCodeHandler(); 855 Process::TerminateExitCodeHandler();
822 856
823 free(const_cast<char*>(original_working_directory)); 857 free(const_cast<char*>(original_working_directory));
824 858
825 return 0; 859 return 0;
826 } 860 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698