| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "content/browser/tracing/background_tracing_rule.h" | 4 #include "content/browser/tracing/background_tracing_rule.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/strings/safe_sprintf.h" | 12 #include "base/strings/safe_sprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "components/tracing/common/tracing_messages.h" | 14 #include "components/tracing/common/tracing_messages.h" |
| 15 #include "content/browser/tracing/background_tracing_manager_impl.h" | 15 #include "content/browser/tracing/background_tracing_manager_impl.h" |
| 16 #include "content/browser/tracing/trace_message_filter.h" | 16 #include "content/browser/tracing/trace_message_filter.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kConfigRuleKey[] = "rule"; | 21 const char kConfigRuleKey[] = "rule"; |
| 22 const char kConfigCategoryKey[] = "category"; | 22 const char kConfigCategoryKey[] = "category"; |
| 23 const char kConfigRuleTriggerNameKey[] = "trigger_name"; | 23 const char kConfigRuleTriggerNameKey[] = "trigger_name"; |
| 24 const char kConfigRuleTriggerDelay[] = "trigger_delay"; | 24 const char kConfigRuleTriggerDelay[] = "trigger_delay"; |
| 25 const char kConfigRuleTriggerChance[] = "trigger_chance"; | 25 const char kConfigRuleTriggerChance[] = "trigger_chance"; |
| 26 const char kConfigRuleStopTracingOnRepeatedReactive[] = | |
| 27 "stop_tracing_on_repeated_reactive"; | |
| 28 | 26 |
| 29 const char kConfigRuleHistogramNameKey[] = "histogram_name"; | 27 const char kConfigRuleHistogramNameKey[] = "histogram_name"; |
| 30 const char kConfigRuleHistogramValueOldKey[] = "histogram_value"; | 28 const char kConfigRuleHistogramValueOldKey[] = "histogram_value"; |
| 31 const char kConfigRuleHistogramValue1Key[] = "histogram_lower_value"; | 29 const char kConfigRuleHistogramValue1Key[] = "histogram_lower_value"; |
| 32 const char kConfigRuleHistogramValue2Key[] = "histogram_upper_value"; | 30 const char kConfigRuleHistogramValue2Key[] = "histogram_upper_value"; |
| 33 const char kConfigRuleHistogramRepeatKey[] = "histogram_repeat"; | 31 const char kConfigRuleHistogramRepeatKey[] = "histogram_repeat"; |
| 34 | 32 |
| 35 const char kConfigRuleRandomIntervalTimeoutMin[] = "timeout_min"; | 33 const char kConfigRuleRandomIntervalTimeoutMin[] = "timeout_min"; |
| 36 const char kConfigRuleRandomIntervalTimeoutMax[] = "timeout_max"; | 34 const char kConfigRuleRandomIntervalTimeoutMax[] = "timeout_max"; |
| 37 | 35 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 54 const int kReactiveTraceRandomStartTimeMin = 60; | 52 const int kReactiveTraceRandomStartTimeMin = 60; |
| 55 const int kReactiveTraceRandomStartTimeMax = 120; | 53 const int kReactiveTraceRandomStartTimeMax = 120; |
| 56 | 54 |
| 57 } // namespace | 55 } // namespace |
| 58 | 56 |
| 59 namespace content { | 57 namespace content { |
| 60 | 58 |
| 61 BackgroundTracingRule::BackgroundTracingRule() | 59 BackgroundTracingRule::BackgroundTracingRule() |
| 62 : trigger_chance_(1.0), | 60 : trigger_chance_(1.0), |
| 63 trigger_delay_(-1), | 61 trigger_delay_(-1), |
| 64 stop_tracing_on_repeated_reactive_(false), | |
| 65 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} | 62 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} |
| 66 | 63 |
| 67 BackgroundTracingRule::BackgroundTracingRule(int trigger_delay) | 64 BackgroundTracingRule::BackgroundTracingRule(int trigger_delay) |
| 68 : trigger_chance_(1.0), | 65 : trigger_chance_(1.0), |
| 69 trigger_delay_(trigger_delay), | 66 trigger_delay_(trigger_delay), |
| 70 stop_tracing_on_repeated_reactive_(false), | |
| 71 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} | 67 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} |
| 72 | 68 |
| 73 BackgroundTracingRule::~BackgroundTracingRule() {} | 69 BackgroundTracingRule::~BackgroundTracingRule() {} |
| 74 | 70 |
| 75 bool BackgroundTracingRule::ShouldTriggerNamedEvent( | 71 bool BackgroundTracingRule::ShouldTriggerNamedEvent( |
| 76 const std::string& named_event) const { | 72 const std::string& named_event) const { |
| 77 return false; | 73 return false; |
| 78 } | 74 } |
| 79 | 75 |
| 80 int BackgroundTracingRule::GetTraceDelay() const { | 76 int BackgroundTracingRule::GetTraceDelay() const { |
| 81 return trigger_delay_; | 77 return trigger_delay_; |
| 82 } | 78 } |
| 83 | 79 |
| 84 void BackgroundTracingRule::IntoDict(base::DictionaryValue* dict) const { | 80 void BackgroundTracingRule::IntoDict(base::DictionaryValue* dict) const { |
| 85 DCHECK(dict); | 81 DCHECK(dict); |
| 86 if (trigger_chance_ < 1.0) | 82 if (trigger_chance_ < 1.0) |
| 87 dict->SetDouble(kConfigRuleTriggerChance, trigger_chance_); | 83 dict->SetDouble(kConfigRuleTriggerChance, trigger_chance_); |
| 88 | 84 |
| 89 if (trigger_delay_ != -1) | 85 if (trigger_delay_ != -1) |
| 90 dict->SetInteger(kConfigRuleTriggerDelay, trigger_delay_); | 86 dict->SetInteger(kConfigRuleTriggerDelay, trigger_delay_); |
| 91 | 87 |
| 92 if (stop_tracing_on_repeated_reactive_) { | |
| 93 dict->SetBoolean(kConfigRuleStopTracingOnRepeatedReactive, | |
| 94 stop_tracing_on_repeated_reactive_); | |
| 95 } | |
| 96 | |
| 97 if (category_preset_ != BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) { | 88 if (category_preset_ != BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) { |
| 98 dict->SetString( | 89 dict->SetString( |
| 99 kConfigCategoryKey, | 90 kConfigCategoryKey, |
| 100 BackgroundTracingConfigImpl::CategoryPresetToString(category_preset_)); | 91 BackgroundTracingConfigImpl::CategoryPresetToString(category_preset_)); |
| 101 } | 92 } |
| 102 } | 93 } |
| 103 | 94 |
| 104 void BackgroundTracingRule::Setup(const base::DictionaryValue* dict) { | 95 void BackgroundTracingRule::Setup(const base::DictionaryValue* dict) { |
| 105 dict->GetDouble(kConfigRuleTriggerChance, &trigger_chance_); | 96 dict->GetDouble(kConfigRuleTriggerChance, &trigger_chance_); |
| 106 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay_); | 97 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay_); |
| 107 dict->GetBoolean(kConfigRuleStopTracingOnRepeatedReactive, | |
| 108 &stop_tracing_on_repeated_reactive_); | |
| 109 } | 98 } |
| 110 | 99 |
| 111 namespace { | 100 namespace { |
| 112 | 101 |
| 113 class NamedTriggerRule : public BackgroundTracingRule { | 102 class NamedTriggerRule : public BackgroundTracingRule { |
| 114 private: | 103 private: |
| 115 NamedTriggerRule(const std::string& named_event) | 104 NamedTriggerRule(const std::string& named_event) |
| 116 : named_event_(named_event) {} | 105 : named_event_(named_event) {} |
| 117 | 106 |
| 118 public: | 107 public: |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 tracing_rule = TraceAtRandomIntervalsRule::Create(dict); | 398 tracing_rule = TraceAtRandomIntervalsRule::Create(dict); |
| 410 } | 399 } |
| 411 | 400 |
| 412 if (tracing_rule) | 401 if (tracing_rule) |
| 413 tracing_rule->Setup(dict); | 402 tracing_rule->Setup(dict); |
| 414 | 403 |
| 415 return tracing_rule; | 404 return tracing_rule; |
| 416 } | 405 } |
| 417 | 406 |
| 418 } // namespace content | 407 } // namespace content |
| OLD | NEW |