| 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"; |
| 26 | 28 |
| 27 const char kConfigRuleHistogramNameKey[] = "histogram_name"; | 29 const char kConfigRuleHistogramNameKey[] = "histogram_name"; |
| 28 const char kConfigRuleHistogramValueOldKey[] = "histogram_value"; | 30 const char kConfigRuleHistogramValueOldKey[] = "histogram_value"; |
| 29 const char kConfigRuleHistogramValue1Key[] = "histogram_lower_value"; | 31 const char kConfigRuleHistogramValue1Key[] = "histogram_lower_value"; |
| 30 const char kConfigRuleHistogramValue2Key[] = "histogram_upper_value"; | 32 const char kConfigRuleHistogramValue2Key[] = "histogram_upper_value"; |
| 31 const char kConfigRuleHistogramRepeatKey[] = "histogram_repeat"; | 33 const char kConfigRuleHistogramRepeatKey[] = "histogram_repeat"; |
| 32 | 34 |
| 33 const char kConfigRuleRandomIntervalTimeoutMin[] = "timeout_min"; | 35 const char kConfigRuleRandomIntervalTimeoutMin[] = "timeout_min"; |
| 34 const char kConfigRuleRandomIntervalTimeoutMax[] = "timeout_max"; | 36 const char kConfigRuleRandomIntervalTimeoutMax[] = "timeout_max"; |
| 35 | 37 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 52 const int kReactiveTraceRandomStartTimeMin = 60; | 54 const int kReactiveTraceRandomStartTimeMin = 60; |
| 53 const int kReactiveTraceRandomStartTimeMax = 120; | 55 const int kReactiveTraceRandomStartTimeMax = 120; |
| 54 | 56 |
| 55 } // namespace | 57 } // namespace |
| 56 | 58 |
| 57 namespace content { | 59 namespace content { |
| 58 | 60 |
| 59 BackgroundTracingRule::BackgroundTracingRule() | 61 BackgroundTracingRule::BackgroundTracingRule() |
| 60 : trigger_chance_(1.0), | 62 : trigger_chance_(1.0), |
| 61 trigger_delay_(-1), | 63 trigger_delay_(-1), |
| 64 stop_tracing_on_repeated_reactive_(false), |
| 62 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} | 65 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} |
| 63 | 66 |
| 64 BackgroundTracingRule::BackgroundTracingRule(int trigger_delay) | 67 BackgroundTracingRule::BackgroundTracingRule(int trigger_delay) |
| 65 : trigger_chance_(1.0), | 68 : trigger_chance_(1.0), |
| 66 trigger_delay_(trigger_delay), | 69 trigger_delay_(trigger_delay), |
| 70 stop_tracing_on_repeated_reactive_(false), |
| 67 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} | 71 category_preset_(BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) {} |
| 68 | 72 |
| 69 BackgroundTracingRule::~BackgroundTracingRule() {} | 73 BackgroundTracingRule::~BackgroundTracingRule() {} |
| 70 | 74 |
| 71 bool BackgroundTracingRule::ShouldTriggerNamedEvent( | 75 bool BackgroundTracingRule::ShouldTriggerNamedEvent( |
| 72 const std::string& named_event) const { | 76 const std::string& named_event) const { |
| 73 return false; | 77 return false; |
| 74 } | 78 } |
| 75 | 79 |
| 76 int BackgroundTracingRule::GetTraceDelay() const { | 80 int BackgroundTracingRule::GetTraceDelay() const { |
| 77 return trigger_delay_; | 81 return trigger_delay_; |
| 78 } | 82 } |
| 79 | 83 |
| 80 void BackgroundTracingRule::IntoDict(base::DictionaryValue* dict) const { | 84 void BackgroundTracingRule::IntoDict(base::DictionaryValue* dict) const { |
| 81 DCHECK(dict); | 85 DCHECK(dict); |
| 82 if (trigger_chance_ < 1.0) | 86 if (trigger_chance_ < 1.0) |
| 83 dict->SetDouble(kConfigRuleTriggerChance, trigger_chance_); | 87 dict->SetDouble(kConfigRuleTriggerChance, trigger_chance_); |
| 84 | 88 |
| 85 if (trigger_delay_ != -1) | 89 if (trigger_delay_ != -1) |
| 86 dict->SetInteger(kConfigRuleTriggerDelay, trigger_delay_); | 90 dict->SetInteger(kConfigRuleTriggerDelay, trigger_delay_); |
| 87 | 91 |
| 92 if (stop_tracing_on_repeated_reactive_) { |
| 93 dict->SetBoolean(kConfigRuleStopTracingOnRepeatedReactive, |
| 94 stop_tracing_on_repeated_reactive_); |
| 95 } |
| 96 |
| 88 if (category_preset_ != BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) { | 97 if (category_preset_ != BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET) { |
| 89 dict->SetString( | 98 dict->SetString( |
| 90 kConfigCategoryKey, | 99 kConfigCategoryKey, |
| 91 BackgroundTracingConfigImpl::CategoryPresetToString(category_preset_)); | 100 BackgroundTracingConfigImpl::CategoryPresetToString(category_preset_)); |
| 92 } | 101 } |
| 93 } | 102 } |
| 94 | 103 |
| 95 void BackgroundTracingRule::Setup(const base::DictionaryValue* dict) { | 104 void BackgroundTracingRule::Setup(const base::DictionaryValue* dict) { |
| 96 dict->GetDouble(kConfigRuleTriggerChance, &trigger_chance_); | 105 dict->GetDouble(kConfigRuleTriggerChance, &trigger_chance_); |
| 97 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay_); | 106 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay_); |
| 107 dict->GetBoolean(kConfigRuleStopTracingOnRepeatedReactive, |
| 108 &stop_tracing_on_repeated_reactive_); |
| 98 } | 109 } |
| 99 | 110 |
| 100 namespace { | 111 namespace { |
| 101 | 112 |
| 102 class NamedTriggerRule : public BackgroundTracingRule { | 113 class NamedTriggerRule : public BackgroundTracingRule { |
| 103 private: | 114 private: |
| 104 NamedTriggerRule(const std::string& named_event) | 115 NamedTriggerRule(const std::string& named_event) |
| 105 : named_event_(named_event) {} | 116 : named_event_(named_event) {} |
| 106 | 117 |
| 107 public: | 118 public: |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 tracing_rule = TraceAtRandomIntervalsRule::Create(dict); | 409 tracing_rule = TraceAtRandomIntervalsRule::Create(dict); |
| 399 } | 410 } |
| 400 | 411 |
| 401 if (tracing_rule) | 412 if (tracing_rule) |
| 402 tracing_rule->Setup(dict); | 413 tracing_rule->Setup(dict); |
| 403 | 414 |
| 404 return tracing_rule; | 415 return tracing_rule; |
| 405 } | 416 } |
| 406 | 417 |
| 407 } // namespace content | 418 } // namespace content |
| OLD | NEW |