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

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

Issue 1975363002: Add ThreadChecker for V8SamplingProfiler. (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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 void V8SamplingThread::Stop() { 574 void V8SamplingThread::Stop() {
575 cancellation_flag_.Set(); 575 cancellation_flag_.Set();
576 base::PlatformThread::Join(sampling_thread_handle_); 576 base::PlatformThread::Join(sampling_thread_handle_);
577 } 577 }
578 578
579 V8SamplingProfiler::V8SamplingProfiler(bool underTest) 579 V8SamplingProfiler::V8SamplingProfiler(bool underTest)
580 : sampling_thread_(nullptr), 580 : sampling_thread_(nullptr),
581 render_thread_sampler_(Sampler::CreateForCurrentThread()), 581 render_thread_sampler_(Sampler::CreateForCurrentThread()),
582 weak_factory_(this) { 582 weak_factory_(this) {
583 DCHECK(underTest || RenderThreadImpl::current()); 583 DCHECK(underTest || RenderThreadImpl::current());
584 DCHECK(thread_checker_.CalledOnValidThread());
584 // Force the "v8.cpu_profile*" categories to show up in the trace viewer. 585 // Force the "v8.cpu_profile*" categories to show up in the trace viewer.
585 TraceLog::GetCategoryGroupEnabled( 586 TraceLog::GetCategoryGroupEnabled(
586 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")); 587 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"));
587 TraceLog::GetCategoryGroupEnabled( 588 TraceLog::GetCategoryGroupEnabled(
588 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile.hires")); 589 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile.hires"));
589 TraceLog::GetInstance()->AddAsyncEnabledStateObserver( 590 TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
590 weak_factory_.GetWeakPtr()); 591 weak_factory_.GetWeakPtr());
591 } 592 }
592 593
593 V8SamplingProfiler::~V8SamplingProfiler() { 594 V8SamplingProfiler::~V8SamplingProfiler() {
595 DCHECK(thread_checker_.CalledOnValidThread());
594 TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(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());
602 DCHECK(thread_checker_.CalledOnValidThread());
600 sampling_thread_.reset(new V8SamplingThread( 603 sampling_thread_.reset(new V8SamplingThread(
601 render_thread_sampler_.get(), waitable_event_for_testing_.get())); 604 render_thread_sampler_.get(), waitable_event_for_testing_.get()));
602 sampling_thread_->Start(); 605 sampling_thread_->Start();
603 } 606 }
604 607
605 void V8SamplingProfiler::StopSamplingThread() { 608 void V8SamplingProfiler::StopSamplingThread() {
609 DCHECK(thread_checker_.CalledOnValidThread());
606 if (!sampling_thread_.get()) 610 if (!sampling_thread_.get())
607 return; 611 return;
608 sampling_thread_->Stop(); 612 sampling_thread_->Stop();
609 sampling_thread_.reset(); 613 sampling_thread_.reset();
610 } 614 }
611 615
612 void V8SamplingProfiler::OnTraceLogEnabled() { 616 void V8SamplingProfiler::OnTraceLogEnabled() {
613 bool enabled; 617 bool enabled;
614 TRACE_EVENT_CATEGORY_GROUP_ENABLED( 618 TRACE_EVENT_CATEGORY_GROUP_ENABLED(
615 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"), &enabled); 619 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"), &enabled);
(...skipping 20 matching lines...) Expand all
636 render_thread_sampler_->SetEventsToCollectForTest(code_added_events, 640 render_thread_sampler_->SetEventsToCollectForTest(code_added_events,
637 sample_events); 641 sample_events);
638 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false)); 642 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false));
639 } 643 }
640 644
641 void V8SamplingProfiler::WaitSamplingEventForTesting() { 645 void V8SamplingProfiler::WaitSamplingEventForTesting() {
642 waitable_event_for_testing_->Wait(); 646 waitable_event_for_testing_->Wait();
643 } 647 }
644 648
645 } // namespace content 649 } // 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