summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-16 18:36:17 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-16 18:36:17 +0000
commitdc5932de45a0d09367e631f7a413258acd1b84b2 (patch)
treea7153e16d54cf7eb10aece162a543def31572361 /base
parent8c9516f5c1a5c9edd443136f1e76ec36567fb664 (diff)
downloadchromium_src-dc5932de45a0d09367e631f7a413258acd1b84b2.zip
chromium_src-dc5932de45a0d09367e631f7a413258acd1b84b2.tar.gz
chromium_src-dc5932de45a0d09367e631f7a413258acd1b84b2.tar.bz2
Make a new TRACE macro that is slower but uses less memory
The current TRACE macros are designed for speed but it means they generate lots of code. I added a TRACE_EVENT_BINARY_EFFICENTx for those cases where memory is more important the speed. The issue here is I'm auto generating traces. The normal TRACE_EVENT0 ended up adding 90k+ to the release build. This new macro does not. This won't effect perf because these macros used through a wrapper that only gets used when certain command line flags are passed in. In other words the code that uses these macros is not called without the command line flags. BUG=176383 Review URL: https://chromiumcodereview.appspot.com/12278018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/debug/trace_event_impl.cc48
-rw-r--r--base/debug/trace_event_internal.h26
2 files changed, 74 insertions, 0 deletions
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 3c770c3..cbcf54b 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -821,3 +821,51 @@ void TraceLog::SetTimeOffset(TimeDelta offset) {
} // namespace debug
} // namespace base
+
+namespace trace_event_internal {
+
+ScopedTrace::ScopedTrace(
+ TRACE_EVENT_API_ATOMIC_WORD* event_uid, const char* name) {
+ category_enabled_ =
+ reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD(
+ *event_uid));
+ if (!category_enabled_) {
+ category_enabled_ = TRACE_EVENT_API_GET_CATEGORY_ENABLED("gpu");
+ TRACE_EVENT_API_ATOMIC_STORE(
+ *event_uid,
+ reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category_enabled_));
+ }
+ if (*category_enabled_) {
+ name_ = name;
+ TRACE_EVENT_API_ADD_TRACE_EVENT(
+ TRACE_EVENT_PHASE_BEGIN, // phase
+ category_enabled_, // category enabled
+ name, // name
+ 0, // id
+ 0, // num_args
+ NULL, // arg_names
+ NULL, // arg_types
+ NULL, // arg_values
+ TRACE_EVENT_FLAG_NONE); // flags
+ } else {
+ category_enabled_ = NULL;
+ }
+}
+
+ScopedTrace::~ScopedTrace() {
+ if (category_enabled_ && *category_enabled_) {
+ TRACE_EVENT_API_ADD_TRACE_EVENT(
+ TRACE_EVENT_PHASE_END, // phase
+ category_enabled_, // category enabled
+ name_, // name
+ 0, // id
+ 0, // num_args
+ NULL, // arg_names
+ NULL, // arg_types
+ NULL, // arg_values
+ TRACE_EVENT_FLAG_NONE); // flags
+ }
+}
+
+} // namespace trace_event_internal
+
diff --git a/base/debug/trace_event_internal.h b/base/debug/trace_event_internal.h
index 7cd56d0..2cdbe68 100644
--- a/base/debug/trace_event_internal.h
+++ b/base/debug/trace_event_internal.h
@@ -991,6 +991,32 @@ class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose {
Data data_;
};
+// Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
+class TRACE_EVENT_API_CLASS_EXPORT ScopedTrace {
+ public:
+ ScopedTrace(TRACE_EVENT_API_ATOMIC_WORD* event_uid, const char* name);
+ ~ScopedTrace();
+
+ private:
+ const unsigned char* category_enabled_;
+ const char* name_;
+};
+
+// A support macro for TRACE_EVENT_BINARY_EFFICIENTx
+#define INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED( \
+ category, name, ...) \
+ static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
+ trace_event_internal::ScopedTrace \
+ INTERNAL_TRACE_EVENT_UID(profileScope)( \
+ &INTERNAL_TRACE_EVENT_UID(atomic), name); \
+
+// This macro generates less code then TRACE_EVENT0 but is also
+// slower to execute when tracing is off. It should generally only be
+// used with code that is seldom executed or conditionally executed
+// when debugging.
+#define TRACE_EVENT_BINARY_EFFICIENT0(category, name) \
+ INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category, name)
+
} // namespace trace_event_internal
#endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_