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

Unified Diff: base/debug/trace_event_impl.h

Issue 22962004: Thread-local trace-event buffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months 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_impl.h
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index be1a1049373e3fdc0a1a5b3048fcbd4330a49149..58cc644e4c8c2056a9a409a937a1a6812c8f7e2d 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/atomicops.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/gtest_prod_util.h"
@@ -20,6 +21,7 @@
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
+#include "base/threading/thread_local.h"
#include "base/timer/timer.h"
// Older style trace macros with explicit id and extra data
@@ -42,9 +44,21 @@
template <typename Type>
struct DefaultSingletonTraits;
+#if defined(COMPILER_GCC)
+namespace BASE_HASH_NAMESPACE {
+template <>
+struct hash<base::MessageLoop*> {
+ std::size_t operator()(base::MessageLoop* value) const {
+ return reinterpret_cast<std::size_t>(value);
+ }
+};
+}
+#endif
+
namespace base {
class WaitableEvent;
+class MessageLoop;
namespace debug {
@@ -108,6 +122,8 @@ class BASE_EXPORT TraceEvent {
std::string* out);
TimeTicks timestamp() const { return timestamp_; }
+ char phase() const { return phase_; }
+ int thread_id() const { return thread_id_; }
// Exposed for unittesting:
@@ -525,14 +541,19 @@ class BASE_EXPORT TraceLog {
int notification_;
};
+ class ThreadLocalEventBuffer;
+
TraceLog();
~TraceLog();
const unsigned char* GetCategoryGroupEnabledInternal(const char* name);
void AddMetadataEvents();
+ void EnableEchoToConsole(bool enable);
+ void EchoEventToConsoleIfEnabled(const TraceEvent& event);
+
#if defined(OS_ANDROID)
void SendToATrace(char phase,
- const char* category_group,
+ const unsigned char* category_group_enabled,
const char* name,
unsigned long long id,
int num_args,
@@ -546,15 +567,19 @@ class BASE_EXPORT TraceLog {
TraceBuffer* GetTraceBuffer();
- // TODO(nduca): switch to per-thread trace buffers to reduce thread
- // synchronization.
+ bool AddEventToMainBufferWhileLocked(const TraceEvent& trace_event,
+ NotificationHelper* notifier);
+ void FlushNextThreadOrFinish();
+ void DestroyThreadLocalEventBuffer();
+
// This lock protects TraceLog member accesses from arbitrary threads.
Lock lock_;
int enable_count_;
int num_traces_recorded_;
+ subtle::AtomicWord /* bool */ buffer_is_full_;
NotificationCallback notification_callback_;
scoped_ptr<TraceBuffer> logged_events_;
- EventCallback event_callback_;
+ subtle::AtomicWord /* EventCallback */ event_callback_;
bool dispatching_to_observer_list_;
std::vector<EnabledStateObserver*> enabled_state_observer_list_;
@@ -564,8 +589,8 @@ class BASE_EXPORT TraceLog {
base::hash_map<int, int> thread_sort_indices_;
base::hash_map<int, std::string> thread_names_;
- base::hash_map<int, std::stack<TimeTicks> > thread_event_start_times_;
- base::hash_map<std::string, int> thread_colors_;
+
+ subtle::AtomicWord echo_to_console_context_;
dsinclair 2013/08/13 21:04:42 nit: the other AtomicWords have a comment with the
Xianzhu 2013/08/14 21:28:33 Done.
// XORed with TraceID to make it unlikely to collide with other processes.
unsigned long long process_id_hash_;
@@ -575,7 +600,7 @@ class BASE_EXPORT TraceLog {
TimeDelta time_offset_;
// Allow tests to wake up when certain events occur.
- const unsigned char* watch_category_;
+ subtle::AtomicWord /* const unsigned char* */ watch_category_;
std::string watch_event_name_;
Options trace_options_;
@@ -586,6 +611,13 @@ class BASE_EXPORT TraceLog {
CategoryFilter category_filter_;
+ ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
+ base::hash_set<MessageLoop*> thread_message_loops_;
+
+ // Set when asynchronous Flush is in progress.
+ OutputCallback flush_output_callback_;
+ MessageLoop* flush_message_loop_;
+
DISALLOW_COPY_AND_ASSIGN(TraceLog);
};

Powered by Google App Engine
This is Rietveld 408576698