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

Side by Side Diff: src/libplatform/tracing/tracing-controller.cc

Issue 2369073003: [tracing] Implement Add/RemoveTraceStateObserver for default platform. (Closed)
Patch Set: addressing comments. Created 4 years, 2 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 | « src/libplatform/default-platform.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 <stdio.h> 5 #include <stdio.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "include/libplatform/v8-tracing.h" 8 #include "include/libplatform/v8-tracing.h"
9 9
10 #include "src/base/platform/mutex.h" 10 #include "src/base/platform/mutex.h"
(...skipping 20 matching lines...) Expand all
31 // Indexes here have to match the g_category_groups array indexes above. 31 // Indexes here have to match the g_category_groups array indexes above.
32 const int g_category_already_shutdown = 1; 32 const int g_category_already_shutdown = 1;
33 const int g_category_categories_exhausted = 2; 33 const int g_category_categories_exhausted = 2;
34 // Metadata category not used in V8. 34 // Metadata category not used in V8.
35 // const int g_category_metadata = 3; 35 // const int g_category_metadata = 3;
36 const int g_num_builtin_categories = 4; 36 const int g_num_builtin_categories = 4;
37 37
38 // Skip default categories. 38 // Skip default categories.
39 v8::base::AtomicWord g_category_index = g_num_builtin_categories; 39 v8::base::AtomicWord g_category_index = g_num_builtin_categories;
40 40
41 TracingController::TracingController() {}
42
43 TracingController::~TracingController() {}
44
41 void TracingController::Initialize(TraceBuffer* trace_buffer) { 45 void TracingController::Initialize(TraceBuffer* trace_buffer) {
42 trace_buffer_.reset(trace_buffer); 46 trace_buffer_.reset(trace_buffer);
47 mutex_.reset(new base::Mutex());
43 } 48 }
44 49
45 uint64_t TracingController::AddTraceEvent( 50 uint64_t TracingController::AddTraceEvent(
46 char phase, const uint8_t* category_enabled_flag, const char* name, 51 char phase, const uint8_t* category_enabled_flag, const char* name,
47 const char* scope, uint64_t id, uint64_t bind_id, int num_args, 52 const char* scope, uint64_t id, uint64_t bind_id, int num_args,
48 const char** arg_names, const uint8_t* arg_types, 53 const char** arg_names, const uint8_t* arg_types,
49 const uint64_t* arg_values, unsigned int flags) { 54 const uint64_t* arg_values, unsigned int flags) {
50 uint64_t handle; 55 uint64_t handle;
51 TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle); 56 TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
52 if (trace_object) { 57 if (trace_object) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 DCHECK(category_ptr >= category_begin && 89 DCHECK(category_ptr >= category_begin &&
85 category_ptr < reinterpret_cast<uintptr_t>(g_category_group_enabled + 90 category_ptr < reinterpret_cast<uintptr_t>(g_category_group_enabled +
86 MAX_CATEGORY_GROUPS)); 91 MAX_CATEGORY_GROUPS));
87 uintptr_t category_index = 92 uintptr_t category_index =
88 (category_ptr - category_begin) / sizeof(g_category_group_enabled[0]); 93 (category_ptr - category_begin) / sizeof(g_category_group_enabled[0]);
89 return g_category_groups[category_index]; 94 return g_category_groups[category_index];
90 } 95 }
91 96
92 void TracingController::StartTracing(TraceConfig* trace_config) { 97 void TracingController::StartTracing(TraceConfig* trace_config) {
93 trace_config_.reset(trace_config); 98 trace_config_.reset(trace_config);
94 mode_ = RECORDING_MODE; 99 std::unordered_set<Platform::TraceStateObserver*> observers_copy;
95 UpdateCategoryGroupEnabledFlags(); 100 {
101 base::LockGuard<base::Mutex> lock(mutex_.get());
102 mode_ = RECORDING_MODE;
103 UpdateCategoryGroupEnabledFlags();
104 observers_copy = observers_;
105 }
106 for (auto o : observers_copy) {
107 o->OnTraceEnabled();
108 }
96 } 109 }
97 110
98 void TracingController::StopTracing() { 111 void TracingController::StopTracing() {
99 mode_ = DISABLED; 112 mode_ = DISABLED;
100 UpdateCategoryGroupEnabledFlags(); 113 UpdateCategoryGroupEnabledFlags();
114 std::unordered_set<Platform::TraceStateObserver*> observers_copy;
115 {
116 base::LockGuard<base::Mutex> lock(mutex_.get());
117 observers_copy = observers_;
118 }
119 for (auto o : observers_copy) {
120 o->OnTraceDisabled();
121 }
101 trace_buffer_->Flush(); 122 trace_buffer_->Flush();
102 } 123 }
103 124
104 void TracingController::UpdateCategoryGroupEnabledFlag(size_t category_index) { 125 void TracingController::UpdateCategoryGroupEnabledFlag(size_t category_index) {
105 unsigned char enabled_flag = 0; 126 unsigned char enabled_flag = 0;
106 const char* category_group = g_category_groups[category_index]; 127 const char* category_group = g_category_groups[category_index];
107 if (mode_ == RECORDING_MODE && 128 if (mode_ == RECORDING_MODE &&
108 trace_config_->IsCategoryGroupEnabled(category_group)) { 129 trace_config_->IsCategoryGroupEnabled(category_group)) {
109 enabled_flag |= ENABLED_FOR_RECORDING; 130 enabled_flag |= ENABLED_FOR_RECORDING;
110 } 131 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 category_group_enabled = &g_category_group_enabled[category_index]; 186 category_group_enabled = &g_category_group_enabled[category_index];
166 // Update the max index now. 187 // Update the max index now.
167 base::Release_Store(&g_category_index, category_index + 1); 188 base::Release_Store(&g_category_index, category_index + 1);
168 } else { 189 } else {
169 category_group_enabled = 190 category_group_enabled =
170 &g_category_group_enabled[g_category_categories_exhausted]; 191 &g_category_group_enabled[g_category_categories_exhausted];
171 } 192 }
172 return category_group_enabled; 193 return category_group_enabled;
173 } 194 }
174 195
196 void TracingController::AddTraceStateObserver(
197 Platform::TraceStateObserver* observer) {
198 {
199 base::LockGuard<base::Mutex> lock(mutex_.get());
200 observers_.insert(observer);
201 if (mode_ != RECORDING_MODE) return;
202 }
203 // Fire the observer if recording is already in progress.
204 observer->OnTraceEnabled();
205 }
206
207 void TracingController::RemoveTraceStateObserver(
208 Platform::TraceStateObserver* observer) {
209 base::LockGuard<base::Mutex> lock(mutex_.get());
210 DCHECK(observers_.find(observer) != observers_.end());
211 observers_.erase(observer);
212 }
213
175 } // namespace tracing 214 } // namespace tracing
176 } // namespace platform 215 } // namespace platform
177 } // namespace v8 216 } // namespace v8
OLDNEW
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698