Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include "base/debug/blame_context.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "base/trace_event/trace_event_argument.h" | |
| 9 | |
| 10 namespace base { | |
| 11 namespace debug { | |
| 12 | |
| 13 BlameContext::BlameContext(const char* category, | |
| 14 const char* name, | |
| 15 const char* scope, | |
| 16 int64_t id) | |
| 17 : category_(category), | |
| 18 name_(name), | |
| 19 scope_(scope), | |
| 20 id_(id), | |
| 21 parent_scope_(nullptr), | |
| 22 parent_id_(0) { | |
| 23 Initialize(); | |
| 24 } | |
| 25 | |
| 26 BlameContext::BlameContext(const char* category, | |
| 27 const char* name, | |
| 28 const char* scope, | |
| 29 int64_t id, | |
| 30 const BlameContext& parent_context) | |
| 31 : category_(category), | |
| 32 name_(name), | |
| 33 scope_(scope), | |
| 34 id_(id), | |
| 35 parent_scope_(parent_context.scope()), | |
| 36 parent_id_(parent_context.id()) { | |
| 37 DCHECK(!std::strcmp(name_, parent_context.name())) | |
| 38 << "Parent blame context must have the same name"; | |
|
benjhayden
2016/03/10 23:18:43
I thought that a WebViewImpl context could be a pa
Sami
2016/03/14 16:59:14
Yeah, I've been going back and forth about this pa
| |
| 39 Initialize(); | |
| 40 } | |
| 41 | |
| 42 void BlameContext::Enter() { | |
| 43 TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 44 TRACE_EVENT_PHASE_ENTER_CONTEXT, category_group_enabled_, name_, scope_, | |
| 45 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); | |
|
benjhayden
2016/03/10 23:18:43
Should the first nullptr should be a 0 for num_arg
Sami
2016/03/14 16:59:14
Hmm, no? The first nullptr is the array of arg_nam
benjhayden
2016/03/14 17:16:08
Oh, sorry! Codesearch showed me the trace-event.h
| |
| 46 } | |
| 47 | |
| 48 void BlameContext::Leave() { | |
| 49 TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 50 TRACE_EVENT_PHASE_LEAVE_CONTEXT, category_group_enabled_, name_, scope_, | |
| 51 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); | |
| 52 } | |
| 53 | |
| 54 void BlameContext::TakeSnapshot() { | |
| 55 if (!*category_group_enabled_) | |
| 56 return; | |
| 57 scoped_ptr<trace_event::TracedValue> snapshot(new trace_event::TracedValue); | |
| 58 AsValueInto(snapshot.get()); | |
| 59 const char* arg_name = "snapshot"; | |
| 60 const int num_args = 1; | |
| 61 unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; | |
| 62 scoped_ptr<trace_event::ConvertableToTraceFormat> arg_values[1] = { | |
| 63 std::move(snapshot)}; | |
| 64 TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, | |
| 65 category_group_enabled_, name_, scope_, id_, | |
| 66 num_args, &arg_name, arg_types, nullptr, | |
| 67 arg_values, TRACE_EVENT_FLAG_HAS_ID); | |
| 68 } | |
| 69 | |
| 70 void BlameContext::OnTraceLogEnabled() { | |
| 71 TakeSnapshot(); | |
| 72 } | |
| 73 | |
| 74 void BlameContext::OnTraceLogDisabled() {} | |
| 75 | |
| 76 BlameContext::~BlameContext() { | |
| 77 TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 78 TRACE_EVENT_PHASE_DELETE_OBJECT, category_group_enabled_, name_, scope_, | |
| 79 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); | |
| 80 trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | |
| 81 } | |
| 82 | |
| 83 void BlameContext::AsValueInto(trace_event::TracedValue* state) { | |
| 84 if (!parent_id_) | |
| 85 return; | |
| 86 state->BeginDictionary("parent"); | |
| 87 state->SetString("id_ref", StringPrintf("0x%" PRIx64, parent_id_)); | |
| 88 state->SetString("scope", parent_scope_); | |
| 89 state->EndDictionary(); | |
| 90 } | |
| 91 | |
| 92 void BlameContext::Initialize() { | |
| 93 category_group_enabled_ = | |
| 94 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_); | |
| 95 TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 96 TRACE_EVENT_PHASE_CREATE_OBJECT, category_group_enabled_, name_, scope_, | |
| 97 id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID); | |
| 98 trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); | |
| 99 } | |
| 100 | |
| 101 } // namespace debug | |
| 102 } // namespace base | |
| OLD | NEW |