| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const MemoryDumpConfig& other) = default; | 112 const MemoryDumpConfig& other) = default; |
| 113 | 113 |
| 114 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} | 114 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} |
| 115 | 115 |
| 116 void TraceConfig::MemoryDumpConfig::Clear() { | 116 void TraceConfig::MemoryDumpConfig::Clear() { |
| 117 allowed_dump_modes.clear(); | 117 allowed_dump_modes.clear(); |
| 118 triggers.clear(); | 118 triggers.clear(); |
| 119 heap_profiler_options.Clear(); | 119 heap_profiler_options.Clear(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void TraceConfig::MemoryDumpConfig::Merge( | |
| 123 const TraceConfig::MemoryDumpConfig& config) { | |
| 124 triggers.insert(triggers.end(), config.triggers.begin(), | |
| 125 config.triggers.end()); | |
| 126 allowed_dump_modes.insert(config.allowed_dump_modes.begin(), | |
| 127 config.allowed_dump_modes.end()); | |
| 128 heap_profiler_options.breakdown_threshold_bytes = | |
| 129 std::min(heap_profiler_options.breakdown_threshold_bytes, | |
| 130 config.heap_profiler_options.breakdown_threshold_bytes); | |
| 131 } | |
| 132 | |
| 133 TraceConfig::EventFilterConfig::EventFilterConfig( | 122 TraceConfig::EventFilterConfig::EventFilterConfig( |
| 134 const std::string& predicate_name) | 123 const std::string& predicate_name) |
| 135 : predicate_name_(predicate_name) {} | 124 : predicate_name_(predicate_name) {} |
| 136 | 125 |
| 137 TraceConfig::EventFilterConfig::~EventFilterConfig() {} | 126 TraceConfig::EventFilterConfig::~EventFilterConfig() {} |
| 138 | 127 |
| 139 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) { | 128 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) { |
| 140 *this = tc; | 129 *this = tc; |
| 141 } | 130 } |
| 142 | 131 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // Otherwise, one of the filter was specifying "*" and we want to honor the | 348 // Otherwise, one of the filter was specifying "*" and we want to honor the |
| 360 // broadest filter. | 349 // broadest filter. |
| 361 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { | 350 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { |
| 362 included_categories_.insert(included_categories_.end(), | 351 included_categories_.insert(included_categories_.end(), |
| 363 config.included_categories_.begin(), | 352 config.included_categories_.begin(), |
| 364 config.included_categories_.end()); | 353 config.included_categories_.end()); |
| 365 } else { | 354 } else { |
| 366 included_categories_.clear(); | 355 included_categories_.clear(); |
| 367 } | 356 } |
| 368 | 357 |
| 369 memory_dump_config_.Merge(config.memory_dump_config_); | 358 memory_dump_config_.triggers.insert(memory_dump_config_.triggers.end(), |
| 359 config.memory_dump_config_.triggers.begin(), |
| 360 config.memory_dump_config_.triggers.end()); |
| 370 | 361 |
| 371 disabled_categories_.insert(disabled_categories_.end(), | 362 disabled_categories_.insert(disabled_categories_.end(), |
| 372 config.disabled_categories_.begin(), | 363 config.disabled_categories_.begin(), |
| 373 config.disabled_categories_.end()); | 364 config.disabled_categories_.end()); |
| 374 excluded_categories_.insert(excluded_categories_.end(), | 365 excluded_categories_.insert(excluded_categories_.end(), |
| 375 config.excluded_categories_.begin(), | 366 config.excluded_categories_.begin(), |
| 376 config.excluded_categories_.end()); | 367 config.excluded_categories_.end()); |
| 377 synthetic_delays_.insert(synthetic_delays_.end(), | 368 synthetic_delays_.insert(synthetic_delays_.end(), |
| 378 config.synthetic_delays_.begin(), | 369 config.synthetic_delays_.begin(), |
| 379 config.synthetic_delays_.end()); | 370 config.synthetic_delays_.end()); |
| 380 event_filters_.insert(event_filters_.end(), config.event_filters().begin(), | |
| 381 config.event_filters().end()); | |
| 382 } | 371 } |
| 383 | 372 |
| 384 void TraceConfig::Clear() { | 373 void TraceConfig::Clear() { |
| 385 record_mode_ = RECORD_UNTIL_FULL; | 374 record_mode_ = RECORD_UNTIL_FULL; |
| 386 enable_systrace_ = false; | 375 enable_systrace_ = false; |
| 387 enable_argument_filter_ = false; | 376 enable_argument_filter_ = false; |
| 388 included_categories_.clear(); | 377 included_categories_.clear(); |
| 389 disabled_categories_.clear(); | 378 disabled_categories_.clear(); |
| 390 excluded_categories_.clear(); | 379 excluded_categories_.clear(); |
| 391 synthetic_delays_.clear(); | 380 synthetic_delays_.clear(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 420 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; | 409 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; |
| 421 | 410 |
| 422 const ListValue* category_list = nullptr; | 411 const ListValue* category_list = nullptr; |
| 423 if (dict.GetList(kIncludedCategoriesParam, &category_list)) | 412 if (dict.GetList(kIncludedCategoriesParam, &category_list)) |
| 424 SetCategoriesFromIncludedList(*category_list); | 413 SetCategoriesFromIncludedList(*category_list); |
| 425 if (dict.GetList(kExcludedCategoriesParam, &category_list)) | 414 if (dict.GetList(kExcludedCategoriesParam, &category_list)) |
| 426 SetCategoriesFromExcludedList(*category_list); | 415 SetCategoriesFromExcludedList(*category_list); |
| 427 if (dict.GetList(kSyntheticDelaysParam, &category_list)) | 416 if (dict.GetList(kSyntheticDelaysParam, &category_list)) |
| 428 SetSyntheticDelaysFromList(*category_list); | 417 SetSyntheticDelaysFromList(*category_list); |
| 429 | 418 |
| 430 const base::ListValue* category_event_filters = nullptr; | |
| 431 if (dict.GetList(kEventFiltersParam, &category_event_filters)) | |
| 432 SetEventFiltersFromConfigList(*category_event_filters); | |
| 433 | |
| 434 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 419 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 435 // If dump triggers not set, the client is using the legacy with just | 420 // If dump triggers not set, the client is using the legacy with just |
| 436 // category enabled. So, use the default periodic dump config. | 421 // category enabled. So, use the default periodic dump config. |
| 437 const DictionaryValue* memory_dump_config = nullptr; | 422 const DictionaryValue* memory_dump_config = nullptr; |
| 438 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 423 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
| 439 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); | 424 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); |
| 440 else | 425 else |
| 441 SetDefaultMemoryDumpConfig(); | 426 SetDefaultMemoryDumpConfig(); |
| 442 } | 427 } |
| 428 |
| 429 const base::ListValue* category_event_filters = nullptr; |
| 430 if (dict.GetList(kEventFiltersParam, &category_event_filters)) |
| 431 SetEventFilters(*category_event_filters); |
| 443 } | 432 } |
| 444 | 433 |
| 445 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { | 434 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { |
| 446 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); | 435 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); |
| 447 if (dict) | 436 if (dict) |
| 448 InitializeFromConfigDict(*dict); | 437 InitializeFromConfigDict(*dict); |
| 449 else | 438 else |
| 450 InitializeDefault(); | 439 InitializeDefault(); |
| 451 } | 440 } |
| 452 | 441 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; | 611 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; |
| 623 } | 612 } |
| 624 } | 613 } |
| 625 } | 614 } |
| 626 | 615 |
| 627 void TraceConfig::SetDefaultMemoryDumpConfig() { | 616 void TraceConfig::SetDefaultMemoryDumpConfig() { |
| 628 memory_dump_config_.Clear(); | 617 memory_dump_config_.Clear(); |
| 629 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); | 618 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
| 630 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); | 619 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
| 631 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); | 620 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); |
| 621 |
| 622 if (AllocationContextTracker::capture_mode() == |
| 623 AllocationContextTracker::CaptureMode::PSEUDO_STACK) { |
| 624 for (const auto& filter : event_filters_) { |
| 625 if (filter.predicate_name() == |
| 626 TraceLog::TraceEventFilter::kHeapProfilerPredicate) |
| 627 return; |
| 628 } |
| 629 // Adds a filter predicate to filter all categories for the heap profiler. |
| 630 // Note that the heap profiler predicate does not filter-out any events. |
| 631 EventFilterConfig heap_profiler_config( |
| 632 TraceLog::TraceEventFilter::kHeapProfilerPredicate); |
| 633 heap_profiler_config.AddIncludedCategory("*"); |
| 634 heap_profiler_config.AddIncludedCategory(MemoryDumpManager::kTraceCategory); |
| 635 event_filters_.push_back(heap_profiler_config); |
| 636 } |
| 632 } | 637 } |
| 633 | 638 |
| 634 void TraceConfig::SetEventFiltersFromConfigList( | 639 void TraceConfig::SetEventFilters( |
| 635 const base::ListValue& category_event_filters) { | 640 const base::ListValue& category_event_filters) { |
| 636 event_filters_.clear(); | 641 event_filters_.clear(); |
| 637 | 642 |
| 638 for (size_t event_filter_index = 0; | 643 for (size_t event_filter_index = 0; |
| 639 event_filter_index < category_event_filters.GetSize(); | 644 event_filter_index < category_event_filters.GetSize(); |
| 640 ++event_filter_index) { | 645 ++event_filter_index) { |
| 641 const base::DictionaryValue* event_filter = nullptr; | 646 const base::DictionaryValue* event_filter = nullptr; |
| 642 if (!category_event_filters.GetDictionary(event_filter_index, | 647 if (!category_event_filters.GetDictionary(event_filter_index, |
| 643 &event_filter)) | 648 &event_filter)) |
| 644 continue; | 649 continue; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 StringPiece str) { | 854 StringPiece str) { |
| 850 return str.empty() || str.front() == ' ' || str.back() == ' '; | 855 return str.empty() || str.front() == ' ' || str.back() == ' '; |
| 851 } | 856 } |
| 852 | 857 |
| 853 bool TraceConfig::HasIncludedPatterns() const { | 858 bool TraceConfig::HasIncludedPatterns() const { |
| 854 return !included_categories_.empty(); | 859 return !included_categories_.empty(); |
| 855 } | 860 } |
| 856 | 861 |
| 857 } // namespace trace_event | 862 } // namespace trace_event |
| 858 } // namespace base | 863 } // namespace base |
| OLD | NEW |