| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const MemoryDumpConfig& other) = default; | 114 const MemoryDumpConfig& other) = default; |
| 115 | 115 |
| 116 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} | 116 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} |
| 117 | 117 |
| 118 void TraceConfig::MemoryDumpConfig::Clear() { | 118 void TraceConfig::MemoryDumpConfig::Clear() { |
| 119 allowed_dump_modes.clear(); | 119 allowed_dump_modes.clear(); |
| 120 triggers.clear(); | 120 triggers.clear(); |
| 121 heap_profiler_options.Clear(); | 121 heap_profiler_options.Clear(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void TraceConfig::MemoryDumpConfig::Merge( |
| 125 const TraceConfig::MemoryDumpConfig& config) { |
| 126 triggers.insert(triggers.end(), config.triggers.begin(), |
| 127 config.triggers.end()); |
| 128 allowed_dump_modes.insert(config.allowed_dump_modes.begin(), |
| 129 config.allowed_dump_modes.end()); |
| 130 heap_profiler_options.breakdown_threshold_bytes = |
| 131 std::min(heap_profiler_options.breakdown_threshold_bytes, |
| 132 config.heap_profiler_options.breakdown_threshold_bytes); |
| 133 } |
| 134 |
| 124 TraceConfig::EventFilterConfig::EventFilterConfig( | 135 TraceConfig::EventFilterConfig::EventFilterConfig( |
| 125 const std::string& predicate_name) | 136 const std::string& predicate_name) |
| 126 : predicate_name_(predicate_name) {} | 137 : predicate_name_(predicate_name) {} |
| 127 | 138 |
| 128 TraceConfig::EventFilterConfig::~EventFilterConfig() {} | 139 TraceConfig::EventFilterConfig::~EventFilterConfig() {} |
| 129 | 140 |
| 130 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) { | 141 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) { |
| 131 *this = tc; | 142 *this = tc; |
| 132 } | 143 } |
| 133 | 144 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // Otherwise, one of the filter was specifying "*" and we want to honor the | 364 // Otherwise, one of the filter was specifying "*" and we want to honor the |
| 354 // broadest filter. | 365 // broadest filter. |
| 355 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { | 366 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { |
| 356 included_categories_.insert(included_categories_.end(), | 367 included_categories_.insert(included_categories_.end(), |
| 357 config.included_categories_.begin(), | 368 config.included_categories_.begin(), |
| 358 config.included_categories_.end()); | 369 config.included_categories_.end()); |
| 359 } else { | 370 } else { |
| 360 included_categories_.clear(); | 371 included_categories_.clear(); |
| 361 } | 372 } |
| 362 | 373 |
| 363 memory_dump_config_.triggers.insert(memory_dump_config_.triggers.end(), | 374 memory_dump_config_.Merge(config.memory_dump_config_); |
| 364 config.memory_dump_config_.triggers.begin(), | |
| 365 config.memory_dump_config_.triggers.end()); | |
| 366 | 375 |
| 367 disabled_categories_.insert(disabled_categories_.end(), | 376 disabled_categories_.insert(disabled_categories_.end(), |
| 368 config.disabled_categories_.begin(), | 377 config.disabled_categories_.begin(), |
| 369 config.disabled_categories_.end()); | 378 config.disabled_categories_.end()); |
| 370 excluded_categories_.insert(excluded_categories_.end(), | 379 excluded_categories_.insert(excluded_categories_.end(), |
| 371 config.excluded_categories_.begin(), | 380 config.excluded_categories_.begin(), |
| 372 config.excluded_categories_.end()); | 381 config.excluded_categories_.end()); |
| 373 synthetic_delays_.insert(synthetic_delays_.end(), | 382 synthetic_delays_.insert(synthetic_delays_.end(), |
| 374 config.synthetic_delays_.begin(), | 383 config.synthetic_delays_.begin(), |
| 375 config.synthetic_delays_.end()); | 384 config.synthetic_delays_.end()); |
| 385 event_filters_.insert(event_filters_.end(), config.event_filters().begin(), |
| 386 config.event_filters().end()); |
| 376 } | 387 } |
| 377 | 388 |
| 378 void TraceConfig::Clear() { | 389 void TraceConfig::Clear() { |
| 379 record_mode_ = RECORD_UNTIL_FULL; | 390 record_mode_ = RECORD_UNTIL_FULL; |
| 380 enable_sampling_ = false; | 391 enable_sampling_ = false; |
| 381 enable_systrace_ = false; | 392 enable_systrace_ = false; |
| 382 enable_argument_filter_ = false; | 393 enable_argument_filter_ = false; |
| 383 included_categories_.clear(); | 394 included_categories_.clear(); |
| 384 disabled_categories_.clear(); | 395 disabled_categories_.clear(); |
| 385 excluded_categories_.clear(); | 396 excluded_categories_.clear(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; | 428 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; |
| 418 | 429 |
| 419 const ListValue* category_list = nullptr; | 430 const ListValue* category_list = nullptr; |
| 420 if (dict.GetList(kIncludedCategoriesParam, &category_list)) | 431 if (dict.GetList(kIncludedCategoriesParam, &category_list)) |
| 421 SetCategoriesFromIncludedList(*category_list); | 432 SetCategoriesFromIncludedList(*category_list); |
| 422 if (dict.GetList(kExcludedCategoriesParam, &category_list)) | 433 if (dict.GetList(kExcludedCategoriesParam, &category_list)) |
| 423 SetCategoriesFromExcludedList(*category_list); | 434 SetCategoriesFromExcludedList(*category_list); |
| 424 if (dict.GetList(kSyntheticDelaysParam, &category_list)) | 435 if (dict.GetList(kSyntheticDelaysParam, &category_list)) |
| 425 SetSyntheticDelaysFromList(*category_list); | 436 SetSyntheticDelaysFromList(*category_list); |
| 426 | 437 |
| 438 const base::ListValue* category_event_filters = nullptr; |
| 439 if (dict.GetList(kEventFiltersParam, &category_event_filters)) |
| 440 SetEventFilters(*category_event_filters); |
| 441 |
| 427 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 442 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 428 // If dump triggers not set, the client is using the legacy with just | 443 // If dump triggers not set, the client is using the legacy with just |
| 429 // category enabled. So, use the default periodic dump config. | 444 // category enabled. So, use the default periodic dump config. |
| 430 const DictionaryValue* memory_dump_config = nullptr; | 445 const DictionaryValue* memory_dump_config = nullptr; |
| 431 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 446 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
| 432 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); | 447 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); |
| 433 else | 448 else |
| 434 SetDefaultMemoryDumpConfig(); | 449 SetDefaultMemoryDumpConfig(); |
| 435 } | 450 } |
| 436 | |
| 437 const base::ListValue* category_event_filters = nullptr; | |
| 438 if (dict.GetList(kEventFiltersParam, &category_event_filters)) | |
| 439 SetEventFilters(*category_event_filters); | |
| 440 } | 451 } |
| 441 | 452 |
| 442 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { | 453 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { |
| 443 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); | 454 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); |
| 444 if (dict) | 455 if (dict) |
| 445 InitializeFromConfigDict(*dict); | 456 InitializeFromConfigDict(*dict); |
| 446 else | 457 else |
| 447 InitializeDefault(); | 458 InitializeDefault(); |
| 448 } | 459 } |
| 449 | 460 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; | 633 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; |
| 623 } | 634 } |
| 624 } | 635 } |
| 625 } | 636 } |
| 626 | 637 |
| 627 void TraceConfig::SetDefaultMemoryDumpConfig() { | 638 void TraceConfig::SetDefaultMemoryDumpConfig() { |
| 628 memory_dump_config_.Clear(); | 639 memory_dump_config_.Clear(); |
| 629 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); | 640 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
| 630 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); | 641 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
| 631 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); | 642 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); |
| 632 | |
| 633 if (AllocationContextTracker::capture_mode() == | |
| 634 AllocationContextTracker::CaptureMode::PSEUDO_STACK) { | |
| 635 for (const auto& filter : event_filters_) { | |
| 636 if (filter.predicate_name() == | |
| 637 TraceLog::TraceEventFilter::kHeapProfilerPredicate) | |
| 638 return; | |
| 639 } | |
| 640 // Adds a filter predicate to filter all categories for the heap profiler. | |
| 641 // Note that the heap profiler predicate does not filter-out any events. | |
| 642 EventFilterConfig heap_profiler_config( | |
| 643 TraceLog::TraceEventFilter::kHeapProfilerPredicate); | |
| 644 heap_profiler_config.AddIncludedCategory("*"); | |
| 645 heap_profiler_config.AddIncludedCategory(MemoryDumpManager::kTraceCategory); | |
| 646 event_filters_.push_back(heap_profiler_config); | |
| 647 } | |
| 648 } | 643 } |
| 649 | 644 |
| 650 void TraceConfig::SetEventFilters( | 645 void TraceConfig::SetEventFilters( |
| 651 const base::ListValue& category_event_filters) { | 646 const base::ListValue& category_event_filters) { |
| 652 event_filters_.clear(); | 647 event_filters_.clear(); |
| 653 | 648 |
| 654 for (size_t event_filter_index = 0; | 649 for (size_t event_filter_index = 0; |
| 655 event_filter_index < category_event_filters.GetSize(); | 650 event_filter_index < category_event_filters.GetSize(); |
| 656 ++event_filter_index) { | 651 ++event_filter_index) { |
| 657 const base::DictionaryValue* event_filter = nullptr; | 652 const base::DictionaryValue* event_filter = nullptr; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 StringPiece str) { | 863 StringPiece str) { |
| 869 return str.empty() || str.front() == ' ' || str.back() == ' '; | 864 return str.empty() || str.front() == ' ' || str.back() == ' '; |
| 870 } | 865 } |
| 871 | 866 |
| 872 bool TraceConfig::HasIncludedPatterns() const { | 867 bool TraceConfig::HasIncludedPatterns() const { |
| 873 return !included_categories_.empty(); | 868 return !included_categories_.empty(); |
| 874 } | 869 } |
| 875 | 870 |
| 876 } // namespace trace_event | 871 } // namespace trace_event |
| 877 } // namespace base | 872 } // namespace base |
| OLD | NEW |