summaryrefslogtreecommitdiffstats
path: root/base/tracked_objects.h
diff options
context:
space:
mode:
authorvadimt <vadimt@chromium.org>2015-03-31 17:09:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-01 00:10:18 +0000
commit379d7fe794b4a200e08ac3f23c69184edef085f7 (patch)
tree82f80ce8e1c9253f027b7c750ef2abbb7431b7d8 /base/tracked_objects.h
parenta7d16cadb7ca6e8d505ae37be437a4ad103d51bc (diff)
downloadchromium_src-379d7fe794b4a200e08ac3f23c69184edef085f7.zip
chromium_src-379d7fe794b4a200e08ac3f23c69184edef085f7.tar.gz
chromium_src-379d7fe794b4a200e08ac3f23c69184edef085f7.tar.bz2
Introducing phased profiling framework.
TrackingSynchronizer can send a "phase completed" message to all processes. Their ThreadData's make a snapshot of task deaths and store it in a static map, associating with the number of the completed phase. They also clean the death data. When requested to return a tasks snapshot, ThreadData returns that saved map, adding a snapshot of current task deaths as a separate "current" phase. The rest of code was transformed to work with the map of snapshots instead of a single snapshot. BUG=456354 Review URL: https://codereview.chromium.org/985773002 Cr-Commit-Position: refs/heads/master@{#323151}
Diffstat (limited to 'base/tracked_objects.h')
-rw-r--r--base/tracked_objects.h74
1 files changed, 51 insertions, 23 deletions
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 34c3667..9643265 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -18,6 +18,7 @@
#include "base/gtest_prod_util.h"
#include "base/lazy_instance.h"
#include "base/location.h"
+#include "base/process/process_handle.h"
#include "base/profiler/alternate_timer.h"
#include "base/profiler/tracked_time.h"
#include "base/synchronization/lock.h"
@@ -147,10 +148,14 @@ struct TrackingInfo;
// TaskSnapshot instances, so that such instances can be sorted and
// aggregated (and remain frozen during our processing).
//
-// The ProcessDataSnapshot struct is a serialized representation of the list
-// of ThreadData objects for a process. It holds a set of TaskSnapshots
-// and tracks parent/child relationships for the executed tasks. The statistics
-// in a snapshot are gathered asynhcronously relative to their ongoing updates.
+// Profiling consists of phases. The concrete phase in the sequence of phases is
+// identified by its 0-based index.
+//
+// The ProcessDataPhaseSnapshot struct is a serialized representation of the
+// list of ThreadData objects for a process for a concrete profiling phase. It
+// holds a set of TaskSnapshots and tracks parent/child relationships for the
+// executed tasks. The statistics in a snapshot are gathered asynhcronously
+// relative to their ongoing updates.
// It is possible, though highly unlikely, that stats could be incorrectly
// recorded by this process (all data is held in 32 bit ints, but we are not
// atomically collecting all data, so we could have count that does not, for
@@ -342,9 +347,15 @@ struct BASE_EXPORT TaskSnapshot {
// We also have a linked list of ThreadData instances, and that list is used to
// harvest data from all existing instances.
+struct ProcessDataPhaseSnapshot;
struct ProcessDataSnapshot;
class BASE_EXPORT TaskStopwatch;
+// Map from profiling phase number to the process-wide snapshotted
+// representation of the list of ThreadData objects that died during the given
+// phase.
+typedef std::map<int, ProcessDataPhaseSnapshot> PhasedProcessDataSnapshotMap;
+
class BASE_EXPORT ThreadData {
public:
// Current allowable states of the tracking system. The states can vary
@@ -376,8 +387,9 @@ class BASE_EXPORT ThreadData {
// This may return NULL if the system is disabled for any reason.
static ThreadData* Get();
- // Fills |process_data| with all the recursive results in our process.
- static void Snapshot(ProcessDataSnapshot* process_data);
+ // Fills |process_data_snapshot| with phased snapshots of all profiling
+ // phases, including the current one.
+ static void Snapshot(ProcessDataSnapshot* process_data_snapshot);
// Finds (or creates) a place to count births from the given location in this
// thread, and increment that tally.
@@ -403,16 +415,14 @@ class BASE_EXPORT ThreadData {
// the task.
// The |end_of_run| was just obtained by a call to Now() (just after the task
// finished).
- static void TallyRunOnWorkerThreadIfTracking(
- const Births* birth,
- const TrackedTime& time_posted,
- const TaskStopwatch& stopwatch);
+ static void TallyRunOnWorkerThreadIfTracking(const Births* birth,
+ const TrackedTime& time_posted,
+ const TaskStopwatch& stopwatch);
// Record the end of execution in region, generally corresponding to a scope
// being exited.
- static void TallyRunInAScopedRegionIfTracking(
- const Births* birth,
- const TaskStopwatch& stopwatch);
+ static void TallyRunInAScopedRegionIfTracking(const Births* birth,
+ const TaskStopwatch& stopwatch);
const std::string& thread_name() const { return thread_name_; }
@@ -514,16 +524,21 @@ class BASE_EXPORT ThreadData {
// Snapshot (under a lock) the profiled data for the tasks in each ThreadData
// instance. Also updates the |birth_counts| tally for each task to keep
// track of the number of living instances of the task.
- static void SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data,
- BirthCountMap* birth_counts);
+ static void SnapshotAllExecutedTasks(
+ ProcessDataPhaseSnapshot* process_data_phase,
+ BirthCountMap* birth_counts);
+
+ // Fills |process_data_phase| with all the recursive results in our process.
+ static void SnapshotCurrentPhase(
+ ProcessDataPhaseSnapshot* process_data_phase);
// Snapshots (under a lock) the profiled data for the tasks for this thread
// and writes all of the executed tasks' data -- i.e. the data for the tasks
- // with with entries in the death_map_ -- into |process_data|. Also updates
- // the |birth_counts| tally for each task to keep track of the number of
- // living instances of the task -- that is, each task maps to the number of
+ // with with entries in the death_map_ -- into |process_data_phase|. Also
+ // updates the |birth_counts| tally for each task to keep track of the number
+ // of living instances of the task -- that is, each task maps to the number of
// births for the task that have not yet been balanced by a death.
- void SnapshotExecutedTasks(ProcessDataSnapshot* process_data,
+ void SnapshotExecutedTasks(ProcessDataPhaseSnapshot* process_data_phase,
BirthCountMap* birth_counts);
// Using our lock, make a copy of the specified maps. This call may be made
@@ -747,16 +762,29 @@ struct BASE_EXPORT ParentChildPairSnapshot {
};
//------------------------------------------------------------------------------
-// A snapshotted representation of the list of ThreadData objects for a process.
+// A snapshotted representation of the list of ThreadData objects for a process,
+// for a single profiling phase.
+
+struct BASE_EXPORT ProcessDataPhaseSnapshot {
+ public:
+ ProcessDataPhaseSnapshot();
+ ~ProcessDataPhaseSnapshot();
+
+ std::vector<TaskSnapshot> tasks;
+ std::vector<ParentChildPairSnapshot> descendants;
+};
+
+//------------------------------------------------------------------------------
+// A snapshotted representation of the list of ThreadData objects for a process,
+// for all profiling phases, including the current one.
struct BASE_EXPORT ProcessDataSnapshot {
public:
ProcessDataSnapshot();
~ProcessDataSnapshot();
- std::vector<TaskSnapshot> tasks;
- std::vector<ParentChildPairSnapshot> descendants;
- int process_id;
+ PhasedProcessDataSnapshotMap phased_process_data_snapshots;
+ base::ProcessId process_id;
};
} // namespace tracked_objects