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

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
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..21a092be25f4bace0c65c45bb7a31a8b1466d4e3 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,11 +541,15 @@ class BASE_EXPORT TraceLog {
int notification_;
};
+ class ThreadLocalEventBuffer;
+
TraceLog();
~TraceLog();
const unsigned char* GetCategoryGroupEnabledInternal(const char* name);
void AddMetadataEvents();
+ void EnableEchoToConsole(bool enable);
+
#if defined(OS_ANDROID)
void SendToATrace(char phase,
const char* category_group,
@@ -546,15 +566,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 FlushCurrentThreadAndContinue();
+
// 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 +588,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 /* EchoToConsoleContext* */ echo_to_console_context_;
// XORed with TraceID to make it unlikely to collide with other processes.
unsigned long long process_id_hash_;
@@ -575,7 +599,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 +610,16 @@ class BASE_EXPORT TraceLog {
CategoryFilter category_filter_;
+ ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
+
+ // Contains the message loops of threads that have had at least one event
+ // is added into the local event buffer.
dsinclair 2013/08/16 14:38:32 s/is//
Xianzhu 2013/08/16 19:41:03 Done.
+ 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);
};
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698