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

Side by Side Diff: base/trace_event/allocation_context.cc

Issue 1340013002: Add thread-local allocation context for tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try to make MSVC happy Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 ditto (c)
Ruud van Asseldonk 2015/09/21 10:10:04 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/allocation_context.h"
6
7 #include "base/threading/thread_local_storage.h"
8
9 namespace base {
10 namespace trace_event {
11
12 // The generation counter is incremented every time capturing is enabled. This
13 // is required to discard leftover context when capturing is enabled a second
14 // time. The generation is monotonically increasing.
15 static int32_t g_capture_generation = 0;
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 Use StaticAtomicSequenceNumber here, so you reduce
Ruud van Asseldonk 2015/09/21 10:10:04 |StaticAtomicSequenceNumber| does not have the abi
Primiano Tucci (use gerrit) 2015/09/22 10:15:00 Well, of course (would defeat atomicity otherwise)
16 subtle::Atomic32 AllocationContextManager::capture_enabled_ = 0;
17 static ThreadLocalStorage::StaticSlot tls_alloc_ctx_mgr = TLS_INITIALIZER;
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 As per code style, static globals should be named
Ruud van Asseldonk 2015/09/21 10:10:05 Done.
18
19 Stack::Stack() {}
20 Stack::~Stack() {}
21
22 AllocationContextManager::AllocationContextManager(int32_t generation)
23 : generation_(generation) {}
24 AllocationContextManager::~AllocationContextManager() {}
25
26 void AllocationContextManager::set_capture_enabled(bool enabled) {
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 add a // static above this, i.e. // static void A
Ruud van Asseldonk 2015/09/21 10:10:05 Done.
27 if (!!subtle::NoBarrier_Load(&capture_enabled_) == enabled)
28 return;
29
30 // There is no memory barrier here for performance reasons, a little lag is
31 // not an issue.
32 subtle::NoBarrier_Store(&capture_enabled_, enabled);
33
34 // Assign a fresh generation number to this capture session.
35 if (enabled)
36 subtle::NoBarrier_AtomicIncrement(&g_capture_generation, 1);
37 }
38
39 void DestructAllocationContextManager(void* alloc_ctx_mgr) {
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 Add a comment specifying that this is only for the
Ruud van Asseldonk 2015/09/21 10:10:05 Done.
40 delete static_cast<AllocationContextManager*>(alloc_ctx_mgr);
41 }
42
43 AllocationContextManager* AllocationContextManager::GetInstance() {
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 Ditto, add // static
Ruud van Asseldonk 2015/09/21 10:10:04 Done.
44 AllocationContextManager* mgr = nullptr;
45
46 if (tls_alloc_ctx_mgr.initialized()) {
Primiano Tucci (use gerrit) 2015/09/18 16:10:00 Hmm I think this could be reworked to be a bit mor
Ruud van Asseldonk 2015/09/21 10:10:04 Done, but note that Simon requested that I merged
47 mgr = static_cast<AllocationContextManager*>(tls_alloc_ctx_mgr.Get());
48
49 // If there is an allocation context manager, it might be left over from a
50 // previous capture, tracing was disabled and enabled again. Context still
51 // in the manager belongs to the previous capture, so start over clean.
52 if (mgr->generation_ != subtle::NoBarrier_Load(&g_capture_generation)) {
53 delete mgr;
54 mgr = nullptr;
55 }
56 }
57
58 if (mgr == nullptr) {
59 mgr = new AllocationContextManager(
60 subtle::NoBarrier_Load(&g_capture_generation));
61 tls_alloc_ctx_mgr.Initialize(DestructAllocationContextManager);
62 tls_alloc_ctx_mgr.Set(static_cast<void*>(mgr));
63 }
64
65 return mgr;
66 }
67
68 AllocationContext AllocationContextManager::GetContext() const {
69 // TODO(ruuda): Implement this in a follow-up CL.
70 return AllocationContext();
71 }
72
73 } // namespace trace_event
74 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698