Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: base/debug/trace_event_internal.h

Issue 11464005: Add trace event Pepper API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Enable NaCl compilation Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/debug/trace_event_internal.h
diff --git a/base/debug/trace_event.h b/base/debug/trace_event_internal.h
similarity index 93%
copy from base/debug/trace_event.h
copy to base/debug/trace_event_internal.h
index 07863ad997b3d56fd46f8033a0775f08b56b279a..3ef0767e3c2a6452b8cf0e60dc400063bfc4c0ac 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event_internal.h
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This header is designed to give you trace_event macros without specifying
+// This header file defines the set of trace_event macros without specifying
// how the events actually get collected and stored. If you need to expose trace
-// event to some other universe, you can copy-and-paste this file,
-// implement the TRACE_EVENT_API macros, and do any other necessary fixup for
-// the target platform. The end result is that multiple libraries can funnel
-// events through to a shared trace event collector.
+// events to some other universe, you can copy-and-paste this file as well as
+// trace_event.h, modifying the macros contained there as necessary for the
+// target platform. The end result is that multiple libraries can funnel events
+// through to a shared trace event collector.
// Trace events are for tracking application performance and resource usage.
// Macros are provided to track:
@@ -148,15 +148,11 @@
// and resolving the category.
-#ifndef BASE_DEBUG_TRACE_EVENT_H_
-#define BASE_DEBUG_TRACE_EVENT_H_
+#ifndef BASE_DEBUG_TRACE_EVENT_INTERNAL_H_
+#define BASE_DEBUG_TRACE_EVENT_INTERNAL_H_
#include <string>
-#include "base/atomicops.h"
-#include "base/debug/trace_event_impl.h"
-#include "build/build_config.h"
-
// By default, const char* argument values are assumed to have long-lived scope
// and will not be copied. Use this macro to force a const char* to be copied.
#define TRACE_STR_COPY(str) \
@@ -564,41 +560,6 @@
arg1_name, arg1_val, arg2_name, arg2_val)
-////////////////////////////////////////////////////////////////////////////////
-// Implementation specific tracing API definitions.
-
-// Get a pointer to the enabled state of the given trace category. Only
-// long-lived literal strings should be given as the category name. The returned
-// pointer can be held permanently in a local static for example. If the
-// unsigned char is non-zero, tracing is enabled. If tracing is enabled,
-// TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled
-// between the load of the tracing state and the call to
-// TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out
-// for best performance when tracing is disabled.
-// const unsigned char*
-// TRACE_EVENT_API_GET_CATEGORY_ENABLED(const char* category_name)
-#define TRACE_EVENT_API_GET_CATEGORY_ENABLED \
- base::debug::TraceLog::GetCategoryEnabled
-
-// Add a trace event to the platform tracing system. Returns thresholdBeginId
-// for use in a corresponding end TRACE_EVENT_API_ADD_TRACE_EVENT call.
-// int TRACE_EVENT_API_ADD_TRACE_EVENT(
-// char phase,
-// const unsigned char* category_enabled,
-// const char* name,
-// unsigned long long id,
-// int num_args,
-// const char** arg_names,
-// const unsigned char* arg_types,
-// const unsigned long long* arg_values,
-// int threshold_begin_id,
-// long long threshold,
-// unsigned char flags)
-#define TRACE_EVENT_API_ADD_TRACE_EVENT \
- base::debug::TraceLog::GetInstance()->AddTraceEvent
-
-////////////////////////////////////////////////////////////////////////////////
-
// Implementation detail: trace event macros create temporary variables
// to keep instrumentation overhead low. These macros give each temporary
// variable a unique name based on the line number to prevent name collissions.
@@ -614,15 +575,15 @@
// even when the unsigned char* points to garbage data (which may be the case
// on processors without cache coherency).
#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \
- static base::subtle::AtomicWord INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
- const uint8* INTERNAL_TRACE_EVENT_UID(catstatic) = \
- reinterpret_cast<const uint8*>( \
- base::subtle::NoBarrier_Load(&INTERNAL_TRACE_EVENT_UID(atomic))); \
+ static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
+ const unsigned char* INTERNAL_TRACE_EVENT_UID(catstatic) = \
+ reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD( \
+ INTERNAL_TRACE_EVENT_UID(atomic))); \
if (!INTERNAL_TRACE_EVENT_UID(catstatic)) { \
INTERNAL_TRACE_EVENT_UID(catstatic) = \
TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \
- base::subtle::NoBarrier_Store(&INTERNAL_TRACE_EVENT_UID(atomic), \
- reinterpret_cast<base::subtle::AtomicWord>( \
+ TRACE_EVENT_API_ATOMIC_STORE(INTERNAL_TRACE_EVENT_UID(atomic), \
+ reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \
INTERNAL_TRACE_EVENT_UID(catstatic))); \
}
@@ -931,7 +892,7 @@ static inline int AddTraceEvent(char phase,
}
// Used by TRACE_EVENTx macro. Do not use directly.
-class BASE_EXPORT TraceEndOnScopeClose {
+class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose {
public:
// Note: members of data_ intentionally left uninitialized. See Initialize.
TraceEndOnScopeClose() : p_data_(NULL) {}
@@ -941,11 +902,26 @@ class BASE_EXPORT TraceEndOnScopeClose {
}
void Initialize(const unsigned char* category_enabled,
- const char* name);
+ const char* name) {
+ data_.category_enabled = category_enabled;
+ data_.name = name;
+ p_data_ = &data_;
+ }
+
private:
// Add the end event if the category is still enabled.
- void AddEventIfEnabled();
+ void AddEventIfEnabled() {
+ // Only called when p_data_ is non-null.
+ if (*p_data_->category_enabled) {
+ TRACE_EVENT_API_ADD_TRACE_EVENT(
jbauman 2012/12/14 00:36:07 Hopefully this won't increase the chrome binary si
elijahtaylor1 2012/12/18 20:40:31 Good point, I just measured and it looks like this
+ TRACE_EVENT_PHASE_END,
+ p_data_->category_enabled,
+ p_data_->name, kNoEventId,
+ kZeroNumArgs, NULL, NULL, NULL,
+ kNoThreshholdBeginId, kNoThresholdValue, TRACE_EVENT_FLAG_NONE);
+ }
+ }
// This Data struct workaround is to avoid initializing all the members
// in Data during construction of this object, since this object is always
@@ -961,7 +937,7 @@ class BASE_EXPORT TraceEndOnScopeClose {
};
// Used by TRACE_EVENTx macro. Do not use directly.
-class BASE_EXPORT TraceEndOnScopeCloseThreshold {
+class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeCloseThreshold {
public:
// Note: members of data_ intentionally left uninitialized. See Initialize.
TraceEndOnScopeCloseThreshold() : p_data_(NULL) {}
@@ -975,11 +951,28 @@ class BASE_EXPORT TraceEndOnScopeCloseThreshold {
void Initialize(const unsigned char* category_enabled,
const char* name,
int threshold_begin_id,
- long long threshold);
+ long long threshold) {
+ data_.category_enabled = category_enabled;
+ data_.name = name;
+ data_.threshold_begin_id = threshold_begin_id;
+ data_.threshold = threshold;
+ p_data_ = &data_;
+ }
private:
// Add the end event if the category is still enabled.
- void AddEventIfEnabled();
+ void AddEventIfEnabled() {
+ // Only called when p_data_ is non-null.
+ if (*p_data_->category_enabled) {
+ TRACE_EVENT_API_ADD_TRACE_EVENT(
+ TRACE_EVENT_PHASE_END,
+ p_data_->category_enabled,
+ p_data_->name, kNoEventId,
+ kZeroNumArgs, NULL, NULL, NULL,
+ p_data_->threshold_begin_id, p_data_->threshold,
+ TRACE_EVENT_FLAG_NONE);
+ }
+ }
// This Data struct workaround is to avoid initializing all the members
// in Data during construction of this object, since this object is always
@@ -998,4 +991,4 @@ class BASE_EXPORT TraceEndOnScopeCloseThreshold {
} // namespace trace_event_internal
-#endif // BASE_DEBUG_TRACE_EVENT_H_
+#endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_

Powered by Google App Engine
This is Rietveld 408576698