Index: base/debug/trace_event_impl.cc |
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
index 93ec6fe29974f891c499c7c6a03645bc645198df..c5c3a2c50de9f51b4d7a6d74cdaf9485be6078b2 100644 |
--- a/base/debug/trace_event_impl.cc |
+++ b/base/debug/trace_event_impl.cc |
@@ -58,6 +58,13 @@ namespace { |
// trace. |
const int kOverheadReportThresholdInMicroseconds = 50; |
+// String options that can be used to initialize TraceOptions. |
+const char kRecordUntilFull[] = "record-until-full"; |
+const char kRecordContinuously[] = "record-continuously"; |
+const char kTraceToConsole[] = "trace-to-console"; |
+const char kEnableSampling[] = "enable-sampling"; |
+const char kEnableSystrace[] = "enable-systrace"; |
+ |
// Controls the number of trace events we will buffer in-memory |
// before throwing them away. |
const size_t kTraceBufferChunkSize = TraceBufferChunk::kTraceBufferChunkSize; |
@@ -970,6 +977,57 @@ TraceBucketData::~TraceBucketData() { |
//////////////////////////////////////////////////////////////////////////////// |
// |
+// TraceOptions |
+// |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+TraceOptions::TraceOptions(StringPiece options) |
+ : record_mode(RECORD_UNTIL_FULL), |
+ enable_sampling(false), |
+ enable_systrace(false) { |
+ std::vector<std::string> split; |
+ std::vector<std::string>::iterator iter; |
+ |
+ base::SplitString(options.as_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 == kEnableSampling) { |
+ enable_sampling = true; |
+ } else if (*iter == kEnableSystrace) { |
+ enable_systrace = true; |
+ } |
+ } |
+} |
+ |
+std::string TraceOptions::ToString() const { |
+ 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; |
+ default: |
+ NOTREACHED(); |
+ } |
+ if (enable_sampling) |
+ ret = ret + "," + kEnableSampling; |
+ if (enable_systrace) |
+ ret = ret + "," + kEnableSystrace; |
+ return ret; |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// |
// TraceLog |
// |
//////////////////////////////////////////////////////////////////////////////// |
@@ -1175,7 +1233,9 @@ TraceLog::TraceLog() |
LOG(ERROR) << "Start " << switches::kTraceToConsole |
<< " with CategoryFilter '" << filter << "'."; |
- SetEnabled(CategoryFilter(filter), RECORDING_MODE, ECHO_TO_CONSOLE); |
+ SetEnabled(CategoryFilter(filter), |
+ RECORDING_MODE, |
+ TraceOptions(TraceOptions::ECHO_TO_CONSOLE)); |
} |
#endif |
@@ -1325,7 +1385,7 @@ void TraceLog::GetKnownCategoryGroups( |
void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
Mode mode, |
- Options options) { |
+ TraceOptions options) { |
std::vector<EnabledStateObserver*> observer_list; |
{ |
AutoLock lock(lock_); |
@@ -1333,10 +1393,13 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
// Can't enable tracing when Flush() is in progress. |
DCHECK(!flush_message_loop_proxy_.get()); |
- Options old_options = trace_options(); |
+ InternalTraceOptions new_options = |
+ GetInternalOptionsFromTraceOptions(options); |
+ |
+ InternalTraceOptions old_options = trace_options(); |
if (IsEnabled()) { |
- if (options != old_options) { |
+ if (new_options != old_options) { |
DLOG(ERROR) << "Attempting to re-enable tracing with a different " |
<< "set of options."; |
} |
@@ -1358,8 +1421,8 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
mode_ = mode; |
- if (options != old_options) { |
- subtle::NoBarrier_Store(&trace_options_, options); |
+ if (new_options != old_options) { |
+ subtle::NoBarrier_Store(&trace_options_, new_options); |
UseNextTraceBuffer(); |
} |
@@ -1369,7 +1432,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
UpdateCategoryGroupEnabledFlags(); |
UpdateSyntheticDelaysFromCategoryFilter(); |
- if (options & ENABLE_SAMPLING) { |
+ if (new_options & ENABLE_SAMPLING) { |
sampling_thread_.reset(new TraceSamplingThread); |
sampling_thread_->RegisterSampleBucket( |
&g_trace_state[0], |
@@ -1402,11 +1465,41 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
} |
} |
+TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions( |
+ const TraceOptions& options) { |
+ InternalTraceOptions ret = options.enable_sampling ? ENABLE_SAMPLING : NONE; |
+ switch (options.record_mode) { |
+ case TraceOptions::RECORD_UNTIL_FULL: |
+ return ret | RECORD_UNTIL_FULL; |
+ case TraceOptions::RECORD_CONTINUOUSLY: |
+ return ret | RECORD_CONTINUOUSLY; |
+ case TraceOptions::ECHO_TO_CONSOLE: |
+ return ret | ECHO_TO_CONSOLE; |
+ } |
+ NOTREACHED(); |
+ return NONE; |
+} |
+ |
CategoryFilter TraceLog::GetCurrentCategoryFilter() { |
AutoLock lock(lock_); |
return category_filter_; |
} |
+TraceOptions TraceLog::GetCurrentTraceOptions() const { |
+ TraceOptions ret; |
+ InternalTraceOptions option = trace_options(); |
+ ret.enable_sampling = (option & ENABLE_SAMPLING) != 0; |
+ if (option & RECORD_UNTIL_FULL) |
+ ret.record_mode = TraceOptions::RECORD_UNTIL_FULL; |
+ else if (option & RECORD_CONTINUOUSLY) |
+ ret.record_mode = TraceOptions::RECORD_CONTINUOUSLY; |
+ else if (option & ECHO_TO_CONSOLE) |
+ ret.record_mode = TraceOptions::ECHO_TO_CONSOLE; |
+ else |
+ NOTREACHED(); |
+ return ret; |
+} |
+ |
void TraceLog::SetDisabled() { |
AutoLock lock(lock_); |
SetDisabledWhileLocked(); |
@@ -1496,7 +1589,7 @@ bool TraceLog::BufferIsFull() const { |
} |
TraceBuffer* TraceLog::CreateTraceBuffer() { |
- Options options = trace_options(); |
+ InternalTraceOptions options = trace_options(); |
if (options & RECORD_CONTINUOUSLY) |
return new TraceBufferRingBuffer(kTraceEventRingBufferChunks); |
else if ((options & ENABLE_SAMPLING) && mode_ == MONITORING_MODE) |