Commit deba7c11 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

Add lock annotations for sampling profiler

Adds GUARDED_BY/EXCLUSIVE_LOCKS_REQUIRED annotations for the parts of
the sampling profiler implementation using locking.

Bug: 887645
Change-Id: Ibe96c541a50254af3822d6811fe03250543a98eb
Reviewed-on: https://chromium-review.googlesource.com/c/1283483Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600092}
parent 75e890c9
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/native_stack_sampler.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -201,15 +202,19 @@ class StackSamplingProfiler::SamplingThread : public Thread { ...@@ -201,15 +202,19 @@ class StackSamplingProfiler::SamplingThread : public Thread {
// Thread API (Start, Stop, StopSoon, & DetachFromSequence) so that // Thread API (Start, Stop, StopSoon, & DetachFromSequence) so that
// multiple threads may make those calls. // multiple threads may make those calls.
Lock thread_execution_state_lock_; // Protects all thread_execution_state_* Lock thread_execution_state_lock_; // Protects all thread_execution_state_*
ThreadExecutionState thread_execution_state_ = NOT_STARTED; ThreadExecutionState thread_execution_state_
scoped_refptr<SingleThreadTaskRunner> thread_execution_state_task_runner_; GUARDED_BY(thread_execution_state_lock_) = NOT_STARTED;
bool thread_execution_state_disable_idle_shutdown_for_testing_ = false; scoped_refptr<SingleThreadTaskRunner> thread_execution_state_task_runner_
GUARDED_BY(thread_execution_state_lock_);
bool thread_execution_state_disable_idle_shutdown_for_testing_
GUARDED_BY(thread_execution_state_lock_) = false;
// A counter that notes adds of new collection requests. It is incremented // A counter that notes adds of new collection requests. It is incremented
// when changes occur so that delayed shutdown tasks are able to detect if // when changes occur so that delayed shutdown tasks are able to detect if
// something new has happened while it was waiting. Like all "execution_state" // something new has happened while it was waiting. Like all "execution_state"
// vars, this must be accessed while holding |thread_execution_state_lock_|. // vars, this must be accessed while holding |thread_execution_state_lock_|.
int thread_execution_state_add_events_ = 0; int thread_execution_state_add_events_
GUARDED_BY(thread_execution_state_lock_) = 0;
DISALLOW_COPY_AND_ASSIGN(SamplingThread); DISALLOW_COPY_AND_ASSIGN(SamplingThread);
}; };
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
...@@ -115,31 +116,32 @@ class PendingProfiles { ...@@ -115,31 +116,32 @@ class PendingProfiles {
// Returns true if collection is enabled for a given profile based on its // Returns true if collection is enabled for a given profile based on its
// |profile_start_time|. The |lock_| must be held prior to calling this // |profile_start_time|. The |lock_| must be held prior to calling this
// method. // method.
bool IsCollectionEnabledForProfile(base::TimeTicks profile_start_time) const; bool IsCollectionEnabledForProfile(base::TimeTicks profile_start_time) const
EXCLUSIVE_LOCKS_REQUIRED(lock_);
// Whether there is spare capacity to store an additional profile. // Whether there is spare capacity to store an additional profile.
// The |lock_| must be held prior to calling this method. // The |lock_| must be held prior to calling this method.
bool HasSpareCapacity() const; bool HasSpareCapacity() const EXCLUSIVE_LOCKS_REQUIRED(lock_);
mutable base::Lock lock_; mutable base::Lock lock_;
// If true, profiles provided to MaybeCollect*Profile should be collected. // If true, profiles provided to MaybeCollect*Profile should be collected.
// Otherwise they will be ignored. // Otherwise they will be ignored.
bool collection_enabled_; bool collection_enabled_ GUARDED_BY(lock_);
// The last time collection was disabled. Used to determine if collection was // The last time collection was disabled. Used to determine if collection was
// disabled at any point since a profile was started. // disabled at any point since a profile was started.
base::TimeTicks last_collection_disable_time_; base::TimeTicks last_collection_disable_time_ GUARDED_BY(lock_);
// The last time collection was enabled. Used to determine if collection was // The last time collection was enabled. Used to determine if collection was
// enabled at any point since a profile was started. // enabled at any point since a profile was started.
base::TimeTicks last_collection_enable_time_; base::TimeTicks last_collection_enable_time_ GUARDED_BY(lock_);
// The set of completed unserialized profiles that should be reported. // The set of completed unserialized profiles that should be reported.
std::vector<SampledProfile> unserialized_profiles_; std::vector<SampledProfile> unserialized_profiles_ GUARDED_BY(lock_);
// The set of completed serialized profiles that should be reported. // The set of completed serialized profiles that should be reported.
std::vector<std::string> serialized_profiles_; std::vector<std::string> serialized_profiles_ GUARDED_BY(lock_);
DISALLOW_COPY_AND_ASSIGN(PendingProfiles); DISALLOW_COPY_AND_ASSIGN(PendingProfiles);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment