OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gin/public/v8_platform.h" | 5 #include "gin/public/v8_platform.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const uint8_t* V8Platform::GetCategoryGroupEnabled(const char* name) { | 79 const uint8_t* V8Platform::GetCategoryGroupEnabled(const char* name) { |
80 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(name); | 80 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(name); |
81 } | 81 } |
82 | 82 |
83 const char* V8Platform::GetCategoryGroupName( | 83 const char* V8Platform::GetCategoryGroupName( |
84 const uint8_t* category_enabled_flag) { | 84 const uint8_t* category_enabled_flag) { |
85 return base::trace_event::TraceLog::GetCategoryGroupName( | 85 return base::trace_event::TraceLog::GetCategoryGroupName( |
86 category_enabled_flag); | 86 category_enabled_flag); |
87 } | 87 } |
88 | 88 |
89 uint64_t V8Platform::AddTraceEvent(char phase, | 89 namespace { |
90 const uint8_t* category_enabled_flag, | 90 |
91 const char* name, | 91 class ConvertableToTraceFormatWrapper |
92 const char* scope, | 92 : public base::trace_event::ConvertableToTraceFormat { |
93 uint64_t id, | 93 public: |
94 uint64_t bind_id, | 94 explicit ConvertableToTraceFormatWrapper( |
95 int32_t num_args, | 95 std::unique_ptr<v8::ConvertableToTraceFormat>& inner) |
96 const char** arg_names, | 96 : inner_(std::move(inner)) {} |
97 const uint8_t* arg_types, | 97 ~ConvertableToTraceFormatWrapper() override = default; |
98 const uint64_t* arg_values, | 98 void AppendAsTraceFormat(std::string* out) const final { |
99 unsigned int flags) { | 99 inner_->AppendAsTraceFormat(out); |
| 100 } |
| 101 |
| 102 private: |
| 103 std::unique_ptr<v8::ConvertableToTraceFormat> inner_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(ConvertableToTraceFormatWrapper); |
| 106 }; |
| 107 |
| 108 } // namespace |
| 109 |
| 110 uint64_t V8Platform::AddTraceEvent( |
| 111 char phase, |
| 112 const uint8_t* category_enabled_flag, |
| 113 const char* name, |
| 114 const char* scope, |
| 115 uint64_t id, |
| 116 uint64_t bind_id, |
| 117 int32_t num_args, |
| 118 const char** arg_names, |
| 119 const uint8_t* arg_types, |
| 120 const uint64_t* arg_values, |
| 121 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, |
| 122 unsigned int flags) { |
100 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> convertables[2]; | 123 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> convertables[2]; |
101 if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) { | 124 if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) { |
102 convertables[0].reset( | 125 convertables[0].reset( |
103 reinterpret_cast<base::trace_event::ConvertableToTraceFormat*>( | 126 new ConvertableToTraceFormatWrapper(arg_convertables[0])); |
104 arg_values[0])); | |
105 } | 127 } |
106 if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) { | 128 if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) { |
107 convertables[1].reset( | 129 convertables[1].reset( |
108 reinterpret_cast<base::trace_event::ConvertableToTraceFormat*>( | 130 new ConvertableToTraceFormatWrapper(arg_convertables[1])); |
109 arg_values[1])); | |
110 } | 131 } |
| 132 DCHECK_LE(num_args, 2); |
111 base::trace_event::TraceEventHandle handle = | 133 base::trace_event::TraceEventHandle handle = |
112 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_BIND_ID( | 134 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_BIND_ID( |
113 phase, category_enabled_flag, name, scope, id, bind_id, num_args, | 135 phase, category_enabled_flag, name, scope, id, bind_id, num_args, |
114 arg_names, arg_types, (const long long unsigned int*)arg_values, | 136 arg_names, arg_types, (const long long unsigned int*)arg_values, |
115 convertables, flags); | 137 convertables, flags); |
116 uint64_t result; | 138 uint64_t result; |
117 memcpy(&result, &handle, sizeof(result)); | 139 memcpy(&result, &handle, sizeof(result)); |
118 return result; | 140 return result; |
119 } | 141 } |
120 | 142 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 v8::Platform::TraceStateObserver* observer) { | 205 v8::Platform::TraceStateObserver* observer) { |
184 g_trace_state_dispatcher.Get().AddObserver(observer); | 206 g_trace_state_dispatcher.Get().AddObserver(observer); |
185 } | 207 } |
186 | 208 |
187 void V8Platform::RemoveTraceStateObserver( | 209 void V8Platform::RemoveTraceStateObserver( |
188 v8::Platform::TraceStateObserver* observer) { | 210 v8::Platform::TraceStateObserver* observer) { |
189 g_trace_state_dispatcher.Get().RemoveObserver(observer); | 211 g_trace_state_dispatcher.Get().RemoveObserver(observer); |
190 } | 212 } |
191 | 213 |
192 } // namespace gin | 214 } // namespace gin |
OLD | NEW |