OLD | NEW |
---|---|
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 Loading... | |
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 base::DictionaryValue& config) { | |
Primiano Tucci (use gerrit)
2016/03/14 16:53:02
ditto
Zhen Wang
2016/03/14 21:41:45
Done.
| |
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 Loading... | |
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 base::DictionaryValue& dict) { |
Primiano Tucci (use gerrit)
2016/03/14 16:53:02
ditto (base::)
Zhen Wang
2016/03/14 21:41:45
Done.
| |
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<base::Value> value(base::JSONReader::Read(config_string)); | |
349 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { | |
350 InitializeDefault(); | |
351 return; | |
352 } | |
353 scoped_ptr<base::DictionaryValue> dict( | |
Primiano Tucci (use gerrit)
2016/03/14 16:53:02
I know that this is not your fault and you are jus
Zhen Wang
2016/03/14 21:41:45
Done.
| |
354 static_cast<base::DictionaryValue*>(value.release())); | |
Primiano Tucci (use gerrit)
2016/03/14 16:53:02
nit: base::
Zhen Wang
2016/03/14 21:41:45
Done.
| |
355 InitializeFromConfigDict(*dict); | |
356 } | |
357 | |
351 void TraceConfig::InitializeFromStrings( | 358 void TraceConfig::InitializeFromStrings( |
352 const std::string& category_filter_string, | 359 const std::string& category_filter_string, |
353 const std::string& trace_options_string) { | 360 const std::string& trace_options_string) { |
354 if (!category_filter_string.empty()) { | 361 if (!category_filter_string.empty()) { |
355 std::vector<std::string> split = base::SplitString( | 362 std::vector<std::string> split = base::SplitString( |
356 category_filter_string, ",", base::TRIM_WHITESPACE, | 363 category_filter_string, ",", base::TRIM_WHITESPACE, |
357 base::SPLIT_WANT_ALL); | 364 base::SPLIT_WANT_ALL); |
358 std::vector<std::string>::iterator iter; | 365 std::vector<std::string>::iterator iter; |
359 for (iter = split.begin(); iter != split.end(); ++iter) { | 366 for (iter = split.begin(); iter != split.end(); ++iter) { |
360 std::string category = *iter; | 367 std::string category = *iter; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 str.at(0) == ' ' || | 667 str.at(0) == ' ' || |
661 str.at(str.length() - 1) == ' '; | 668 str.at(str.length() - 1) == ' '; |
662 } | 669 } |
663 | 670 |
664 bool TraceConfig::HasIncludedPatterns() const { | 671 bool TraceConfig::HasIncludedPatterns() const { |
665 return !included_categories_.empty(); | 672 return !included_categories_.empty(); |
666 } | 673 } |
667 | 674 |
668 } // namespace trace_event | 675 } // namespace trace_event |
669 } // namespace base | 676 } // namespace base |
OLD | NEW |