Chromium Code Reviews| 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, | |
| 257 trace_config->GetIncludedCategories()); | |
|
fmeawad
2016/08/04 13:01:06
Instead of Getting the categories list, and append
lpy
2016/08/04 17:48:30
Then it will need to update categories list method
lpy
2016/08/08 18:39:56
Done.
| |
| 258 UpdateCategoriesList(isolate, context, trace_config_object, | |
| 259 kExcludedCategoriesParam, | |
| 260 trace_config->GetExcludedCategories()); | |
| 261 } | |
| 262 | |
| 263 private: | |
| 264 static bool GetBoolean(v8::Isolate* isolate, Local<Context> context, | |
| 265 Local<v8::Object> object, const char* property) { | |
| 266 Local<Value> value = GetValue(isolate, context, object, property); | |
| 267 if (value->IsNumber()) { | |
| 268 Local<Boolean> v8_boolean = value->ToBoolean(context).ToLocalChecked(); | |
| 269 return v8_boolean->Value(); | |
| 270 } | |
| 271 return false; | |
| 272 } | |
| 273 | |
| 274 static int UpdateCategoriesList( | |
| 275 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object, | |
| 276 const char* property, | |
| 277 platform::tracing::TraceConfig::StringList& categories_list) { | |
| 278 Local<Value> value = GetValue(isolate, context, object, property); | |
| 279 if (value->IsArray()) { | |
| 280 Local<Array> v8_array = Local<Array>::Cast(value); | |
| 281 for (int i = 0, length = v8_array->Length(); i < length; ++i) { | |
| 282 Local<Value> v = v8_array->Get(context, i) | |
| 283 .ToLocalChecked() | |
| 284 ->ToString(context) | |
| 285 .ToLocalChecked(); | |
| 286 String::Utf8Value str(v->ToString(context).ToLocalChecked()); | |
| 287 categories_list.push_back(std::string(*str)); | |
| 288 } | |
| 289 return v8_array->Length(); | |
| 290 } | |
| 291 return 0; | |
| 292 } | |
| 293 | |
| 294 static platform::tracing::TraceRecordMode GetTraceRecordMode( | |
| 295 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object) { | |
| 296 Local<Value> value = GetValue(isolate, context, object, kRecordModeParam); | |
| 297 if (value->IsString()) { | |
| 298 Local<String> v8_string = value->ToString(context).ToLocalChecked(); | |
| 299 String::Utf8Value str(v8_string); | |
| 300 if (strcmp(kRecordUntilFull, *str) == 0) { | |
| 301 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL; | |
| 302 } else if (strcmp(kRecordContinuously, *str) == 0) { | |
| 303 return platform::tracing::TraceRecordMode::RECORD_CONTINUOUSLY; | |
| 304 } else if (strcmp(kRecordAsMuchAsPossible, *str) == 0) { | |
| 305 return platform::tracing::TraceRecordMode::RECORD_AS_MUCH_AS_POSSIBLE; | |
| 306 } | |
| 307 } | |
| 308 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL; | |
| 309 } | |
| 310 | |
| 311 static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context, | |
| 312 Local<v8::Object> object, const char* property) { | |
| 313 Local<String> v8_str = | |
| 314 String::NewFromUtf8(isolate, property, NewStringType::kNormal) | |
| 315 .ToLocalChecked(); | |
| 316 return object->Get(context, v8_str).ToLocalChecked(); | |
| 317 } | |
| 318 }; | |
| 319 | |
| 320 } // namespace | |
| 321 | |
| 322 static platform::tracing::TraceConfig* CreateTraceConfigFromJSON( | |
| 323 v8::Isolate* isolate, const char* json_str) { | |
| 324 platform::tracing::TraceConfig* trace_config = | |
| 325 new platform::tracing::TraceConfig(); | |
| 326 TraceConfigParser::FillTraceConfig(isolate, trace_config, json_str); | |
| 327 return trace_config; | |
| 328 } | |
| 329 | |
| 330 } // namespace tracing | |
| 209 | 331 |
| 210 class PerIsolateData { | 332 class PerIsolateData { |
| 211 public: | 333 public: |
| 212 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { | 334 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { |
| 213 HandleScope scope(isolate); | 335 HandleScope scope(isolate); |
| 214 isolate->SetData(0, this); | 336 isolate->SetData(0, this); |
| 215 } | 337 } |
| 216 | 338 |
| 217 ~PerIsolateData() { | 339 ~PerIsolateData() { |
| 218 isolate_->SetData(0, NULL); // Not really needed, just to be sure... | 340 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) { | 2110 } else if (strncmp(value, "=none", 6) == 0) { |
| 1989 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; | 2111 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; |
| 1990 } else { | 2112 } else { |
| 1991 printf("Unknown option to --cache.\n"); | 2113 printf("Unknown option to --cache.\n"); |
| 1992 return false; | 2114 return false; |
| 1993 } | 2115 } |
| 1994 argv[i] = NULL; | 2116 argv[i] = NULL; |
| 1995 } else if (strcmp(argv[i], "--enable-tracing") == 0) { | 2117 } else if (strcmp(argv[i], "--enable-tracing") == 0) { |
| 1996 options.trace_enabled = true; | 2118 options.trace_enabled = true; |
| 1997 argv[i] = NULL; | 2119 argv[i] = NULL; |
| 2120 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) { | |
| 2121 options.trace_config = argv[i] + 15; | |
| 2122 argv[i] = NULL; | |
| 1998 } | 2123 } |
| 1999 } | 2124 } |
| 2000 | 2125 |
| 2001 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 2126 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 2002 | 2127 |
| 2003 // Set up isolated source groups. | 2128 // Set up isolated source groups. |
| 2004 options.isolate_sources = new SourceGroup[options.num_isolates]; | 2129 options.isolate_sources = new SourceGroup[options.num_isolates]; |
| 2005 SourceGroup* current = options.isolate_sources; | 2130 SourceGroup* current = options.isolate_sources; |
| 2006 current->Begin(argv, 1); | 2131 current->Begin(argv, 1); |
| 2007 for (int i = 1; i < argc; i++) { | 2132 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) { | 2607 if (options.trace_enabled) { |
| 2483 trace_file.open("v8_trace.json"); | 2608 trace_file.open("v8_trace.json"); |
| 2484 platform::tracing::TracingController* tracing_controller = | 2609 platform::tracing::TracingController* tracing_controller = |
| 2485 new platform::tracing::TracingController(); | 2610 new platform::tracing::TracingController(); |
| 2486 platform::tracing::TraceBuffer* trace_buffer = | 2611 platform::tracing::TraceBuffer* trace_buffer = |
| 2487 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( | 2612 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( |
| 2488 platform::tracing::TraceBuffer::kRingBufferChunks, | 2613 platform::tracing::TraceBuffer::kRingBufferChunks, |
| 2489 platform::tracing::TraceWriter::CreateJSONTraceWriter( | 2614 platform::tracing::TraceWriter::CreateJSONTraceWriter( |
| 2490 trace_file)); | 2615 trace_file)); |
| 2491 platform::tracing::TraceConfig* trace_config; | 2616 platform::tracing::TraceConfig* trace_config; |
| 2492 trace_config = new platform::tracing::TraceConfig(); | 2617 if (options.trace_config) { |
| 2493 trace_config->AddIncludedCategory("v8"); | 2618 int size = 0; |
| 2619 char* trace_config_json_str = | |
| 2620 ReadChars(nullptr, options.trace_config, &size); | |
| 2621 trace_config = | |
| 2622 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); | |
| 2623 delete[] trace_config_json_str; | |
| 2624 } else { | |
| 2625 trace_config = | |
| 2626 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); | |
| 2627 } | |
| 2494 tracing_controller->Initialize(trace_buffer); | 2628 tracing_controller->Initialize(trace_buffer); |
| 2495 tracing_controller->StartTracing(trace_config); | 2629 tracing_controller->StartTracing(trace_config); |
| 2496 #ifndef V8_SHARED | 2630 #ifndef V8_SHARED |
| 2497 if (!i::FLAG_verify_predictable) { | 2631 if (!i::FLAG_verify_predictable) { |
| 2498 platform::SetTracingController(g_platform, tracing_controller); | 2632 platform::SetTracingController(g_platform, tracing_controller); |
| 2499 } | 2633 } |
| 2500 #else | 2634 #else |
| 2501 platform::SetTracingController(g_platform, tracing_controller); | 2635 platform::SetTracingController(g_platform, tracing_controller); |
| 2502 #endif | 2636 #endif |
| 2503 } | 2637 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2576 } | 2710 } |
| 2577 | 2711 |
| 2578 } // namespace v8 | 2712 } // namespace v8 |
| 2579 | 2713 |
| 2580 | 2714 |
| 2581 #ifndef GOOGLE3 | 2715 #ifndef GOOGLE3 |
| 2582 int main(int argc, char* argv[]) { | 2716 int main(int argc, char* argv[]) { |
| 2583 return v8::Shell::Main(argc, argv); | 2717 return v8::Shell::Main(argc, argv); |
| 2584 } | 2718 } |
| 2585 #endif | 2719 #endif |
| OLD | NEW |