Index: base/trace_event/trace_config.cc |
diff --git a/base/trace_event/trace_config.cc b/base/trace_event/trace_config.cc |
index 653b1995f81a8397b2ebd474a79a81e7af658293..4a4c6d3fc57e412fc55deeba5ff7b07e4f1d2867 100644 |
--- a/base/trace_event/trace_config.cc |
+++ b/base/trace_event/trace_config.cc |
@@ -44,71 +44,34 @@ TraceConfig::TraceConfig() { |
TraceConfig::TraceConfig(const std::string& category_filter_string, |
const std::string& trace_options_string) { |
- if (!category_filter_string.empty()) { |
- std::vector<std::string> split; |
- std::vector<std::string>::iterator iter; |
- base::SplitString(category_filter_string, ',', &split); |
- for (iter = split.begin(); iter != split.end(); ++iter) { |
- std::string category = *iter; |
- // Ignore empty categories. |
- if (category.empty()) |
- continue; |
- // Synthetic delays are of the form 'DELAY(delay;option;option;...)'. |
- if (category.find(kSyntheticDelayCategoryFilterPrefix) == 0 && |
- category.at(category.size() - 1) == ')') { |
- category = category.substr( |
- strlen(kSyntheticDelayCategoryFilterPrefix), |
- category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1); |
- size_t name_length = category.find(';'); |
- if (name_length != std::string::npos && name_length > 0 && |
- name_length != category.size() - 1) { |
- synthetic_delays_.push_back(category); |
- } |
- } else if (category.at(0) == '-') { |
- // Excluded categories start with '-'. |
- // Remove '-' from category string. |
- category = category.substr(1); |
- excluded_categories_.push_back(category); |
- } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), |
- TRACE_DISABLED_BY_DEFAULT("")) == 0) { |
- disabled_categories_.push_back(category); |
- } else { |
- included_categories_.push_back(category); |
- } |
- } |
- } |
+ InitializeFromStrings(category_filter_string, trace_options_string); |
+} |
- record_mode_ = RECORD_UNTIL_FULL; |
- enable_sampling_ = false; |
- enable_systrace_ = false; |
- enable_argument_filter_ = false; |
- if(!trace_options_string.empty()) { |
- std::vector<std::string> split; |
- std::vector<std::string>::iterator iter; |
- base::SplitString(trace_options_string, ',', &split); |
- for (iter = split.begin(); iter != split.end(); ++iter) { |
- if (*iter == kRecordUntilFull) { |
- record_mode_ = RECORD_UNTIL_FULL; |
- } else if (*iter == kRecordContinuously) { |
- record_mode_ = RECORD_CONTINUOUSLY; |
- } else if (*iter == kTraceToConsole) { |
- record_mode_ = ECHO_TO_CONSOLE; |
- } else if (*iter == kRecordAsMuchAsPossible) { |
- record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
- } else if (*iter == kEnableSampling) { |
- enable_sampling_ = true; |
- } else if (*iter == kEnableSystrace) { |
- enable_systrace_ = true; |
- } else if (*iter == kEnableArgumentFilter) { |
- enable_argument_filter_ = true; |
- } |
- } |
+TraceConfig::TraceConfig(const std::string& category_filter_string, |
+ TraceRecordMode record_mode) { |
+ std::string trace_options_string; |
+ switch (record_mode) { |
+ case RECORD_UNTIL_FULL: |
+ trace_options_string = kRecordUntilFull; |
+ break; |
+ case RECORD_CONTINUOUSLY: |
+ trace_options_string = kRecordContinuously; |
+ break; |
+ case ECHO_TO_CONSOLE: |
dsinclair
2015/06/02 13:56:55
Put this one below RECORD_AS_MUCH_AS_POSSIBLE so w
Zhen Wang
2015/06/02 16:24:42
Done.
I also updated the order in the header file
|
+ trace_options_string = kTraceToConsole; |
+ break; |
+ case RECORD_AS_MUCH_AS_POSSIBLE: |
+ trace_options_string = kRecordAsMuchAsPossible; |
+ break; |
+ default: |
+ NOTREACHED(); |
} |
+ InitializeFromStrings(category_filter_string, trace_options_string); |
} |
TraceConfig::TraceConfig(const std::string& config_string) { |
if (!config_string.empty()) |
- Initialize(config_string); |
+ InitializeFromConfigString(config_string); |
else |
InitializeDefault(); |
} |
@@ -146,6 +109,34 @@ const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { |
return synthetic_delays_; |
} |
+TraceRecordMode TraceConfig::GetTraceRecordMode() const { |
+ return record_mode_; |
dsinclair
2015/06/02 13:56:55
These can all be implemented in the header.
Zhen Wang
2015/06/02 16:24:42
Done.
|
+} |
+ |
+bool TraceConfig::IsSamplingEnabled() const { |
+ return enable_sampling_; |
+} |
+ |
+bool TraceConfig::IsSystraceEnabled() const { |
+ return enable_systrace_; |
+} |
+ |
+bool TraceConfig::IsArgumentFilterEnabled() const { |
+ return enable_argument_filter_; |
+} |
+ |
+void TraceConfig::SetTraceRecordMode(TraceRecordMode mode) { |
+ record_mode_ = mode; |
+} |
+ |
+void TraceConfig::EnableSampling() { |
+ enable_sampling_ = true; |
+} |
+ |
+void TraceConfig::EnableSystrace() { |
+ enable_systrace_ = true; |
+} |
+ |
std::string TraceConfig::ToString() const { |
base::DictionaryValue dict; |
ToDict(dict); |
@@ -274,7 +265,7 @@ void TraceConfig::InitializeDefault() { |
excluded_categories_.push_back("*Test"); |
} |
-void TraceConfig::Initialize(const std::string& config_string) { |
+void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
scoped_ptr<base::Value> value(base::JSONReader::Read(config_string)); |
if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
InitializeDefault(); |
@@ -325,6 +316,71 @@ void TraceConfig::Initialize(const std::string& config_string) { |
SetSyntheticDelaysFromList(*category_list); |
} |
+void TraceConfig::InitializeFromStrings( |
+ const std::string& category_filter_string, |
+ const std::string& trace_options_string) { |
+ if (!category_filter_string.empty()) { |
+ std::vector<std::string> split; |
+ std::vector<std::string>::iterator iter; |
+ base::SplitString(category_filter_string, ',', &split); |
+ for (iter = split.begin(); iter != split.end(); ++iter) { |
+ std::string category = *iter; |
+ // Ignore empty categories. |
+ if (category.empty()) |
+ continue; |
+ // Synthetic delays are of the form 'DELAY(delay;option;option;...)'. |
+ if (category.find(kSyntheticDelayCategoryFilterPrefix) == 0 && |
+ category.at(category.size() - 1) == ')') { |
+ category = category.substr( |
+ strlen(kSyntheticDelayCategoryFilterPrefix), |
+ category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1); |
+ size_t name_length = category.find(';'); |
+ if (name_length != std::string::npos && name_length > 0 && |
+ name_length != category.size() - 1) { |
+ synthetic_delays_.push_back(category); |
+ } |
+ } else if (category.at(0) == '-') { |
+ // Excluded categories start with '-'. |
+ // Remove '-' from category string. |
+ category = category.substr(1); |
+ excluded_categories_.push_back(category); |
+ } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), |
+ TRACE_DISABLED_BY_DEFAULT("")) == 0) { |
+ disabled_categories_.push_back(category); |
+ } else { |
+ included_categories_.push_back(category); |
+ } |
+ } |
+ } |
+ |
+ record_mode_ = RECORD_UNTIL_FULL; |
+ enable_sampling_ = false; |
+ enable_systrace_ = false; |
+ enable_argument_filter_ = false; |
+ if(!trace_options_string.empty()) { |
+ std::vector<std::string> split; |
+ std::vector<std::string>::iterator iter; |
+ base::SplitString(trace_options_string, ',', &split); |
+ for (iter = split.begin(); iter != split.end(); ++iter) { |
+ if (*iter == kRecordUntilFull) { |
+ record_mode_ = RECORD_UNTIL_FULL; |
+ } else if (*iter == kRecordContinuously) { |
+ record_mode_ = RECORD_CONTINUOUSLY; |
+ } else if (*iter == kTraceToConsole) { |
+ record_mode_ = ECHO_TO_CONSOLE; |
+ } else if (*iter == kRecordAsMuchAsPossible) { |
+ record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
+ } else if (*iter == kEnableSampling) { |
+ enable_sampling_ = true; |
+ } else if (*iter == kEnableSystrace) { |
+ enable_systrace_ = true; |
+ } else if (*iter == kEnableArgumentFilter) { |
+ enable_argument_filter_ = true; |
+ } |
+ } |
+ } |
+} |
+ |
void TraceConfig::SetCategoriesFromIncludedList( |
const base::ListValue& included_list) { |
included_categories_.clear(); |
@@ -425,12 +481,30 @@ void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
} |
std::string TraceConfig::ToTraceOptionsString() const { |
- TraceOptions to; |
- to.record_mode = record_mode_; |
- to.enable_sampling = enable_sampling_; |
- to.enable_systrace = enable_systrace_; |
- to.enable_argument_filter = enable_argument_filter_; |
- return to.ToString(); |
+ std::string ret; |
+ switch (record_mode_) { |
+ case RECORD_UNTIL_FULL: |
+ ret = kRecordUntilFull; |
+ break; |
+ case RECORD_CONTINUOUSLY: |
+ ret = kRecordContinuously; |
+ break; |
+ case ECHO_TO_CONSOLE: |
+ ret = kTraceToConsole; |
+ break; |
+ case RECORD_AS_MUCH_AS_POSSIBLE: |
+ ret = kRecordAsMuchAsPossible; |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+ if (enable_sampling_) |
+ ret = ret + "," + kEnableSampling; |
+ if (enable_systrace_) |
+ ret = ret + "," + kEnableSystrace; |
+ if (enable_argument_filter_) |
+ ret = ret + "," + kEnableArgumentFilter; |
+ return ret; |
} |
void TraceConfig::WriteCategoryFilterString(const StringList& values, |