summaryrefslogtreecommitdiffstats
path: root/base/debug/trace_event_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/debug/trace_event_unittest.cc')
-rw-r--r--base/debug/trace_event_unittest.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index e7883d0..43297c6 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -99,6 +99,19 @@ class TraceEventTestFixture : public testing::Test {
base::Unretained(flush_complete_event)));
}
+ void FlushMonitoring() {
+ WaitableEvent flush_complete_event(false, false);
+ FlushMonitoring(&flush_complete_event);
+ flush_complete_event.Wait();
+ }
+
+ void FlushMonitoring(WaitableEvent* flush_complete_event) {
+ TraceLog::GetInstance()->FlushButLeaveBufferIntact(
+ base::Bind(&TraceEventTestFixture::OnTraceDataCollected,
+ base::Unretained(static_cast<TraceEventTestFixture*>(this)),
+ base::Unretained(flush_complete_event)));
+ }
+
virtual void SetUp() OVERRIDE {
const char* name = PlatformThread::GetName();
old_thread_name_ = name ? strdup(name) : NULL;
@@ -1765,6 +1778,56 @@ TEST_F(TraceEventTestFixture, TraceSamplingScope) {
EndTraceAndFlush();
}
+TEST_F(TraceEventTestFixture, TraceContinuousSampling) {
+ event_watch_notification_ = 0;
+ TraceLog::GetInstance()->SetEnabled(
+ CategoryFilter("*"),
+ TraceLog::Options(TraceLog::MONITOR_SAMPLING));
+
+ WaitableEvent* sampled = new WaitableEvent(false, false);
+ TraceLog::GetInstance()->InstallWaitableEventForSamplingTesting(
+ sampled);
+
+ TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "AAA");
+ sampled->Wait();
+ TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "BBB");
+ sampled->Wait();
+
+ FlushMonitoring();
+
+ // Make sure we can get the profiled data.
+ EXPECT_TRUE(FindNamePhase("AAA", "P"));
+ EXPECT_TRUE(FindNamePhase("BBB", "P"));
+
+ Clear();
+
+ TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "CCC");
+ sampled->Wait();
+ TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "DDD");
+ sampled->Wait();
+
+ FlushMonitoring();
+
+ // Make sure the profiled data is accumulated.
+ EXPECT_TRUE(FindNamePhase("AAA", "P"));
+ EXPECT_TRUE(FindNamePhase("BBB", "P"));
+ EXPECT_TRUE(FindNamePhase("CCC", "P"));
+ EXPECT_TRUE(FindNamePhase("DDD", "P"));
+
+ Clear();
+
+ TraceLog::GetInstance()->SetDisabled();
+
+ // Make sure disabling the continuous sampling thread clears
+ // the profiled data.
+ EXPECT_FALSE(FindNamePhase("AAA", "P"));
+ EXPECT_FALSE(FindNamePhase("BBB", "P"));
+ EXPECT_FALSE(FindNamePhase("CCC", "P"));
+ EXPECT_FALSE(FindNamePhase("DDD", "P"));
+
+ Clear();
+}
+
class MyData : public base::debug::ConvertableToTraceFormat {
public:
MyData() {}