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

Side by Side Diff: base/trace_event/trace_config.cc

Issue 1765153002: Update DevTools Tracing.Start to accept trace config as a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix for primiano and petrcermak's comments Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium 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 #include "base/trace_event/trace_config.h" 5 #include "base/trace_event/trace_config.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 break; 98 break;
99 case ECHO_TO_CONSOLE: 99 case ECHO_TO_CONSOLE:
100 trace_options_string = kTraceToConsole; 100 trace_options_string = kTraceToConsole;
101 break; 101 break;
102 default: 102 default:
103 NOTREACHED(); 103 NOTREACHED();
104 } 104 }
105 InitializeFromStrings(category_filter_string, trace_options_string); 105 InitializeFromStrings(category_filter_string, trace_options_string);
106 } 106 }
107 107
108 TraceConfig::TraceConfig(const DictionaryValue& config) {
109 InitializeFromConfigDict(config);
110 }
111
108 TraceConfig::TraceConfig(const std::string& config_string) { 112 TraceConfig::TraceConfig(const std::string& config_string) {
109 if (!config_string.empty()) 113 if (!config_string.empty())
110 InitializeFromConfigString(config_string); 114 InitializeFromConfigString(config_string);
111 else 115 else
112 InitializeDefault(); 116 InitializeDefault();
113 } 117 }
114 118
115 TraceConfig::TraceConfig(const TraceConfig& tc) 119 TraceConfig::TraceConfig(const TraceConfig& tc)
116 : record_mode_(tc.record_mode_), 120 : record_mode_(tc.record_mode_),
117 enable_sampling_(tc.enable_sampling_), 121 enable_sampling_(tc.enable_sampling_),
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 285
282 void TraceConfig::InitializeDefault() { 286 void TraceConfig::InitializeDefault() {
283 record_mode_ = RECORD_UNTIL_FULL; 287 record_mode_ = RECORD_UNTIL_FULL;
284 enable_sampling_ = false; 288 enable_sampling_ = false;
285 enable_systrace_ = false; 289 enable_systrace_ = false;
286 enable_argument_filter_ = false; 290 enable_argument_filter_ = false;
287 excluded_categories_.push_back("*Debug"); 291 excluded_categories_.push_back("*Debug");
288 excluded_categories_.push_back("*Test"); 292 excluded_categories_.push_back("*Test");
289 } 293 }
290 294
291 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { 295 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) {
292 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string));
293 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) {
294 InitializeDefault();
295 return;
296 }
297 scoped_ptr<base::DictionaryValue> dict(
298 static_cast<base::DictionaryValue*>(value.release()));
299
300 record_mode_ = RECORD_UNTIL_FULL; 296 record_mode_ = RECORD_UNTIL_FULL;
301 std::string record_mode; 297 std::string record_mode;
302 if (dict->GetString(kRecordModeParam, &record_mode)) { 298 if (dict.GetString(kRecordModeParam, &record_mode)) {
303 if (record_mode == kRecordUntilFull) { 299 if (record_mode == kRecordUntilFull) {
304 record_mode_ = RECORD_UNTIL_FULL; 300 record_mode_ = RECORD_UNTIL_FULL;
305 } else if (record_mode == kRecordContinuously) { 301 } else if (record_mode == kRecordContinuously) {
306 record_mode_ = RECORD_CONTINUOUSLY; 302 record_mode_ = RECORD_CONTINUOUSLY;
307 } else if (record_mode == kTraceToConsole) { 303 } else if (record_mode == kTraceToConsole) {
308 record_mode_ = ECHO_TO_CONSOLE; 304 record_mode_ = ECHO_TO_CONSOLE;
309 } else if (record_mode == kRecordAsMuchAsPossible) { 305 } else if (record_mode == kRecordAsMuchAsPossible) {
310 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; 306 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE;
311 } 307 }
312 } 308 }
313 309
314 bool enable_sampling; 310 bool enable_sampling;
315 if (!dict->GetBoolean(kEnableSamplingParam, &enable_sampling)) 311 if (!dict.GetBoolean(kEnableSamplingParam, &enable_sampling))
316 enable_sampling_ = false; 312 enable_sampling_ = false;
317 else 313 else
318 enable_sampling_ = enable_sampling; 314 enable_sampling_ = enable_sampling;
319 315
320 bool enable_systrace; 316 bool enable_systrace;
321 if (!dict->GetBoolean(kEnableSystraceParam, &enable_systrace)) 317 if (!dict.GetBoolean(kEnableSystraceParam, &enable_systrace))
322 enable_systrace_ = false; 318 enable_systrace_ = false;
323 else 319 else
324 enable_systrace_ = enable_systrace; 320 enable_systrace_ = enable_systrace;
325 321
326 bool enable_argument_filter; 322 bool enable_argument_filter;
327 if (!dict->GetBoolean(kEnableArgumentFilterParam, &enable_argument_filter)) 323 if (!dict.GetBoolean(kEnableArgumentFilterParam, &enable_argument_filter))
328 enable_argument_filter_ = false; 324 enable_argument_filter_ = false;
329 else 325 else
330 enable_argument_filter_ = enable_argument_filter; 326 enable_argument_filter_ = enable_argument_filter;
331 327
332 base::ListValue* category_list = nullptr; 328 const base::ListValue* category_list = nullptr;
333 if (dict->GetList(kIncludedCategoriesParam, &category_list)) 329 if (dict.GetList(kIncludedCategoriesParam, &category_list))
334 SetCategoriesFromIncludedList(*category_list); 330 SetCategoriesFromIncludedList(*category_list);
335 if (dict->GetList(kExcludedCategoriesParam, &category_list)) 331 if (dict.GetList(kExcludedCategoriesParam, &category_list))
336 SetCategoriesFromExcludedList(*category_list); 332 SetCategoriesFromExcludedList(*category_list);
337 if (dict->GetList(kSyntheticDelaysParam, &category_list)) 333 if (dict.GetList(kSyntheticDelaysParam, &category_list))
338 SetSyntheticDelaysFromList(*category_list); 334 SetSyntheticDelaysFromList(*category_list);
339 335
340 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { 336 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) {
341 // If dump triggers not set, the client is using the legacy with just 337 // If dump triggers not set, the client is using the legacy with just
342 // category enabled. So, use the default periodic dump config. 338 // category enabled. So, use the default periodic dump config.
343 base::DictionaryValue* memory_dump_config = nullptr; 339 const base::DictionaryValue* memory_dump_config = nullptr;
344 if (dict->GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) 340 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config))
345 SetMemoryDumpConfig(*memory_dump_config); 341 SetMemoryDumpConfig(*memory_dump_config);
346 else 342 else
347 SetDefaultMemoryDumpConfig(); 343 SetDefaultMemoryDumpConfig();
348 } 344 }
349 } 345 }
350 346
347 void TraceConfig::InitializeFromConfigString(const std::string& config_string) {
348 scoped_ptr<Value> value(JSONReader::Read(config_string));
349 if (!value)
350 return InitializeDefault();
351
352 const DictionaryValue* dict = nullptr;
353 bool is_dict = value->GetAsDictionary(&dict);
354
355 if (!is_dict)
356 return InitializeDefault();
357
358 DCHECK(dict);
359 InitializeFromConfigDict(*dict);
360 }
361
351 void TraceConfig::InitializeFromStrings( 362 void TraceConfig::InitializeFromStrings(
352 const std::string& category_filter_string, 363 const std::string& category_filter_string,
353 const std::string& trace_options_string) { 364 const std::string& trace_options_string) {
354 if (!category_filter_string.empty()) { 365 if (!category_filter_string.empty()) {
355 std::vector<std::string> split = base::SplitString( 366 std::vector<std::string> split = base::SplitString(
356 category_filter_string, ",", base::TRIM_WHITESPACE, 367 category_filter_string, ",", base::TRIM_WHITESPACE,
357 base::SPLIT_WANT_ALL); 368 base::SPLIT_WANT_ALL);
358 std::vector<std::string>::iterator iter; 369 std::vector<std::string>::iterator iter;
359 for (iter = split.begin(); iter != split.end(); ++iter) { 370 for (iter = split.begin(); iter != split.end(); ++iter) {
360 std::string category = *iter; 371 std::string category = *iter;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 str.at(0) == ' ' || 671 str.at(0) == ' ' ||
661 str.at(str.length() - 1) == ' '; 672 str.at(str.length() - 1) == ' ';
662 } 673 }
663 674
664 bool TraceConfig::HasIncludedPatterns() const { 675 bool TraceConfig::HasIncludedPatterns() const {
665 return !included_categories_.empty(); 676 return !included_categories_.empty();
666 } 677 }
667 678
668 } // namespace trace_event 679 } // namespace trace_event
669 } // namespace base 680 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698