Skip to content

Commit

Permalink
Add lock annotations for sampling profiler
Browse files Browse the repository at this point in the history
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/1283483
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Commit-Queue: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600092}
  • Loading branch information
Mike Wittman authored and Commit Bot committed Oct 16, 2018
1 parent 75e890c commit deba7c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
13 changes: 9 additions & 4 deletions base/profiler/stack_sampling_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/memory/singleton.h"
#include "base/profiler/native_stack_sampler.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -201,15 +202,19 @@ class StackSamplingProfiler::SamplingThread : public Thread {
// Thread API (Start, Stop, StopSoon, & DetachFromSequence) so that
// multiple threads may make those calls.
Lock thread_execution_state_lock_; // Protects all thread_execution_state_*
ThreadExecutionState thread_execution_state_ = NOT_STARTED;
scoped_refptr<SingleThreadTaskRunner> thread_execution_state_task_runner_;
bool thread_execution_state_disable_idle_shutdown_for_testing_ = false;
ThreadExecutionState thread_execution_state_
GUARDED_BY(thread_execution_state_lock_) = NOT_STARTED;
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
// 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"
// 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);
};
Expand Down
16 changes: 9 additions & 7 deletions components/metrics/call_stack_profile_metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "base/time/time.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"

Expand Down Expand Up @@ -115,31 +116,32 @@ class PendingProfiles {
// 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
// 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.
// The |lock_| must be held prior to calling this method.
bool HasSpareCapacity() const;
bool HasSpareCapacity() const EXCLUSIVE_LOCKS_REQUIRED(lock_);

mutable base::Lock lock_;

// If true, profiles provided to MaybeCollect*Profile should be collected.
// 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
// 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
// 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.
std::vector<SampledProfile> unserialized_profiles_;
std::vector<SampledProfile> unserialized_profiles_ GUARDED_BY(lock_);

// 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);
};
Expand Down

0 comments on commit deba7c1

Please sign in to comment.