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

Side by Side Diff: content/renderer/devtools/v8_sampling_profiler.cc

Issue 1967793004: Change base class of V8SamplingProfiler to AsyncEnabledStateObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « content/renderer/devtools/v8_sampling_profiler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/devtools/v8_sampling_profiler.h" 5 #include "content/renderer/devtools/v8_sampling_profiler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 573 }
574 574
575 void V8SamplingThread::Stop() { 575 void V8SamplingThread::Stop() {
576 cancellation_flag_.Set(); 576 cancellation_flag_.Set();
577 base::PlatformThread::Join(sampling_thread_handle_); 577 base::PlatformThread::Join(sampling_thread_handle_);
578 } 578 }
579 579
580 V8SamplingProfiler::V8SamplingProfiler(bool underTest) 580 V8SamplingProfiler::V8SamplingProfiler(bool underTest)
581 : sampling_thread_(nullptr), 581 : sampling_thread_(nullptr),
582 render_thread_sampler_(Sampler::CreateForCurrentThread()), 582 render_thread_sampler_(Sampler::CreateForCurrentThread()),
583 task_runner_(base::ThreadTaskRunnerHandle::Get()) { 583 task_runner_(base::ThreadTaskRunnerHandle::Get()),
584 weak_factory_(this) {
584 DCHECK(underTest || RenderThreadImpl::current()); 585 DCHECK(underTest || RenderThreadImpl::current());
585 // Force the "v8.cpu_profile*" categories to show up in the trace viewer. 586 // Force the "v8.cpu_profile*" categories to show up in the trace viewer.
586 TraceLog::GetCategoryGroupEnabled( 587 TraceLog::GetCategoryGroupEnabled(
587 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")); 588 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"));
588 TraceLog::GetCategoryGroupEnabled( 589 TraceLog::GetCategoryGroupEnabled(
589 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile.hires")); 590 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile.hires"));
590 TraceLog::GetInstance()->AddEnabledStateObserver(this); 591 TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
592 weak_factory_.GetWeakPtr());
591 } 593 }
592 594
593 V8SamplingProfiler::~V8SamplingProfiler() { 595 V8SamplingProfiler::~V8SamplingProfiler() {
594 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 596 TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(this);
595 DCHECK(!sampling_thread_.get()); 597 DCHECK(!sampling_thread_.get());
596 } 598 }
597 599
598 void V8SamplingProfiler::StartSamplingThread() { 600 void V8SamplingProfiler::StartSamplingThread() {
599 DCHECK(!sampling_thread_.get()); 601 DCHECK(!sampling_thread_.get());
600 sampling_thread_.reset(new V8SamplingThread( 602 sampling_thread_.reset(new V8SamplingThread(
601 render_thread_sampler_.get(), waitable_event_for_testing_.get())); 603 render_thread_sampler_.get(), waitable_event_for_testing_.get()));
602 sampling_thread_->Start(); 604 sampling_thread_->Start();
603 } 605 }
604 606
(...skipping 12 matching lines...) Expand all
617 return; 619 return;
618 620
619 // Do not enable sampling profiler in continuous mode, as losing 621 // Do not enable sampling profiler in continuous mode, as losing
620 // Jit code events may not be afforded. 622 // Jit code events may not be afforded.
621 // TODO(alph): add support of infinite recording of meta trace events. 623 // TODO(alph): add support of infinite recording of meta trace events.
622 base::trace_event::TraceRecordMode record_mode = 624 base::trace_event::TraceRecordMode record_mode =
623 TraceLog::GetInstance()->GetCurrentTraceConfig().GetTraceRecordMode(); 625 TraceLog::GetInstance()->GetCurrentTraceConfig().GetTraceRecordMode();
624 if (record_mode == base::trace_event::TraceRecordMode::RECORD_CONTINUOUSLY) 626 if (record_mode == base::trace_event::TraceRecordMode::RECORD_CONTINUOUSLY)
625 return; 627 return;
626 628
627 task_runner_->PostTask(FROM_HERE, 629 task_runner_->PostTask(FROM_HERE,
alph 2016/05/11 22:39:51 Why do we need to post another task? The async sta
lpy 2016/05/11 23:01:52 Done.
628 base::Bind(&V8SamplingProfiler::StartSamplingThread, 630 base::Bind(&V8SamplingProfiler::StartSamplingThread,
629 base::Unretained(this))); 631 base::Unretained(this)));
630 } 632 }
631 633
632 void V8SamplingProfiler::OnTraceLogDisabled() { 634 void V8SamplingProfiler::OnTraceLogDisabled() {
633 task_runner_->PostTask(FROM_HERE, 635 task_runner_->PostTask(FROM_HERE,
alph 2016/05/11 22:39:51 ditto
lpy 2016/05/11 23:01:52 Done.
634 base::Bind(&V8SamplingProfiler::StopSamplingThread, 636 base::Bind(&V8SamplingProfiler::StopSamplingThread,
635 base::Unretained(this))); 637 base::Unretained(this)));
636 } 638 }
637 639
638 void V8SamplingProfiler::EnableSamplingEventForTesting(int code_added_events, 640 void V8SamplingProfiler::EnableSamplingEventForTesting(int code_added_events,
639 int sample_events) { 641 int sample_events) {
640 render_thread_sampler_->SetEventsToCollectForTest(code_added_events, 642 render_thread_sampler_->SetEventsToCollectForTest(code_added_events,
641 sample_events); 643 sample_events);
642 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false)); 644 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false));
643 } 645 }
644 646
645 void V8SamplingProfiler::WaitSamplingEventForTesting() { 647 void V8SamplingProfiler::WaitSamplingEventForTesting() {
646 waitable_event_for_testing_->Wait(); 648 waitable_event_for_testing_->Wait();
647 } 649 }
648 650
649 } // namespace content 651 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/devtools/v8_sampling_profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698