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

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 109933006: Implement sampling profiler (chromium side change) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/tracing/tracing_controller_impl.h" 5 #include "content/browser/tracing/tracing_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 LOG(ERROR) << "Failed to open " << path_.value(); 73 LOG(ERROR) << "Failed to open " << path_.value();
74 return; 74 return;
75 } 75 }
76 const char* preamble = "{\"traceEvents\": ["; 76 const char* preamble = "{\"traceEvents\": [";
77 size_t written = fwrite(preamble, strlen(preamble), 1, file_); 77 size_t written = fwrite(preamble, strlen(preamble), 1, file_);
78 DCHECK(written == 1); 78 DCHECK(written == 1);
79 } 79 }
80 80
81 void TracingControllerImpl::ResultFile::WriteTask( 81 void TracingControllerImpl::ResultFile::WriteTask(
82 const scoped_refptr<base::RefCountedString>& events_str_ptr) { 82 const scoped_refptr<base::RefCountedString>& events_str_ptr) {
83 if (!file_) 83 if (!file_ || !events_str_ptr->data().size())
84 return; 84 return;
85 85
86 // If there is already a result in the file, then put a commma 86 // If there is already a result in the file, then put a commma
87 // before the next batch of results. 87 // before the next batch of results.
88 if (has_at_least_one_result_) { 88 if (has_at_least_one_result_) {
89 size_t written = fwrite(",", 1, 1, file_); 89 size_t written = fwrite(",", 1, 1, file_);
90 DCHECK(written == 1); 90 DCHECK(written == 1);
91 } 91 }
92 has_at_least_one_result_ = true; 92 has_at_least_one_result_ = true;
93 size_t written = fwrite(events_str_ptr->data().c_str(), 93 size_t written = fwrite(events_str_ptr->data().c_str(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return false; 145 return false;
146 } 146 }
147 147
148 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback()); 148 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback());
149 DCHECK(ok); 149 DCHECK(ok);
150 return true; 150 return true;
151 } 151 }
152 152
153 void TracingControllerImpl::SetEnabledOnFileThread( 153 void TracingControllerImpl::SetEnabledOnFileThread(
154 const std::string& category_filter, 154 const std::string& category_filter,
155 int mode,
155 int trace_options, 156 int trace_options,
156 const base::Closure& callback) { 157 const base::Closure& callback) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
158 159
159 TraceLog::GetInstance()->SetEnabled( 160 TraceLog::GetInstance()->SetEnabled(
160 base::debug::CategoryFilter(category_filter), 161 base::debug::CategoryFilter(category_filter),
162 static_cast<TraceLog::Mode>(mode),
161 static_cast<TraceLog::Options>(trace_options)); 163 static_cast<TraceLog::Options>(trace_options));
162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
163 } 165 }
164 166
165 void TracingControllerImpl::SetDisabledOnFileThread( 167 void TracingControllerImpl::SetDisabledOnFileThread(
166 const base::Closure& callback) { 168 const base::Closure& callback) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
168 170
169 TraceLog::GetInstance()->SetDisabled(); 171 TraceLog::GetInstance()->SetDisabled();
170 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); 172 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
(...skipping 17 matching lines...) Expand all
188 int trace_options = (options & RECORD_CONTINUOUSLY) ? 190 int trace_options = (options & RECORD_CONTINUOUSLY) ?
189 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; 191 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL;
190 if (options & ENABLE_SAMPLING) { 192 if (options & ENABLE_SAMPLING) {
191 trace_options |= TraceLog::ENABLE_SAMPLING; 193 trace_options |= TraceLog::ENABLE_SAMPLING;
192 } 194 }
193 // TODO(haraken): How to handle ENABLE_SYSTRACE? 195 // TODO(haraken): How to handle ENABLE_SYSTRACE?
194 196
195 base::Closure on_enable_recording_done_callback = 197 base::Closure on_enable_recording_done_callback =
196 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, 198 base::Bind(&TracingControllerImpl::OnEnableRecordingDone,
197 base::Unretained(this), 199 base::Unretained(this),
198 category_filter, trace_options, callback); 200 category_filter,trace_options, callback);
199 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 201 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
200 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, 202 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
201 base::Unretained(this), 203 base::Unretained(this),
202 category_filter, trace_options, 204 category_filter,
205 base::debug::TraceLog::RECORDING_MODE,
206 trace_options,
203 on_enable_recording_done_callback)); 207 on_enable_recording_done_callback));
204 return true; 208 return true;
205 } 209 }
206 210
207 void TracingControllerImpl::OnEnableRecordingDone( 211 void TracingControllerImpl::OnEnableRecordingDone(
208 const std::string& category_filter, 212 const std::string& category_filter,
209 int trace_options, 213 int trace_options,
210 const EnableRecordingDoneCallback& callback) { 214 const EnableRecordingDoneCallback& callback) {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212 216
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (!can_enable_monitoring()) 292 if (!can_enable_monitoring())
289 return false; 293 return false;
290 is_monitoring_ = true; 294 is_monitoring_ = true;
291 295
292 #if defined(OS_ANDROID) 296 #if defined(OS_ANDROID)
293 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 297 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
294 #endif 298 #endif
295 299
296 int trace_options = 0; 300 int trace_options = 0;
297 if (options & ENABLE_SAMPLING) 301 if (options & ENABLE_SAMPLING)
298 trace_options |= TraceLog::MONITOR_SAMPLING; 302 trace_options |= TraceLog::ENABLE_SAMPLING;
299 303
300 base::Closure on_enable_monitoring_done_callback = 304 base::Closure on_enable_monitoring_done_callback =
301 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, 305 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone,
302 base::Unretained(this), 306 base::Unretained(this),
303 category_filter, trace_options, callback); 307 category_filter, trace_options, callback);
304 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 308 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
305 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, 309 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
306 base::Unretained(this), 310 base::Unretained(this),
307 category_filter, trace_options, 311 category_filter,
312 base::debug::TraceLog::MONITORING_MODE,
313 trace_options,
308 on_enable_monitoring_done_callback)); 314 on_enable_monitoring_done_callback));
309 return true; 315 return true;
310 } 316 }
311 317
312 void TracingControllerImpl::OnEnableMonitoringDone( 318 void TracingControllerImpl::OnEnableMonitoringDone(
313 const std::string& category_filter, 319 const std::string& category_filter,
314 int trace_options, 320 int trace_options,
315 const EnableMonitoringDoneCallback& callback) { 321 const EnableMonitoringDoneCallback& callback) {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
317 323
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 trace_message_filters_.insert(trace_message_filter); 500 trace_message_filters_.insert(trace_message_filter);
495 if (can_cancel_watch_event()) { 501 if (can_cancel_watch_event()) {
496 trace_message_filter->SendSetWatchEvent(watch_category_name_, 502 trace_message_filter->SendSetWatchEvent(watch_category_name_,
497 watch_event_name_); 503 watch_event_name_);
498 } 504 }
499 if (can_disable_recording()) { 505 if (can_disable_recording()) {
500 trace_message_filter->SendBeginTracing( 506 trace_message_filter->SendBeginTracing(
501 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), 507 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
502 TraceLog::GetInstance()->trace_options()); 508 TraceLog::GetInstance()->trace_options());
503 } 509 }
510 if (can_disable_monitoring()) {
511 trace_message_filter->SendEnableMonitoring(
512 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
513 TraceLog::GetInstance()->trace_options());
514 }
504 } 515 }
505 516
506 void TracingControllerImpl::RemoveTraceMessageFilter( 517 void TracingControllerImpl::RemoveTraceMessageFilter(
507 TraceMessageFilter* trace_message_filter) { 518 TraceMessageFilter* trace_message_filter) {
508 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 519 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
509 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 520 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
510 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, 521 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter,
511 base::Unretained(this), 522 base::Unretained(this),
512 make_scoped_refptr(trace_message_filter))); 523 make_scoped_refptr(trace_message_filter)));
513 return; 524 return;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 base::Bind(&TracingControllerImpl::OnWatchEventMatched, 786 base::Bind(&TracingControllerImpl::OnWatchEventMatched,
776 base::Unretained(this))); 787 base::Unretained(this)));
777 return; 788 return;
778 } 789 }
779 790
780 if (!watch_event_callback_.is_null()) 791 if (!watch_event_callback_.is_null())
781 watch_event_callback_.Run(); 792 watch_event_callback_.Run();
782 } 793 }
783 794
784 } // namespace content 795 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.h ('k') | content/browser/tracing/tracing_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698