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

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: address review comments 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 // TODO(cshapiro): eliminate the #ifdef by moving this code to a
140 // Linux specific source file.
141 #if defined(TARGET_OS_LINUX)
142 const char* format = "/tmp/perf-%ld.map";
143 intptr_t pid = Process::CurrentProcessId();
144 intptr_t len = snprintf(NULL, 0, format, pid);
145 char* filename = new char[len + 1];
146 snprintf(filename, len + 1, format, pid);
147 perf_events_symbols_file = File::Open(filename, File::kWriteTruncate);
148 ASSERT(perf_events_symbols_file != NULL);
149 delete[] filename;
150 #endif
151 }
152 }
153
154
131 static void ProcessPprofOption(const char* filename) { 155 static void ProcessPprofOption(const char* filename) {
132 ASSERT(filename != NULL); 156 ASSERT(filename != NULL);
133 generate_pprof_symbols_filename = filename; 157 generate_pprof_symbols_filename = filename;
134 } 158 }
135 159
136 160
137 static void ProcessFlowGraphOption(const char* flowgraph_option) { 161 static void ProcessFlowGraphOption(const char* flowgraph_option) {
138 ASSERT(flowgraph_option != NULL); 162 ASSERT(flowgraph_option != NULL);
139 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); 163 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate);
140 ASSERT(flow_graph_file != NULL); 164 ASSERT(flow_graph_file != NULL);
141 } 165 }
142 166
143 167
144 static void ProcessImportMapOption(const char* map) { 168 static void ProcessImportMapOption(const char* map) {
145 ASSERT(map != NULL); 169 ASSERT(map != NULL);
146 import_map_options->AddArgument(map); 170 import_map_options->AddArgument(map);
147 } 171 }
148 172
149 173
150 static struct { 174 static struct {
151 const char* option_name; 175 const char* option_name;
152 void (*process)(const char* option); 176 void (*process)(const char* option);
153 } main_options[] = { 177 } main_options[] = {
154 { "--break_at=", ProcessBreakpointOption }, 178 { "--break_at=", ProcessBreakpointOption },
155 { "--compile_all", ProcessCompileAllOption }, 179 { "--compile_all", ProcessCompileAllOption },
156 { "--debug", ProcessDebugOption }, 180 { "--debug", ProcessDebugOption },
181 { "--generate_perf_events_symbols", ProcessPerfEventsOption },
157 { "--generate_pprof_symbols=", ProcessPprofOption }, 182 { "--generate_pprof_symbols=", ProcessPprofOption },
158 { "--import_map=", ProcessImportMapOption }, 183 { "--import_map=", ProcessImportMapOption },
159 { "--package-root=", ProcessPackageRootOption }, 184 { "--package-root=", ProcessPackageRootOption },
160 { "--generate_flow_graph", ProcessFlowGraphOption }, 185 { "--generate_flow_graph", ProcessFlowGraphOption },
161 { NULL, NULL } 186 { NULL, NULL }
162 }; 187 };
163 188
164 189
165 static bool ProcessMainOptions(const char* option) { 190 static bool ProcessMainOptions(const char* option) {
166 int i = 0; 191 int i = 0;
167 const char* name = main_options[0].option_name; 192 const char* name = main_options[0].option_name;
168 while (name != NULL) { 193 while (name != NULL) {
169 int length = strlen(name); 194 int length = strlen(name);
170 if (strncmp(option, name, length) == 0) { 195 if (strncmp(option, name, length) == 0) {
171 main_options[i].process(option + length); 196 main_options[i].process(option + length);
172 return true; 197 return true;
173 } 198 }
174 i += 1; 199 i += 1;
175 name = main_options[i].option_name; 200 name = main_options[i].option_name;
176 } 201 }
177 return false; 202 return false;
178 } 203 }
179 204
180 205
206 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) {
207 ASSERT(perf_events_symbols_file != NULL);
208 perf_events_symbols_file->WriteFully(buffer, num_bytes);
209 }
210
211
181 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) { 212 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) {
182 ASSERT(flow_graph_file != NULL); 213 ASSERT(flow_graph_file != NULL);
183 flow_graph_file->WriteFully(buffer, num_bytes); 214 flow_graph_file->WriteFully(buffer, num_bytes);
184 } 215 }
185 216
186 217
187 // Parse out the command line arguments. Returns -1 if the arguments 218 // Parse out the command line arguments. Returns -1 if the arguments
188 // are incorrect, 0 otherwise. 219 // are incorrect, 0 otherwise.
189 static int ParseArguments(int argc, 220 static int ParseArguments(int argc,
190 char** argv, 221 char** argv,
(...skipping 19 matching lines...) Expand all
210 const char* kPrintFlags1 = "--print-flags"; 241 const char* kPrintFlags1 = "--print-flags";
211 const char* kPrintFlags2 = "--print_flags"; 242 const char* kPrintFlags2 = "--print_flags";
212 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || 243 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) ||
213 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { 244 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) {
214 *print_flags_seen = true; 245 *print_flags_seen = true;
215 } 246 }
216 vm_options->AddArgument(argv[i]); 247 vm_options->AddArgument(argv[i]);
217 i++; 248 i++;
218 } 249 }
219 } 250 }
251
252 if (perf_events_symbols_file != NULL) {
253 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile);
254 }
255
220 if (generate_pprof_symbols_filename != NULL) { 256 if (generate_pprof_symbols_filename != NULL) {
221 Dart_InitPprofSupport(); 257 Dart_InitPprofSupport();
222 } 258 }
223 259
224 if (flow_graph_file != NULL) { 260 if (flow_graph_file != NULL) {
225 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile); 261 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile);
226 } 262 }
227 263
228 // Get the script name. 264 // Get the script name.
229 if (i < argc) { 265 if (i < argc) {
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 DumpPprofSymbolInfo(); 853 DumpPprofSymbolInfo();
818 // Shutdown the isolate. 854 // Shutdown the isolate.
819 Dart_ShutdownIsolate(); 855 Dart_ShutdownIsolate();
820 // Terminate process exit-code handler. 856 // Terminate process exit-code handler.
821 Process::TerminateExitCodeHandler(); 857 Process::TerminateExitCodeHandler();
822 858
823 free(const_cast<char*>(original_working_directory)); 859 free(const_cast<char*>(original_working_directory));
824 860
825 return 0; 861 return 0;
826 } 862 }
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