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

Side by Side Diff: src/d8.cc

Issue 2208873002: [Tracing] Create TraceConfig JSON string parser in D8. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 4 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
« no previous file with comments | « src/d8.h ('k') | src/libplatform/tracing/trace-config.cc » ('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 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
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 bool included_categories_param =
277 strcmp(kIncludedCategoriesParam, property) == 0;
Yang 2016/08/10 05:58:25 I don't think you need to do a strcmp here. A poin
278 if (value->IsArray()) {
279 Local<Array> v8_array = Local<Array>::Cast(value);
280 for (int i = 0, length = v8_array->Length(); i < length; ++i) {
281 Local<Value> v = v8_array->Get(context, i)
282 .ToLocalChecked()
283 ->ToString(context)
284 .ToLocalChecked();
285 String::Utf8Value str(v->ToString(context).ToLocalChecked());
286 if (included_categories_param) {
287 trace_config->AddIncludedCategory(*str);
288 } else {
289 trace_config->AddExcludedCategory(*str);
290 }
291 }
292 return v8_array->Length();
293 }
294 return 0;
295 }
296
297 static platform::tracing::TraceRecordMode GetTraceRecordMode(
298 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object) {
299 Local<Value> value = GetValue(isolate, context, object, kRecordModeParam);
300 if (value->IsString()) {
301 Local<String> v8_string = value->ToString(context).ToLocalChecked();
302 String::Utf8Value str(v8_string);
303 if (strcmp(kRecordUntilFull, *str) == 0) {
304 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL;
305 } else if (strcmp(kRecordContinuously, *str) == 0) {
306 return platform::tracing::TraceRecordMode::RECORD_CONTINUOUSLY;
307 } else if (strcmp(kRecordAsMuchAsPossible, *str) == 0) {
308 return platform::tracing::TraceRecordMode::RECORD_AS_MUCH_AS_POSSIBLE;
309 }
310 }
311 return platform::tracing::TraceRecordMode::RECORD_UNTIL_FULL;
312 }
313
314 static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context,
315 Local<v8::Object> object, const char* property) {
316 Local<String> v8_str =
317 String::NewFromUtf8(isolate, property, NewStringType::kNormal)
318 .ToLocalChecked();
319 return object->Get(context, v8_str).ToLocalChecked();
320 }
321 };
322
323 } // namespace
324
325 static platform::tracing::TraceConfig* CreateTraceConfigFromJSON(
326 v8::Isolate* isolate, const char* json_str) {
327 platform::tracing::TraceConfig* trace_config =
328 new platform::tracing::TraceConfig();
329 TraceConfigParser::FillTraceConfig(isolate, trace_config, json_str);
330 return trace_config;
331 }
332
333 } // namespace tracing
209 334
210 class PerIsolateData { 335 class PerIsolateData {
211 public: 336 public:
212 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { 337 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) {
213 HandleScope scope(isolate); 338 HandleScope scope(isolate);
214 isolate->SetData(0, this); 339 isolate->SetData(0, this);
215 } 340 }
216 341
217 ~PerIsolateData() { 342 ~PerIsolateData() {
218 isolate_->SetData(0, NULL); // Not really needed, just to be sure... 343 isolate_->SetData(0, NULL); // Not really needed, just to be sure...
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 } else if (strncmp(value, "=none", 6) == 0) { 2113 } else if (strncmp(value, "=none", 6) == 0) {
1989 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; 2114 options.compile_options = v8::ScriptCompiler::kNoCompileOptions;
1990 } else { 2115 } else {
1991 printf("Unknown option to --cache.\n"); 2116 printf("Unknown option to --cache.\n");
1992 return false; 2117 return false;
1993 } 2118 }
1994 argv[i] = NULL; 2119 argv[i] = NULL;
1995 } else if (strcmp(argv[i], "--enable-tracing") == 0) { 2120 } else if (strcmp(argv[i], "--enable-tracing") == 0) {
1996 options.trace_enabled = true; 2121 options.trace_enabled = true;
1997 argv[i] = NULL; 2122 argv[i] = NULL;
2123 } else if (strncmp(argv[i], "--trace-config=", 15) == 0) {
2124 options.trace_config = argv[i] + 15;
2125 argv[i] = NULL;
1998 } 2126 }
1999 } 2127 }
2000 2128
2001 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 2129 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
2002 2130
2003 // Set up isolated source groups. 2131 // Set up isolated source groups.
2004 options.isolate_sources = new SourceGroup[options.num_isolates]; 2132 options.isolate_sources = new SourceGroup[options.num_isolates];
2005 SourceGroup* current = options.isolate_sources; 2133 SourceGroup* current = options.isolate_sources;
2006 current->Begin(argv, 1); 2134 current->Begin(argv, 1);
2007 for (int i = 1; i < argc; i++) { 2135 for (int i = 1; i < argc; i++) {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
2482 if (options.trace_enabled) { 2610 if (options.trace_enabled) {
2483 trace_file.open("v8_trace.json"); 2611 trace_file.open("v8_trace.json");
2484 platform::tracing::TracingController* tracing_controller = 2612 platform::tracing::TracingController* tracing_controller =
2485 new platform::tracing::TracingController(); 2613 new platform::tracing::TracingController();
2486 platform::tracing::TraceBuffer* trace_buffer = 2614 platform::tracing::TraceBuffer* trace_buffer =
2487 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( 2615 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(
2488 platform::tracing::TraceBuffer::kRingBufferChunks, 2616 platform::tracing::TraceBuffer::kRingBufferChunks,
2489 platform::tracing::TraceWriter::CreateJSONTraceWriter( 2617 platform::tracing::TraceWriter::CreateJSONTraceWriter(
2490 trace_file)); 2618 trace_file));
2491 platform::tracing::TraceConfig* trace_config; 2619 platform::tracing::TraceConfig* trace_config;
2492 trace_config = new platform::tracing::TraceConfig(); 2620 if (options.trace_config) {
2493 trace_config->AddIncludedCategory("v8"); 2621 int size = 0;
2622 char* trace_config_json_str =
2623 ReadChars(nullptr, options.trace_config, &size);
2624 trace_config =
2625 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str);
2626 delete[] trace_config_json_str;
2627 } else {
2628 trace_config =
2629 platform::tracing::TraceConfig::CreateDefaultTraceConfig();
2630 }
2494 tracing_controller->Initialize(trace_buffer); 2631 tracing_controller->Initialize(trace_buffer);
2495 tracing_controller->StartTracing(trace_config); 2632 tracing_controller->StartTracing(trace_config);
2496 #ifndef V8_SHARED 2633 #ifndef V8_SHARED
2497 if (!i::FLAG_verify_predictable) { 2634 if (!i::FLAG_verify_predictable) {
2498 platform::SetTracingController(g_platform, tracing_controller); 2635 platform::SetTracingController(g_platform, tracing_controller);
2499 } 2636 }
2500 #else 2637 #else
2501 platform::SetTracingController(g_platform, tracing_controller); 2638 platform::SetTracingController(g_platform, tracing_controller);
2502 #endif 2639 #endif
2503 } 2640 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 } 2713 }
2577 2714
2578 } // namespace v8 2715 } // namespace v8
2579 2716
2580 2717
2581 #ifndef GOOGLE3 2718 #ifndef GOOGLE3
2582 int main(int argc, char* argv[]) { 2719 int main(int argc, char* argv[]) {
2583 return v8::Shell::Main(argc, argv); 2720 return v8::Shell::Main(argc, argv);
2584 } 2721 }
2585 #endif 2722 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/libplatform/tracing/trace-config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698