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

Side by Side Diff: base/trace_event/v2/trace_event.h

Issue 1947373002: Tracing V2 prototype [NOT FOR REVIEW] Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WORKS Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/trace_event/v2/scattered_buffer.cc ('k') | base/trace_event/v2/trace_event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_TRACE_EVENT_V2_TRACE_EVENT_H_
6 #define BASE_TRACE_EVENT_V2_TRACE_EVENT_H_
7
8 #include "base/base_export.h"
9 #include "base/macros.h"
10 #include "base/trace_event/common/proto/event.tracing-pb.h"
11
12 //TODO add thread checker. The handle should not be moved cross threads.
13
14 namespace base {
15 namespace trace_event {
16 namespace v2 {
17
18 class TraceEventHandle;
19
20 class BASE_EXPORT TraceEvent : public ::tracing::Event {
21 public:
22 TraceEvent();
23 ~TraceEvent() override;
24
25 void set_event_handle(TraceEventHandle* handle) { handle_ = handle; }
26
27 private:
28 TraceEventHandle* handle_;
29
30 DISALLOW_COPY_AND_ASSIGN(TraceEvent);
31 };
32
33 // Rationale of this handle: we want to return a (pointer to) Event to clients,
34 // so they can add extra properties (fill the proto fields).
35 // At the same time, we want to be in charge of its lifetime. More specifically
36 // an Event is valid for a given thread only until the next event is added.
37 // The functional purposes of this handle are:
38 // 1. Finalize the event when it goes out of scope from the caller.
39 // 2. Prevent bugs in the client code. If we did just return an Event* ptr,
40 // clients might be tempted to keep it cached. Which means that once the
41 // Event, that we own, is destroyed the client will have an invalid ptr
42 // causing all sort of hard-to-debug memory bugs.
43 class BASE_EXPORT TraceEventHandle {
44 public:
45 TraceEventHandle();
46 explicit TraceEventHandle(TraceEvent* event);
47 ~TraceEventHandle();
48
49 // Move-only type.
50 TraceEventHandle(TraceEventHandle&& other);
51 TraceEventHandle& operator=(TraceEventHandle&& other);
52
53 TraceEvent& operator*() const { return *event_; }
54 TraceEvent* operator->() const { return event_; }
55
56 private:
57 void Swap(TraceEventHandle* other);
58 friend class TraceEvent;
59 TraceEvent* event_;
60
61 DISALLOW_COPY_AND_ASSIGN(TraceEventHandle);
62 };
63
64 } // namespace v2
65 } // namespace trace_event
66 } // namespace base
67
68 #endif // BASE_TRACE_EVENT_V2_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « base/trace_event/v2/scattered_buffer.cc ('k') | base/trace_event/v2/trace_event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698