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

Unified Diff: base/trace_event/trace_log.h

Issue 2503473002: tracing: split out ThreadLocalEventBuffer
Patch Set: Created 4 years, 1 month 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 | « base/trace_event/trace_buffer.h ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_log.h
diff --git a/base/trace_event/trace_log.h b/base/trace_event/trace_log.h
index c86675177fe7000891be12632c63ed6c87f8bc92..cb8b68f9972bca408fae0738cf8de6e4718a1f22 100644
--- a/base/trace_event/trace_log.h
+++ b/base/trace_event/trace_log.h
@@ -10,6 +10,7 @@
#include <memory>
#include <string>
+#include <unordered_map>
#include <vector>
#include "base/atomicops.h"
@@ -17,6 +18,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/trace_config.h"
#include "base/trace_event/trace_event_impl.h"
@@ -31,6 +33,7 @@ class RefCountedString;
namespace trace_event {
+class ThreadLocalEventBuffer;
struct TraceCategory;
class TraceBuffer;
class TraceBufferChunk;
@@ -44,7 +47,8 @@ struct BASE_EXPORT TraceLogStatus {
uint32_t event_count;
};
-class BASE_EXPORT TraceLog : public MemoryDumpProvider {
+class BASE_EXPORT TraceLog : public MessageLoop::DestructionObserver,
+ public MemoryDumpProvider {
public:
// Argument passed to TraceLog::SetEnabled.
enum Mode : uint8_t {
@@ -68,6 +72,7 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
// Initializes the thread-local event buffer, if not already initialized and
// if the current thread supports that (has a message loop).
void InitializeThreadLocalEventBufferIfSupported();
+ void DestroyThreadLocalEventBufferIfSupported();
// See TraceConfig comments for details on how to control which categories
// will be traced. SetDisabled must be called distinctly for each mode that is
@@ -276,6 +281,15 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
uint64_t MangleEventId(uint64_t id);
+ // Functions to exchange chunks with the ThreadLocalEventBuffer. Ownership of
+ // |logged_events_| chunks is trasnferred to each thread and moved back to
+ // the TraceLog once the thread-local instance has filled the chunk, or upon
+ // flush (end of tracing).
+ std::unique_ptr<TraceBufferChunk> TakeChunk(size_t* chunk_index);
+ void ReturnChunk(std::unique_ptr<TraceBufferChunk>,
+ int generation,
+ size_t chunk_index);
+
// Exposed for unittesting:
// Allows deleting our singleton instance.
@@ -324,6 +338,20 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
#endif
private:
+ // Used to report the overhead of each thread-local instance to memory-infra.
+ class MemoryDumpProviderForThreadLocalBuffer : public MemoryDumpProvider {
+ public:
+ explicit MemoryDumpProviderForThreadLocalBuffer(ThreadLocalEventBuffer*);
+ ~MemoryDumpProviderForThreadLocalBuffer() override;
+
+ bool OnMemoryDump(const MemoryDumpArgs&, ProcessMemoryDump*) override;
+
+ private:
+ ThreadLocalEventBuffer* const thread_local_event_buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryDumpProviderForThreadLocalBuffer);
+ };
+
typedef unsigned int InternalTraceOptions;
FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
@@ -346,6 +374,9 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
bool OnMemoryDump(const MemoryDumpArgs& args,
ProcessMemoryDump* pmd) override;
+ // MessageLoop::DestructionObserver implementation.
+ void WillDestroyCurrentMessageLoop() override;
+
// Enable/disable each category group based on the current mode_,
// category_filter_ and event_filters_enabled_.
// Enable the category group in the recording mode if category_filter_ matches
@@ -363,7 +394,6 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
InternalTraceOptions GetInternalOptionsFromTraceConfig(
const TraceConfig& config);
- class ThreadLocalEventBuffer;
class OptionalAutoLock;
struct RegisteredAsyncObserver;
@@ -476,6 +506,13 @@ class BASE_EXPORT TraceLog : public MemoryDumpProvider {
// because we need to know the life time of the message loops.
hash_set<MessageLoop*> thread_message_loops_;
+ // Maps each MessageLoop to the corresponding MDP that is used to report the
+ // overhead of the ThreadLocalEventBuffer.
+ std::unordered_map<MessageLoop*,
+ std::unique_ptr<MemoryDumpProviderForThreadLocalBuffer>>
+ thread_local_mdps_;
+
+ // TODO get rid of this and use a locked writer. ////////////////////////////////////
// For events which can't be added into the thread local buffer, e.g. events
// from threads without a message loop.
std::unique_ptr<TraceBufferChunk> thread_shared_chunk_;
« no previous file with comments | « base/trace_event/trace_buffer.h ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698