OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return NULL; | 199 return NULL; |
200 } | 200 } |
201 | 201 |
202 return worker; | 202 return worker; |
203 } | 203 } |
204 #endif // !V8_SHARED | 204 #endif // !V8_SHARED |
205 | 205 |
206 | 206 |
207 } // namespace | 207 } // namespace |
208 | 208 |
| 209 namespace tracing { |
| 210 |
| 211 namespace { |
| 212 |
| 213 // String options that can be used to initialize TraceOptions. |
| 214 const char kRecordUntilFull[] = "record-until-full"; |
| 215 const char kRecordContinuously[] = "record-continuously"; |
| 216 const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible"; |
| 217 |
| 218 const char kRecordModeParam[] = "record_mode"; |
| 219 const char kEnableSamplingParam[] = "enable_sampling"; |
| 220 const char kEnableSystraceParam[] = "enable_systrace"; |
| 221 const char kEnableArgumentFilterParam[] = "enable_argument_filter"; |
| 222 const char kIncludedCategoriesParam[] = "included_categories"; |
| 223 const char kExcludedCategoriesParam[] = "excluded_categories"; |
| 224 |
| 225 class TraceConfigParser { |
| 226 public: |
| 227 static void FillTraceConfig(v8::Isolate* isolate, |
| 228 platform::tracing::TraceConfig* trace_config, |
| 229 const char* json_str) { |
| 230 HandleScope outer_scope(isolate); |
| 231 Local<Context> context = Context::New(isolate); |
| 232 Context::Scope context_scope(context); |
| 233 HandleScope inner_scope(isolate); |
| 234 |
| 235 Local<String> source = |
| 236 String::NewFromUtf8(isolate, json_str, NewStringType::kNormal) |
| 237 .ToLocalChecked(); |
| 238 Local<Value> result = JSON::Parse(context, source).ToLocalChecked(); |
| 239 Local<v8::Object> trace_config_object = Local<v8::Object>::Cast(result); |
| 240 |
| 241 trace_config->SetTraceRecordMode( |
| 242 GetTraceRecordMode(isolate, context, trace_config_object)); |
| 243 if (GetBoolean(isolate, context, trace_config_object, |
| 244 kEnableSamplingParam)) { |
| 245 trace_config->EnableSampling(); |
| 246 } |
| 247 if (GetBoolean(isolate, context, trace_config_object, |
| 248 kEnableSystraceParam)) { |
| 249 trace_config->EnableSystrace(); |
| 250 } |
| 251 if (GetBoolean(isolate, context, trace_config_object, |
| 252 kEnableArgumentFilterParam)) { |
| 253 trace_config->EnableArgumentFilter(); |
| 254 } |
| 255 UpdateCategoriesList(isolate, context, trace_config_object, |
| 256 kIncludedCategoriesParam, trace_config); |
| 257 UpdateCategoriesList(isolate, context, trace_config_object, |
| 258 kExcludedCategoriesParam, trace_config); |
| 259 } |
| 260 |
| 261 private: |
| 262 static bool GetBoolean(v8::Isolate* isolate, Local<Context> context, |
| 263 Local<v8::Object> object, const char* property) { |
| 264 Local<Value> value = GetValue(isolate, context, object, property); |
| 265 if (value->IsNumber()) { |
| 266 Local<Boolean> v8_boolean = value->ToBoolean(context).ToLocalChecked(); |
| 267 return v8_boolean->Value(); |
| 268 } |
| 269 return false; |
| 270 } |
| 271 |
| 272 static int UpdateCategoriesList( |
| 273 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object, |
| 274 const char* property, platform::tracing::TraceConfig* trace_config) { |
| 275 Local<Value> value = GetValue(isolate, context, object, property); |
| 276 if (value->IsArray()) { |
| 277 Local<Array> v8_array = Local<Array>::Cast(value); |
| 278 for (int i = 0, length = v8_array->Length(); i < length; ++i) { |
| 279 Local<Value> v = v8_array->Get(context, i) |
| 280 .ToLocalChecked() |
| 281 ->ToString(context) |
| 282 .ToLocalChecked(); |
| 283 String::Utf8Value str(v->ToString(context).ToLocalChecked()); |
| 284 if (kIncludedCategoriesParam == property) { |
| 285 trace_config->AddIncludedCategory(*str); |
| 286 } else { |
| 287 trace_config->AddExcludedCategory(*str); |
| 288 } |
| 289 } |
| 290 return v8_array->Length(); |
| 291 } |
| 292 return 0; |
| 293 } |
| 294 |
| 295 static platform::tracing::TraceRecordMode GetTraceRecordMode( |
| 296 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object) { |
| 297 Local<Value> value = GetValue(isolate, context, object, kRecordModeParam); |
| 298 if (value->IsString()) { |
| 299 Local<String> v8_string = value->ToString(context).ToLocalChecked(); |
| 300 String::Utf8Value str(v8_string); |
| 301 if (strcmp(kRecordUntilFull, *str) == 0) { |
| 302 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL; |
| 303 } else if (strcmp(kRecordContinuously, *str) == 0) { |
| 304 return platform::tracing::TraceRecordMode::RECORD_CONTINUOUSLY; |
| 305 } else if (strcmp(kRecordAsMuchAsPossible, *str) == 0) { |
| 306 return platform::tracing::TraceRecordMode::RECORD_AS_MUCH_AS_POSSIBLE; |
| 307 } |
| 308 } |
| 309 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL; |
| 310 } |
| 311 |
| 312 static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context, |
| 313 Local<v8::Object> object, const char* property) { |
| 314 Local<String> v8_str = |
| 315 String::NewFromUtf8(isolate, property, NewStringType::kNormal) |
| 316 .ToLocalChecked(); |
| 317 return object->Get(context, v8_str).ToLocalChecked(); |
| 318 } |
| 319 }; |
| 320 |
| 321 } // namespace |
| 322 |
| 323 static platform::tracing::TraceConfig* CreateTraceConfigFromJSON( |
| 324 v8::Isolate* isolate, const char* json_str) { |
| 325 platform::tracing::TraceConfig* trace_config = |
| 326 new platform::tracing::TraceConfig(); |
| 327 TraceConfigParser::FillTraceConfig(isolate, trace_config, json_str); |
| 328 return trace_config; |
| 329 } |
| 330 |
| 331 } // namespace tracing |
209 | 332 |
210 class PerIsolateData { | 333 class PerIsolateData { |
211 public: | 334 public: |
212 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { | 335 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { |
213 HandleScope scope(isolate); | 336 HandleScope scope(isolate); |
214 isolate->SetData(0, this); | 337 isolate->SetData(0, this); |
215 } | 338 } |
216 | 339 |
217 ~PerIsolateData() { | 340 ~PerIsolateData() { |
218 isolate_->SetData(0, NULL); // Not really needed, just to be sure... | 341 isolate_->SetData(0, NULL); // Not really needed, just to be sure... |
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 } else if (strncmp(value, "=none", 6) == 0) { | 2111 } else if (strncmp(value, "=none", 6) == 0) { |
1989 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; | 2112 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; |
1990 } else { | 2113 } else { |
1991 printf("Unknown option to --cache.\n"); | 2114 printf("Unknown option to --cache.\n"); |
1992 return false; | 2115 return false; |
1993 } | 2116 } |
1994 argv[i] = NULL; | 2117 argv[i] = NULL; |
1995 } else if (strcmp(argv[i], "--enable-tracing") == 0) { | 2118 } else if (strcmp(argv[i], "--enable-tracing") == 0) { |
1996 options.trace_enabled = true; | 2119 options.trace_enabled = true; |
1997 argv[i] = NULL; | 2120 argv[i] = NULL; |
| 2121 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) { |
| 2122 options.trace_config = argv[i] + 15; |
| 2123 argv[i] = NULL; |
1998 } | 2124 } |
1999 } | 2125 } |
2000 | 2126 |
2001 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 2127 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
2002 | 2128 |
2003 // Set up isolated source groups. | 2129 // Set up isolated source groups. |
2004 options.isolate_sources = new SourceGroup[options.num_isolates]; | 2130 options.isolate_sources = new SourceGroup[options.num_isolates]; |
2005 SourceGroup* current = options.isolate_sources; | 2131 SourceGroup* current = options.isolate_sources; |
2006 current->Begin(argv, 1); | 2132 current->Begin(argv, 1); |
2007 for (int i = 1; i < argc; i++) { | 2133 for (int i = 1; i < argc; i++) { |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2482 if (options.trace_enabled) { | 2608 if (options.trace_enabled) { |
2483 trace_file.open("v8_trace.json"); | 2609 trace_file.open("v8_trace.json"); |
2484 platform::tracing::TracingController* tracing_controller = | 2610 platform::tracing::TracingController* tracing_controller = |
2485 new platform::tracing::TracingController(); | 2611 new platform::tracing::TracingController(); |
2486 platform::tracing::TraceBuffer* trace_buffer = | 2612 platform::tracing::TraceBuffer* trace_buffer = |
2487 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( | 2613 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( |
2488 platform::tracing::TraceBuffer::kRingBufferChunks, | 2614 platform::tracing::TraceBuffer::kRingBufferChunks, |
2489 platform::tracing::TraceWriter::CreateJSONTraceWriter( | 2615 platform::tracing::TraceWriter::CreateJSONTraceWriter( |
2490 trace_file)); | 2616 trace_file)); |
2491 platform::tracing::TraceConfig* trace_config; | 2617 platform::tracing::TraceConfig* trace_config; |
2492 trace_config = new platform::tracing::TraceConfig(); | 2618 if (options.trace_config) { |
2493 trace_config->AddIncludedCategory("v8"); | 2619 int size = 0; |
| 2620 char* trace_config_json_str = |
| 2621 ReadChars(nullptr, options.trace_config, &size); |
| 2622 trace_config = |
| 2623 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); |
| 2624 delete[] trace_config_json_str; |
| 2625 } else { |
| 2626 trace_config = |
| 2627 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); |
| 2628 } |
2494 tracing_controller->Initialize(trace_buffer); | 2629 tracing_controller->Initialize(trace_buffer); |
2495 tracing_controller->StartTracing(trace_config); | 2630 tracing_controller->StartTracing(trace_config); |
2496 #ifndef V8_SHARED | 2631 #ifndef V8_SHARED |
2497 if (!i::FLAG_verify_predictable) { | 2632 if (!i::FLAG_verify_predictable) { |
2498 platform::SetTracingController(g_platform, tracing_controller); | 2633 platform::SetTracingController(g_platform, tracing_controller); |
2499 } | 2634 } |
2500 #else | 2635 #else |
2501 platform::SetTracingController(g_platform, tracing_controller); | 2636 platform::SetTracingController(g_platform, tracing_controller); |
2502 #endif | 2637 #endif |
2503 } | 2638 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2576 } | 2711 } |
2577 | 2712 |
2578 } // namespace v8 | 2713 } // namespace v8 |
2579 | 2714 |
2580 | 2715 |
2581 #ifndef GOOGLE3 | 2716 #ifndef GOOGLE3 |
2582 int main(int argc, char* argv[]) { | 2717 int main(int argc, char* argv[]) { |
2583 return v8::Shell::Main(argc, argv); | 2718 return v8::Shell::Main(argc, argv); |
2584 } | 2719 } |
2585 #endif | 2720 #endif |
OLD | NEW |