summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authornduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 01:31:52 +0000
committernduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 01:31:52 +0000
commit37349bc71c662756c5a000ea2af49a4baac7b1ab (patch)
treeb6fbf698b8059aed354554f256e1ace1d3bc0803 /base
parent22a0fbd00117465e9d451cc4d1758e8050052661 (diff)
downloadchromium_src-37349bc71c662756c5a000ea2af49a4baac7b1ab.zip
chromium_src-37349bc71c662756c5a000ea2af49a4baac7b1ab.tar.gz
chromium_src-37349bc71c662756c5a000ea2af49a4baac7b1ab.tar.bz2
Add TRACE_EVENT_IS_NEW_TRACE as a way to snapshot objects at start of recording
R=dsinclair,enne NOTRY=True Android test failures are flake. Review URL: https://chromiumcodereview.appspot.com/15774010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/debug/trace_event.h22
-rw-r--r--base/debug/trace_event_impl.cc11
-rw-r--r--base/debug/trace_event_impl.h8
-rw-r--r--base/debug/trace_event_unittest.cc31
4 files changed, 71 insertions, 1 deletions
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index abd3901..aa4cc75 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -678,6 +678,22 @@
} \
} while (0)
+// Macro to efficiently determine, through polling, if a new trace has begun.
+#define TRACE_EVENT_IS_NEW_TRACE(ret) \
+ do { \
+ static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \
+ int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \
+ if (num_traces_recorded != -1 && \
+ num_traces_recorded != \
+ INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \
+ INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = \
+ num_traces_recorded; \
+ *ret = true; \
+ } else { \
+ *ret = false; \
+ } \
+ } while (0)
+
////////////////////////////////////////////////////////////////////////////////
// Implementation specific tracing API definitions.
@@ -694,6 +710,12 @@
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
base::debug::TraceLog::GetCategoryGroupEnabled
+// Get the number of times traces have been recorded. This is used to implement
+// the TRACE_EVENT_IS_NEW_TRACE facility.
+// unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED()
+#define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \
+ base::debug::TraceLog::GetInstance()->GetNumTracesRecorded
+
// Add a trace event to the platform tracing system.
// void TRACE_EVENT_API_ADD_TRACE_EVENT(
// char phase,
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 34f26f6..6e3516e 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -773,6 +773,7 @@ TraceLog::Options TraceLog::TraceOptionsFromString(const std::string& options) {
TraceLog::TraceLog()
: enable_count_(0),
+ num_traces_recorded_(0),
logged_events_(NULL),
dispatching_to_observer_list_(false),
watch_category_(NULL),
@@ -933,6 +934,8 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
return;
}
+ num_traces_recorded_++;
+
dispatching_to_observer_list_ = true;
FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_,
OnTraceLogWillEnable());
@@ -1007,6 +1010,13 @@ void TraceLog::SetDisabled() {
AddThreadNameMetadataEvents();
}
+int TraceLog::GetNumTracesRecorded() {
+ AutoLock lock(lock_);
+ if (enable_count_ == 0)
+ return -1;
+ return num_traces_recorded_;
+}
+
void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) {
enabled_state_observer_list_.AddObserver(listener);
}
@@ -1517,4 +1527,3 @@ ScopedTrace::~ScopedTrace() {
}
} // namespace trace_event_internal
-
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index da70b4b..b3be02a 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -317,6 +317,13 @@ class BASE_EXPORT TraceLog {
void SetDisabled();
bool IsEnabled() { return !!enable_count_; }
+ // 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
+ // recorded a trace. By watching for this number to increment, you can
+ // passively discover when a new trace has begun. This is then used to
+ // implement the TRACE_EVENT_IS_NEW_TRACE() primitive.
+ int GetNumTracesRecorded();
+
#if defined(OS_ANDROID)
void StartATrace();
void StopATrace();
@@ -526,6 +533,7 @@ class BASE_EXPORT TraceLog {
// This lock protects TraceLog member accesses from arbitrary threads.
Lock lock_;
int enable_count_;
+ int num_traces_recorded_;
NotificationCallback notification_callback_;
scoped_ptr<TraceBuffer> logged_events_;
EventCallback event_callback_;
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index 26e79c0..02bb899 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -905,6 +905,37 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) {
TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer);
}
+bool IsNewTrace() {
+ bool is_new_trace;
+ TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
+ return is_new_trace;
+}
+
+TEST_F(TraceEventTestFixture, NewTraceRecording) {
+ ManualTestSetUp();
+ ASSERT_FALSE(IsNewTrace());
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ TraceLog::RECORD_UNTIL_FULL);
+ // First call to IsNewTrace() should succeed. But, the second shouldn't.
+ ASSERT_TRUE(IsNewTrace());
+ ASSERT_FALSE(IsNewTrace());
+ EndTraceAndFlush();
+
+ // IsNewTrace() should definitely be false now.
+ ASSERT_FALSE(IsNewTrace());
+
+ // Start another trace. IsNewTrace() should become true again, briefly, as
+ // before.
+ TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
+ TraceLog::RECORD_UNTIL_FULL);
+ ASSERT_TRUE(IsNewTrace());
+ ASSERT_FALSE(IsNewTrace());
+
+ // Cleanup.
+ EndTraceAndFlush();
+}
+
+
// Test that categories work.
TEST_F(TraceEventTestFixture, Categories) {
ManualTestSetUp();