summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharaken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-28 06:04:28 +0000
committerharaken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-28 06:04:28 +0000
commit462ceb0a79acbd01421795bf2391643ca6d73f78 (patch)
tree5524511c651043c49986d3b5669b7d9305cc6c98
parentf5f22386b9413ce39b7e3cc7e718f652969f01e2 (diff)
downloadchromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.zip
chromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.tar.gz
chromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.tar.bz2
Implement sampling profiler (chromium side change)
Trace-viewer side change is here: https://codereview.appspot.com/39310043 Screenshot of the profiler: http://haraken.info/null/sampling_tracing.png Design document: https://docs.google.com/a/google.com/document/d/1j39sbA9ECTwFFlxbhSD1EvJnGfYeS5EUJ05yxuku6VY/edit TBR=phajdan.jr NOTRY=true Review URL: https://codereview.chromium.org/109933006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242671 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/debug/trace_event.h14
-rw-r--r--base/debug/trace_event_android.cc1
-rw-r--r--base/debug/trace_event_impl.cc38
-rw-r--r--base/debug/trace_event_impl.h31
-rw-r--r--base/debug/trace_event_unittest.cc92
-rw-r--r--base/test/trace_event_analyzer_unittest.cc1
-rw-r--r--chrome/browser/lifetime/application_lifetime.cc1
-rw-r--r--components/tracing/child_trace_message_filter.cc2
-rw-r--r--content/app/content_main_runner.cc1
-rw-r--r--content/browser/media/webrtc_browsertest.cc1
-rw-r--r--content/browser/tracing/tracing_controller_impl.cc14
-rw-r--r--content/browser/tracing/tracing_ui.cc93
-rw-r--r--content/common/gpu/client/gl_helper_unittests.cc1
13 files changed, 226 insertions, 64 deletions
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index 18feb33..b753963 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -725,12 +725,16 @@
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \
category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
+#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
+ *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
+ (base::debug::TraceLog::ENABLED_FOR_RECORDING | \
+ base::debug::TraceLog::ENABLED_FOR_EVENT_CALLBACK)
// Macro to efficiently determine if a given category group is enabled.
#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \
do { \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
*ret = true; \
} else { \
*ret = false; \
@@ -870,7 +874,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
#define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
do { \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
trace_event_internal::AddTraceEvent( \
phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \
@@ -883,7 +887,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
- if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
base::debug::TraceEventHandle h = trace_event_internal::AddTraceEvent( \
TRACE_EVENT_PHASE_COMPLETE, \
INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
@@ -899,7 +903,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
flags, ...) \
do { \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
trace_event_internal::TraceID trace_event_trace_id( \
id, &trace_event_flags); \
@@ -916,7 +920,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
category_group, name, id, thread_id, timestamp, flags, ...) \
do { \
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
trace_event_internal::TraceID trace_event_trace_id( \
id, &trace_event_flags); \
diff --git a/base/debug/trace_event_android.cc b/base/debug/trace_event_android.cc
index 567c48e..ed6b20d 100644
--- a/base/debug/trace_event_android.cc
+++ b/base/debug/trace_event_android.cc
@@ -97,6 +97,7 @@ void TraceLog::StartATrace() {
return;
}
SetEnabled(CategoryFilter(CategoryFilter::kDefaultCategoryFilterString),
+ base::debug::TraceLog::RECORDING_MODE,
RECORD_CONTINUOUSLY);
}
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index e774f62..03a4ae3 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -1094,7 +1094,7 @@ void TraceLog::ThreadLocalEventBuffer::FlushWhileLocked() {
trace_log_->lock_.AssertAcquired();
if (trace_log_->CheckGeneration(generation_)) {
- // Return the chunk to the buffer only if the generation matches,
+ // Return the chunk to the buffer only if the generation matches.
trace_log_->logged_events_->ReturnChunk(chunk_index_, chunk_.Pass());
}
// Otherwise this method may be called from the destructor, or TraceLog will
@@ -1107,7 +1107,7 @@ TraceLog* TraceLog::GetInstance() {
}
TraceLog::TraceLog()
- : enabled_(false),
+ : mode_(DISABLED),
num_traces_recorded_(0),
event_callback_(0),
dispatching_to_observer_list_(false),
@@ -1153,7 +1153,7 @@ TraceLog::TraceLog()
LOG(ERROR) << "Start " << switches::kTraceToConsole
<< " with CategoryFilter '" << filter << "'.";
- SetEnabled(CategoryFilter(filter), ECHO_TO_CONSOLE);
+ SetEnabled(CategoryFilter(filter), RECORDING_MODE, ECHO_TO_CONSOLE);
}
#endif
@@ -1192,8 +1192,12 @@ const char* TraceLog::GetCategoryGroupName(
void TraceLog::UpdateCategoryGroupEnabledFlag(int category_index) {
unsigned char enabled_flag = 0;
const char* category_group = g_category_groups[category_index];
- if (enabled_ && category_filter_.IsCategoryGroupEnabled(category_group))
+ if (mode_ == RECORDING_MODE &&
+ category_filter_.IsCategoryGroupEnabled(category_group))
enabled_flag |= ENABLED_FOR_RECORDING;
+ else if (mode_ == MONITORING_MODE &&
+ category_filter_.IsCategoryGroupEnabled(category_group))
+ enabled_flag |= ENABLED_FOR_MONITORING;
if (event_callback_ &&
event_callback_category_filter_.IsCategoryGroupEnabled(category_group))
enabled_flag |= ENABLED_FOR_EVENT_CALLBACK;
@@ -1256,6 +1260,7 @@ void TraceLog::GetKnownCategoryGroups(
}
void TraceLog::SetEnabled(const CategoryFilter& category_filter,
+ Mode mode,
Options options) {
std::vector<EnabledStateObserver*> observer_list;
{
@@ -1266,12 +1271,16 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
Options old_options = trace_options();
- if (enabled_) {
+ if (IsEnabled()) {
if (options != old_options) {
DLOG(ERROR) << "Attemting to re-enable tracing with a different "
<< "set of options.";
}
+ if (mode != mode_) {
+ DLOG(ERROR) << "Attemting to re-enable tracing with a different mode.";
+ }
+
category_filter_.Merge(category_filter);
UpdateCategoryGroupEnabledFlags();
return;
@@ -1283,7 +1292,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
return;
}
- enabled_ = true;
+ mode_ = mode;
if (options != old_options) {
subtle::NoBarrier_Store(&trace_options_, options);
@@ -1295,7 +1304,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
category_filter_ = CategoryFilter(category_filter);
UpdateCategoryGroupEnabledFlags();
- if ((options & ENABLE_SAMPLING) || (options & MONITOR_SAMPLING)) {
+ if (options & ENABLE_SAMPLING) {
sampling_thread_.reset(new TraceSamplingThread);
sampling_thread_->RegisterSampleBucket(
&g_trace_state[0],
@@ -1341,7 +1350,7 @@ void TraceLog::SetDisabled() {
void TraceLog::SetDisabledWhileLocked() {
lock_.AssertAcquired();
- if (!enabled_)
+ if (!IsEnabled())
return;
if (dispatching_to_observer_list_) {
@@ -1350,9 +1359,11 @@ void TraceLog::SetDisabledWhileLocked() {
return;
}
- enabled_ = false;
+ mode_ = DISABLED;
if (sampling_thread_.get()) {
+ base::ThreadRestrictions::SetIOAllowed(true);
+
// Stop the sampling thread.
sampling_thread_->Stop();
lock_.Release();
@@ -1360,6 +1371,8 @@ void TraceLog::SetDisabledWhileLocked() {
lock_.Acquire();
sampling_thread_handle_ = PlatformThreadHandle();
sampling_thread_.reset();
+
+ base::ThreadRestrictions::SetIOAllowed(false);
}
category_filter_.Clear();
@@ -1384,7 +1397,7 @@ void TraceLog::SetDisabledWhileLocked() {
int TraceLog::GetNumTracesRecorded() {
AutoLock lock(lock_);
- if (!enabled_)
+ if (!IsEnabled())
return -1;
return num_traces_recorded_;
}
@@ -1425,7 +1438,7 @@ TraceBuffer* TraceLog::CreateTraceBuffer() {
Options options = trace_options();
if (options & RECORD_CONTINUOUSLY)
return new TraceBufferRingBuffer(kTraceEventRingBufferChunks);
- else if (options & MONITOR_SAMPLING)
+ else if ((options & ENABLE_SAMPLING) && mode_ == MONITORING_MODE)
return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks);
else if (options & ECHO_TO_CONSOLE)
return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks);
@@ -1769,7 +1782,8 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
std::string console_message;
- if ((*category_group_enabled & ENABLED_FOR_RECORDING)) {
+ if (*category_group_enabled &
+ (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) {
OptionalAutoLock lock(lock_);
TraceEvent* trace_event = NULL;
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index 6179480..7dd4a00 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -354,6 +354,12 @@ class TraceSamplingThread;
class BASE_EXPORT TraceLog {
public:
+ enum Mode {
+ DISABLED = 0,
+ RECORDING_MODE,
+ MONITORING_MODE,
+ };
+
// Options determines how the trace buffer stores data.
enum Options {
// Record until the trace buffer is full.
@@ -366,21 +372,21 @@ class BASE_EXPORT TraceLog {
// Enable the sampling profiler in the recording mode.
ENABLE_SAMPLING = 1 << 2,
- // Enable the sampling profiler in the monitoring mode.
- MONITOR_SAMPLING = 1 << 3,
-
// Echo to console. Events are discarded.
- ECHO_TO_CONSOLE = 1 << 4,
+ ECHO_TO_CONSOLE = 1 << 3,
};
// The pointer returned from GetCategoryGroupEnabledInternal() points to a
// value with zero or more of the following bits. Used in this class only.
// The TRACE_EVENT macros should only use the value as a bool.
+ // These values must be in sync with macro values in TraceEvent.h in Blink.
enum CategoryGroupEnabledFlags {
- // Normal enabled flag for category groups enabled by SetEnabled().
+ // Category group enabled for the recording mode.
ENABLED_FOR_RECORDING = 1 << 0,
+ // Category group enabled for the monitoring mode.
+ ENABLED_FOR_MONITORING = 1 << 1,
// Category group enabled by SetEventCallbackEnabled().
- ENABLED_FOR_EVENT_CALLBACK = 1 << 1,
+ ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
};
static TraceLog* GetInstance();
@@ -400,12 +406,13 @@ class BASE_EXPORT TraceLog {
// See CategoryFilter comments for details on how to control what categories
// will be traced. If tracing has already been enabled, |category_filter| will
// be merged into the current category filter.
- void SetEnabled(const CategoryFilter& category_filter, Options options);
+ void SetEnabled(const CategoryFilter& category_filter,
+ Mode mode, Options options);
// Disables normal tracing for all categories.
void SetDisabled();
- bool IsEnabled() { return enabled_; }
+ bool IsEnabled() { return mode_ != DISABLED; }
// The number of times we have begun recording traces. If tracing is off,
// returns -1. If tracing is on, then it returns the number of times we have
@@ -426,7 +433,7 @@ class BASE_EXPORT TraceLog {
class EnabledStateObserver {
public:
// Called just after the tracing system becomes enabled, outside of the
- // |lock_|. TraceLog::IsEnabled() is true at this point.
+ // |lock_|. TraceLog::IsEnabled() is true at this point.
virtual void OnTraceLogEnabled() = 0;
// Called just after the tracing system disables, outside of the |lock_|.
@@ -591,9 +598,9 @@ class BASE_EXPORT TraceLog {
// by the Singleton class.
friend struct DefaultSingletonTraits<TraceLog>;
- // Enable/disable each category group based on the current enabled_,
+ // Enable/disable each category group based on the current mode_,
// category_filter_, event_callback_ and event_callback_category_filter_.
- // Enable the category group if enabled_ is true and category_filter_ matches
+ // Enable the category group in the enabled mode if category_filter_ matches
// the category group, or event_callback_ is not null and
// event_callback_category_filter_ matches the category group.
void UpdateCategoryGroupEnabledFlags();
@@ -652,7 +659,7 @@ class BASE_EXPORT TraceLog {
// and thread_colors_.
Lock thread_info_lock_;
int locked_line_;
- bool enabled_;
+ Mode mode_;
int num_traces_recorded_;
scoped_ptr<TraceBuffer> logged_events_;
subtle::AtomicWord /* EventCallback */ event_callback_;
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index aef2c43..d71b242 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -78,6 +78,7 @@ class TraceEventTestFixture : public testing::Test {
void BeginSpecificTrace(const std::string& filter) {
event_watch_notification_ = 0;
TraceLog::GetInstance()->SetEnabled(CategoryFilter(filter),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
}
@@ -853,6 +854,7 @@ void HighResSleepForTraceTest(base::TimeDelta elapsed) {
// Simple Test for emitting data and validating it was received.
TEST_F(TraceEventTestFixture, DataCaptured) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TraceWithAllMacroVariants(NULL);
@@ -876,6 +878,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) {
EXPECT_CALL(observer, OnTraceLogEnabled())
.Times(1);
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
@@ -887,6 +890,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) {
TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
testing::StrictMock<MockEnabledStateChangedObserver> observer;
@@ -897,6 +901,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) {
EXPECT_CALL(observer, OnTraceLogDisabled())
.Times(0);
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
@@ -909,8 +914,12 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) {
TEST_F(TraceEventTestFixture, EnabledObserverFiresOnFirstDisable) {
CategoryFilter cf_inc_all("*");
- TraceLog::GetInstance()->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL);
- TraceLog::GetInstance()->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(cf_inc_all,
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(cf_inc_all,
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
testing::StrictMock<MockEnabledStateChangedObserver> observer;
TraceLog::GetInstance()->AddEnabledStateObserver(&observer);
@@ -929,6 +938,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnFirstDisable) {
TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
MockEnabledStateChangedObserver observer;
@@ -965,6 +975,7 @@ TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) {
TraceLog::GetInstance()->AddEnabledStateObserver(&observer);
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
@@ -997,6 +1008,7 @@ TEST_F(TraceEventTestFixture, SelfRemovingObserver) {
EXPECT_EQ(1u, TraceLog::GetInstance()->GetObserverCountForTest());
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TraceLog::GetInstance()->SetDisabled();
// The observer removed itself on disable.
@@ -1012,6 +1024,7 @@ bool IsNewTrace() {
TEST_F(TraceEventTestFixture, NewTraceRecording) {
ASSERT_FALSE(IsNewTrace());
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
// First call to IsNewTrace() should succeed. But, the second shouldn't.
ASSERT_TRUE(IsNewTrace());
@@ -1024,6 +1037,7 @@ TEST_F(TraceEventTestFixture, NewTraceRecording) {
// Start another trace. IsNewTrace() should become true again, briefly, as
// before.
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
ASSERT_TRUE(IsNewTrace());
ASSERT_FALSE(IsNewTrace());
@@ -1080,6 +1094,7 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
included_categories.clear();
TraceLog::GetInstance()->SetEnabled(CategoryFilter("not_found823564786"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("cat1", "name", TRACE_EVENT_SCOPE_THREAD);
TRACE_EVENT_INSTANT0("cat2", "name", TRACE_EVENT_SCOPE_THREAD);
@@ -1090,6 +1105,7 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
included_categories.clear();
TraceLog::GetInstance()->SetEnabled(CategoryFilter("inc"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc", "name", TRACE_EVENT_SCOPE_THREAD);
TRACE_EVENT_INSTANT0("inc2", "name", TRACE_EVENT_SCOPE_THREAD);
@@ -1102,6 +1118,7 @@ TEST_F(TraceEventTestFixture, Categories) {
included_categories.clear();
TraceLog::GetInstance()->SetEnabled(
CategoryFilter("inc_wildcard_*,inc_wildchar_?_end"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc_wildcard_abc", "included",
TRACE_EVENT_SCOPE_THREAD);
@@ -1131,6 +1148,7 @@ TEST_F(TraceEventTestFixture, Categories) {
// Exclude nonexistent category -> all events
Clear();
TraceLog::GetInstance()->SetEnabled(CategoryFilter("-not_found823564786"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("cat1", "name", TRACE_EVENT_SCOPE_THREAD);
TRACE_EVENT_INSTANT0("cat2", "name", TRACE_EVENT_SCOPE_THREAD);
@@ -1143,6 +1161,7 @@ TEST_F(TraceEventTestFixture, Categories) {
// Exclude existent category -> only events of other categories
Clear();
TraceLog::GetInstance()->SetEnabled(CategoryFilter("-inc"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc", "name", TRACE_EVENT_SCOPE_THREAD);
TRACE_EVENT_INSTANT0("inc2", "name", TRACE_EVENT_SCOPE_THREAD);
@@ -1158,6 +1177,7 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
TraceLog::GetInstance()->SetEnabled(
CategoryFilter("-inc_wildcard_*,-inc_wildchar_?_end"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc_wildcard_abc", "not_inc",
TRACE_EVENT_SCOPE_THREAD);
@@ -1665,15 +1685,21 @@ TEST_F(TraceEventTestFixture, TracingIsLazy) {
TEST_F(TraceEventTestFixture, TraceEnableDisable) {
TraceLog* trace_log = TraceLog::GetInstance();
CategoryFilter cf_inc_all("*");
- trace_log->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(cf_inc_all,
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
trace_log->SetDisabled();
EXPECT_FALSE(trace_log->IsEnabled());
- trace_log->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(cf_inc_all,
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
const std::vector<std::string> empty;
- trace_log->SetEnabled(CategoryFilter(""), TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(CategoryFilter(""),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
trace_log->SetDisabled();
EXPECT_FALSE(trace_log->IsEnabled());
@@ -1683,15 +1709,21 @@ TEST_F(TraceEventTestFixture, TraceEnableDisable) {
TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
TraceLog* trace_log = TraceLog::GetInstance();
- trace_log->SetEnabled(CategoryFilter("foo,bar"), TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(CategoryFilter("foo,bar"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar"));
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz"));
- trace_log->SetEnabled(CategoryFilter("foo2"), TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(CategoryFilter("foo2"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo2"));
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz"));
// The "" becomes the default catergory set when applied.
- trace_log->SetEnabled(CategoryFilter(""), TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(CategoryFilter(""),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz"));
EXPECT_STREQ("-*Debug,-*Test",
@@ -1703,10 +1735,13 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz"));
trace_log->SetEnabled(CategoryFilter("-foo,-bar"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz"));
- trace_log->SetEnabled(CategoryFilter("moo"), TraceLog::RECORD_UNTIL_FULL);
+ trace_log->SetEnabled(CategoryFilter("moo"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz"));
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("moo"));
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo"));
@@ -1717,9 +1752,11 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
// Make sure disabled categories aren't cleared if we set in the second.
trace_log->SetEnabled(CategoryFilter("disabled-by-default-cc,foo"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("bar"));
trace_log->SetEnabled(CategoryFilter("disabled-by-default-gpu"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-cc"));
EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-gpu"));
@@ -1733,6 +1770,7 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
TEST_F(TraceEventTestFixture, TraceSampling) {
TraceLog::GetInstance()->SetEnabled(
CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::Options(TraceLog::RECORD_UNTIL_FULL |
TraceLog::ENABLE_SAMPLING));
@@ -1751,6 +1789,7 @@ TEST_F(TraceEventTestFixture, TraceSampling) {
TEST_F(TraceEventTestFixture, TraceSamplingScope) {
TraceLog::GetInstance()->SetEnabled(
CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::Options(TraceLog::RECORD_UNTIL_FULL |
TraceLog::ENABLE_SAMPLING));
@@ -1785,7 +1824,8 @@ TEST_F(TraceEventTestFixture, TraceSamplingScope) {
TEST_F(TraceEventTestFixture, TraceContinuousSampling) {
TraceLog::GetInstance()->SetEnabled(
CategoryFilter("*"),
- TraceLog::Options(TraceLog::MONITOR_SAMPLING));
+ base::debug::TraceLog::MONITORING_MODE,
+ TraceLog::Options(TraceLog::ENABLE_SAMPLING));
TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "AAA");
TraceLog::GetInstance()->WaitSamplingEventForTesting();
@@ -1843,6 +1883,7 @@ class MyData : public base::debug::ConvertableToTraceFormat {
TEST_F(TraceEventTestFixture, ConvertableTypes) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
scoped_refptr<ConvertableToTraceFormat> data(new MyData());
@@ -2046,6 +2087,7 @@ TEST_F(TraceEventCallbackTest, TraceEventCallback) {
TEST_F(TraceEventCallbackTest, TraceEventCallbackWhileFull) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_UNTIL_FULL);
do {
TRACE_EVENT_INSTANT0("all", "badger badger", TRACE_EVENT_SCOPE_GLOBAL);
@@ -2066,8 +2108,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording1) {
Callback);
TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL);
- TraceLog::GetInstance()->SetEnabled(
- CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL);
TraceLog::GetInstance()->SetEventCallbackDisabled();
@@ -2088,8 +2131,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording2) {
Callback);
TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL);
- TraceLog::GetInstance()->SetEnabled(
- CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL);
EndTraceAndFlush();
@@ -2106,8 +2150,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording2) {
TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording3) {
TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL);
- TraceLog::GetInstance()->SetEnabled(
- CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL);
TraceLog::GetInstance()->SetEventCallbackEnabled(CategoryFilter("callback"),
@@ -2128,8 +2173,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording3) {
TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording4) {
TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL);
- TraceLog::GetInstance()->SetEnabled(
- CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL);
TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL);
TraceLog::GetInstance()->SetEventCallbackEnabled(CategoryFilter("callback"),
@@ -2151,8 +2197,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecordingDuration) {
Callback);
{
TRACE_EVENT0("callback", "duration1");
- TraceLog::GetInstance()->SetEnabled(
- CategoryFilter("*"), TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT0("callback", "duration2");
EndTraceAndFlush();
TRACE_EVENT0("callback", "duration3");
@@ -2170,6 +2217,7 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecordingDuration) {
TEST_F(TraceEventTestFixture, TraceBufferRingBufferGetReturnChunk) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_CONTINUOUSLY);
TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer();
size_t capacity = buffer->Capacity();
@@ -2229,6 +2277,7 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferGetReturnChunk) {
TEST_F(TraceEventTestFixture, TraceBufferRingBufferHalfIteration) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_CONTINUOUSLY);
TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer();
size_t capacity = buffer->Capacity();
@@ -2256,6 +2305,7 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferHalfIteration) {
TEST_F(TraceEventTestFixture, TraceBufferRingBufferFullIteration) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::RECORD_CONTINUOUSLY);
TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer();
size_t capacity = buffer->Capacity();
@@ -2504,6 +2554,7 @@ TEST_F(TraceEventTestFixture, EchoToConsole) {
logging::SetLogMessageHandler(MockLogMessageHandler);
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::ECHO_TO_CONSOLE);
TRACE_EVENT_BEGIN0("a", "begin_end");
{
@@ -2539,6 +2590,7 @@ TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) {
logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent);
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
TraceLog::ECHO_TO_CONSOLE);
{
// This should not cause deadlock or infinite recursion.
diff --git a/base/test/trace_event_analyzer_unittest.cc b/base/test/trace_event_analyzer_unittest.cc
index 760def2..6cb0f36 100644
--- a/base/test/trace_event_analyzer_unittest.cc
+++ b/base/test/trace_event_analyzer_unittest.cc
@@ -47,6 +47,7 @@ void TraceEventAnalyzerTest::BeginTracing() {
buffer_.Start();
base::debug::TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter("*"),
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceLog::RECORD_UNTIL_FULL);
}
diff --git a/chrome/browser/lifetime/application_lifetime.cc b/chrome/browser/lifetime/application_lifetime.cc
index 43f68c0..60df0480 100644
--- a/chrome/browser/lifetime/application_lifetime.cc
+++ b/chrome/browser/lifetime/application_lifetime.cc
@@ -188,6 +188,7 @@ void StartShutdownTracing() {
command_line.GetSwitchValueASCII(switches::kTraceShutdown));
base::debug::TraceLog::GetInstance()->SetEnabled(
category_filter,
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceLog::RECORD_UNTIL_FULL);
}
TRACE_EVENT0("shutdown", "StartShutdownTracing");
diff --git a/components/tracing/child_trace_message_filter.cc b/components/tracing/child_trace_message_filter.cc
index d3875c7..847ff9a 100644
--- a/components/tracing/child_trace_message_filter.cc
+++ b/components/tracing/child_trace_message_filter.cc
@@ -61,6 +61,7 @@ void ChildTraceMessageFilter::OnBeginTracing(
TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter(category_filter_str),
+ base::debug::TraceLog::RECORDING_MODE,
static_cast<base::debug::TraceLog::Options>(options));
}
@@ -81,6 +82,7 @@ void ChildTraceMessageFilter::OnEnableMonitoring(
int options) {
TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter(category_filter_str),
+ base::debug::TraceLog::MONITORING_MODE,
static_cast<base::debug::TraceLog::Options>(options));
}
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
index 33bb2a3..f59f177 100644
--- a/content/app/content_main_runner.cc
+++ b/content/app/content_main_runner.cc
@@ -671,6 +671,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
command_line.GetSwitchValueASCII(switches::kTraceStartup));
base::debug::TraceLog::GetInstance()->SetEnabled(
category_filter,
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceLog::RECORD_UNTIL_FULL);
}
#if !defined(OS_ANDROID)
diff --git a/content/browser/media/webrtc_browsertest.cc b/content/browser/media/webrtc_browsertest.cc
index af7b087..f8b3c1b 100644
--- a/content/browser/media/webrtc_browsertest.cc
+++ b/content/browser/media/webrtc_browsertest.cc
@@ -417,6 +417,7 @@ IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, TracePerformanceDuringGetUserMedia) {
ExpectTitle("Running...");
base::debug::TraceLog* trace_log = base::debug::TraceLog::GetInstance();
trace_log->SetEnabled(base::debug::CategoryFilter("video"),
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceLog::ENABLE_SAMPLING);
// Check that we are indeed recording.
EXPECT_EQ(trace_log->GetNumTracesRecorded(), 1);
diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc
index ead4cf2..d639023 100644
--- a/content/browser/tracing/tracing_controller_impl.cc
+++ b/content/browser/tracing/tracing_controller_impl.cc
@@ -80,7 +80,7 @@ void TracingControllerImpl::ResultFile::OpenTask() {
void TracingControllerImpl::ResultFile::WriteTask(
const scoped_refptr<base::RefCountedString>& events_str_ptr) {
- if (!file_)
+ if (!file_ || !events_str_ptr->data().size())
return;
// If there is already a result in the file, then put a commma
@@ -173,7 +173,9 @@ bool TracingControllerImpl::EnableRecording(
// TODO(haraken): How to handle ENABLE_SYSTRACE?
TraceLog::GetInstance()->SetEnabled(
- base::debug::CategoryFilter(category_filter), trace_options);
+ base::debug::CategoryFilter(category_filter),
+ base::debug::TraceLog::RECORDING_MODE,
+ trace_options);
is_recording_ = true;
// Notify all child processes.
@@ -247,10 +249,11 @@ bool TracingControllerImpl::EnableMonitoring(
int monitoring_tracing_options = 0;
if (options & ENABLE_SAMPLING)
- monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING;
+ monitoring_tracing_options |= base::debug::TraceLog::ENABLE_SAMPLING;
TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter(category_filter),
+ base::debug::TraceLog::MONITORING_MODE,
static_cast<TraceLog::Options>(monitoring_tracing_options));
// Notify all child processes.
@@ -425,6 +428,11 @@ void TracingControllerImpl::AddTraceMessageFilter(
TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
TraceLog::GetInstance()->trace_options());
}
+ if (can_disable_monitoring()) {
+ trace_message_filter->SendEnableMonitoring(
+ TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
+ TraceLog::GetInstance()->trace_options());
+ }
}
void TracingControllerImpl::RemoveTraceMessageFilter(
diff --git a/content/browser/tracing/tracing_ui.cc b/content/browser/tracing/tracing_ui.cc
index e59f566..7b1f6e8 100644
--- a/content/browser/tracing/tracing_ui.cc
+++ b/content/browser/tracing/tracing_ui.cc
@@ -41,10 +41,10 @@ void OnGotCategories(const WebUIDataSource::GotDataCallback& callback,
callback.Run(res);
}
-void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback);
-
-bool OnBeginRecording(const std::string& data64,
- const WebUIDataSource::GotDataCallback& callback) {
+bool GetTracingOptions(const std::string& data64,
+ std::string* category_filter_string,
+ int* tracing_options)
+{
std::string data;
if (!base::Base64Decode(data64, &data)) {
LOG(ERROR) << "Options were not base64 encoded.";
@@ -62,13 +62,12 @@ bool OnBeginRecording(const std::string& data64,
return false;
}
- std::string category_filter_string;
bool use_system_tracing;
bool use_continuous_tracing;
bool use_sampling;
bool options_ok = true;
- options_ok &= options->GetString("categoryFilter", &category_filter_string);
+ options_ok &= options->GetString("categoryFilter", category_filter_string);
options_ok &= options->GetBoolean("useSystemTracing", &use_system_tracing);
options_ok &= options->GetBoolean("useContinuousTracing",
&use_continuous_tracing);
@@ -78,13 +77,24 @@ bool OnBeginRecording(const std::string& data64,
return false;
}
- int tracing_options = 0;
+ *tracing_options = 0;
if (use_system_tracing)
- tracing_options |= TracingController::ENABLE_SYSTRACE;
+ *tracing_options |= TracingController::ENABLE_SYSTRACE;
if (use_sampling)
- tracing_options |= TracingController::ENABLE_SAMPLING;
+ *tracing_options |= TracingController::ENABLE_SAMPLING;
if (use_continuous_tracing)
- tracing_options |= TracingController::RECORD_CONTINUOUSLY;
+ *tracing_options |= TracingController::RECORD_CONTINUOUSLY;
+ return true;
+}
+
+void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback);
+
+bool OnBeginRecording(const std::string& data64,
+ const WebUIDataSource::GotDataCallback& callback) {
+ std::string category_filter_string;
+ int tracing_options = 0;
+ if (!GetTracingOptions(data64, &category_filter_string, &tracing_options))
+ return false;
return TracingController::GetInstance()->EnableRecording(
category_filter_string,
@@ -120,13 +130,56 @@ void BeginReadingRecordingResult(
base::Bind(ReadRecordingResult, callback, path));
}
-bool OnBeginRequest(const std::string& path,
+void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback);
+
+bool OnEnableMonitoring(const std::string& data64,
+ const WebUIDataSource::GotDataCallback& callback) {
+ std::string category_filter_string;
+ int tracing_options = 0;
+ if (!GetTracingOptions(data64, &category_filter_string, &tracing_options))
+ return false;
+
+ return TracingController::GetInstance()->EnableMonitoring(
+ category_filter_string,
+ static_cast<TracingController::Options>(tracing_options),
+ base::Bind(OnMonitoringEnabledAck, callback));
+}
+
+void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) {
+ base::RefCountedString* res = new base::RefCountedString();
+ callback.Run(res);
+}
+
+void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) {
+ base::RefCountedString* res = new base::RefCountedString();
+ callback.Run(res);
+}
+
+void ReadMonitoringSnapshot(const WebUIDataSource::GotDataCallback& callback,
+ const base::FilePath& path) {
+ std::string tmp;
+ if (!base::ReadFileToString(path, &tmp))
+ LOG(ERROR) << "Failed to read file " << path.value();
+ base::DeleteFile(path, false);
+ callback.Run(base::RefCountedString::TakeString(&tmp));
+}
+
+void OnMonitoringSnapshotCaptured(
+ const WebUIDataSource::GotDataCallback& callback,
+ const base::FilePath& path) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(ReadMonitoringSnapshot, callback, path));
+}
+
+bool OnTracingRequest(const std::string& path,
const WebUIDataSource::GotDataCallback& callback) {
if (path == "json/categories") {
TracingController::GetInstance()->GetCategories(
base::Bind(OnGotCategories, callback));
return true;
}
+
const char* beginRecordingPath = "json/begin_recording?";
if (path.find(beginRecordingPath) == 0) {
std::string data = path.substr(strlen(beginRecordingPath));
@@ -140,6 +193,22 @@ bool OnBeginRequest(const std::string& path,
return TracingController::GetInstance()->DisableRecording(
base::FilePath(), base::Bind(BeginReadingRecordingResult, callback));
}
+
+ const char* enableMonitoringPath = "json/begin_monitoring?";
+ if (path.find(enableMonitoringPath) == 0) {
+ std::string data = path.substr(strlen(enableMonitoringPath));
+ return OnEnableMonitoring(data, callback);
+ }
+ if (path == "json/end_monitoring") {
+ return TracingController::GetInstance()->DisableMonitoring(
+ base::Bind(OnMonitoringDisabled, callback));
+ }
+ if (path == "json/capture_monitoring") {
+ TracingController::GetInstance()->CaptureMonitoringSnapshot(
+ base::FilePath(), base::Bind(OnMonitoringSnapshotCaptured, callback));
+ return true;
+ }
+
if (StartsWithASCII(path, "json/", true))
LOG(ERROR) << "Unhandled request to " << path;
return false;
@@ -163,7 +232,7 @@ TracingUI::TracingUI(WebUI* web_ui) : WebUIController(web_ui) {
source->SetJsonPath("strings.js");
source->SetDefaultResource(IDR_TRACING_HTML);
source->AddResourcePath("tracing.js", IDR_TRACING_JS);
- source->SetRequestFilter(base::Bind(OnBeginRequest));
+ source->SetRequestFilter(base::Bind(OnTracingRequest));
WebUIDataSource::Add(browser_context, source);
}
diff --git a/content/common/gpu/client/gl_helper_unittests.cc b/content/common/gpu/client/gl_helper_unittests.cc
index 2ec61ac..d642799 100644
--- a/content/common/gpu/client/gl_helper_unittests.cc
+++ b/content/common/gpu/client/gl_helper_unittests.cc
@@ -83,6 +83,7 @@ class GLHelperTest : public testing::Test {
void StartTracing(const std::string& filter) {
base::debug::TraceLog::GetInstance()->SetEnabled(
base::debug::CategoryFilter(filter),
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceLog::RECORD_UNTIL_FULL);
}