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

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

Issue 2253973003: Add an explicit way of making IDs local or global (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/blame_context.h" 5 #include "base/trace_event/blame_context.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 10
(...skipping 17 matching lines...) Expand all
28 weak_factory_(this) { 28 weak_factory_(this) {
29 DCHECK(!parent_context || !std::strcmp(name_, parent_context->name())) 29 DCHECK(!parent_context || !std::strcmp(name_, parent_context->name()))
30 << "Parent blame context must have the same name"; 30 << "Parent blame context must have the same name";
31 } 31 }
32 32
33 BlameContext::~BlameContext() { 33 BlameContext::~BlameContext() {
34 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
35 DCHECK(WasInitialized()); 35 DCHECK(WasInitialized());
36 TRACE_EVENT_API_ADD_TRACE_EVENT( 36 TRACE_EVENT_API_ADD_TRACE_EVENT(
37 TRACE_EVENT_PHASE_DELETE_OBJECT, category_group_enabled_, type_, scope_, 37 TRACE_EVENT_PHASE_DELETE_OBJECT, category_group_enabled_, type_, scope_,
38 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); 38 id_, 0, nullptr, nullptr, nullptr, nullptr,
39 TRACE_EVENT_FLAG_HAS_LOCAL_ID);
39 trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(this); 40 trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(this);
40 } 41 }
41 42
42 void BlameContext::Enter() { 43 void BlameContext::Enter() {
43 DCHECK(WasInitialized()); 44 DCHECK(WasInitialized());
44 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_ENTER_CONTEXT, 45 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_ENTER_CONTEXT,
45 category_group_enabled_, name_, scope_, id_, 46 category_group_enabled_, name_, scope_, id_,
46 0 /* num_args */, nullptr, nullptr, nullptr, 47 0 /* num_args */, nullptr, nullptr, nullptr,
47 nullptr, TRACE_EVENT_FLAG_HAS_ID); 48 nullptr, TRACE_EVENT_FLAG_HAS_LOCAL_ID);
48 } 49 }
49 50
50 void BlameContext::Leave() { 51 void BlameContext::Leave() {
51 DCHECK(WasInitialized()); 52 DCHECK(WasInitialized());
52 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_LEAVE_CONTEXT, 53 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_LEAVE_CONTEXT,
53 category_group_enabled_, name_, scope_, id_, 54 category_group_enabled_, name_, scope_, id_,
54 0 /* num_args */, nullptr, nullptr, nullptr, 55 0 /* num_args */, nullptr, nullptr, nullptr,
55 nullptr, TRACE_EVENT_FLAG_HAS_ID); 56 nullptr, TRACE_EVENT_FLAG_HAS_LOCAL_ID);
56 } 57 }
57 58
58 void BlameContext::TakeSnapshot() { 59 void BlameContext::TakeSnapshot() {
59 DCHECK(thread_checker_.CalledOnValidThread()); 60 DCHECK(thread_checker_.CalledOnValidThread());
60 DCHECK(WasInitialized()); 61 DCHECK(WasInitialized());
61 if (!*category_group_enabled_) 62 if (!*category_group_enabled_)
62 return; 63 return;
63 std::unique_ptr<trace_event::TracedValue> snapshot( 64 std::unique_ptr<trace_event::TracedValue> snapshot(
64 new trace_event::TracedValue); 65 new trace_event::TracedValue);
65 AsValueInto(snapshot.get()); 66 AsValueInto(snapshot.get());
66 static const char* kArgName = "snapshot"; 67 static const char* kArgName = "snapshot";
67 const int kNumArgs = 1; 68 const int kNumArgs = 1;
68 unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; 69 unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE};
69 std::unique_ptr<trace_event::ConvertableToTraceFormat> arg_values[1] = { 70 std::unique_ptr<trace_event::ConvertableToTraceFormat> arg_values[1] = {
70 std::move(snapshot)}; 71 std::move(snapshot)};
71 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, 72 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT,
72 category_group_enabled_, type_, scope_, id_, 73 category_group_enabled_, type_, scope_, id_,
73 kNumArgs, &kArgName, arg_types, nullptr, 74 kNumArgs, &kArgName, arg_types, nullptr,
74 arg_values, TRACE_EVENT_FLAG_HAS_ID); 75 arg_values, TRACE_EVENT_FLAG_HAS_LOCAL_ID);
75 } 76 }
76 77
77 void BlameContext::OnTraceLogEnabled() { 78 void BlameContext::OnTraceLogEnabled() {
78 DCHECK(WasInitialized()); 79 DCHECK(WasInitialized());
79 TakeSnapshot(); 80 TakeSnapshot();
80 } 81 }
81 82
82 void BlameContext::OnTraceLogDisabled() {} 83 void BlameContext::OnTraceLogDisabled() {}
83 84
84 void BlameContext::AsValueInto(trace_event::TracedValue* state) { 85 void BlameContext::AsValueInto(trace_event::TracedValue* state) {
85 DCHECK(WasInitialized()); 86 DCHECK(WasInitialized());
86 if (!parent_id_) 87 if (!parent_id_)
87 return; 88 return;
88 state->BeginDictionary("parent"); 89 state->BeginDictionary("parent");
89 state->SetString("id_ref", StringPrintf("0x%" PRIx64, parent_id_)); 90 state->SetString("id_ref", StringPrintf("0x%" PRIx64, parent_id_));
90 state->SetString("scope", parent_scope_); 91 state->SetString("scope", parent_scope_);
91 state->EndDictionary(); 92 state->EndDictionary();
92 } 93 }
93 94
94 void BlameContext::Initialize() { 95 void BlameContext::Initialize() {
95 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK(thread_checker_.CalledOnValidThread());
96 category_group_enabled_ = 97 category_group_enabled_ =
97 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_); 98 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_);
98 TRACE_EVENT_API_ADD_TRACE_EVENT( 99 TRACE_EVENT_API_ADD_TRACE_EVENT(
99 TRACE_EVENT_PHASE_CREATE_OBJECT, category_group_enabled_, type_, scope_, 100 TRACE_EVENT_PHASE_CREATE_OBJECT, category_group_enabled_, type_, scope_,
100 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); 101 id_, 0, nullptr, nullptr, nullptr, nullptr,
102 TRACE_EVENT_FLAG_HAS_LOCAL_ID);
101 trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver( 103 trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
102 weak_factory_.GetWeakPtr()); 104 weak_factory_.GetWeakPtr());
103 TakeSnapshot(); 105 TakeSnapshot();
104 } 106 }
105 107
106 bool BlameContext::WasInitialized() const { 108 bool BlameContext::WasInitialized() const {
107 return category_group_enabled_ != nullptr; 109 return category_group_enabled_ != nullptr;
108 } 110 }
109 111
110 } // namespace trace_event 112 } // namespace trace_event
111 } // namespace base 113 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/common/trace_event_common.h » ('j') | base/trace_event/common/trace_event_common.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698