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

Unified Diff: base/tracked_objects.h

Issue 2386123003: Add heap allocator usage to task profiler. (Closed)
Patch Set: Figure out where the @#$%! corruption is coming from. Move heap tracking to TaskStopwatch." Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: base/tracked_objects.h
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 7ef0317c39bb1712873d9a78856b5c32220aa1fd..2d60f9863cb554b83b11a785eeab46355ee13695 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -14,8 +14,10 @@
#include <utility>
#include <vector>
+#include "base/allocator/features.h"
#include "base/atomicops.h"
#include "base/base_export.h"
+#include "base/debug/scoped_thread_heap_usage.h"
#include "base/containers/hash_tables.h"
#include "base/gtest_prod_util.h"
#include "base/lazy_instance.h"
@@ -248,6 +250,8 @@ class BASE_EXPORT Births: public BirthOnThread {
DISALLOW_COPY_AND_ASSIGN(Births);
};
+// forward
+class DeathData;
//------------------------------------------------------------------------------
// A "snapshotted" representation of the DeathData class.
@@ -265,7 +269,14 @@ struct BASE_EXPORT DeathDataSnapshot {
int32_t run_duration_sample,
int32_t queue_duration_sum,
int32_t queue_duration_max,
- int32_t queue_duration_sample);
+ int32_t queue_duration_sample,
+ int32_t alloc_ops,
+ int32_t free_ops,
+ int32_t allocated_bytes,
+ int32_t freed_bytes,
+ int32_t alloc_overhead_bytes,
+ int32_t max_allocated_bytes);
+ DeathDataSnapshot(const DeathData& death_data);
~DeathDataSnapshot();
// Calculates and returns the delta between this snapshot and an earlier
@@ -279,6 +290,13 @@ struct BASE_EXPORT DeathDataSnapshot {
int32_t queue_duration_sum;
int32_t queue_duration_max;
int32_t queue_duration_sample;
+
+ int32_t alloc_ops;
+ int32_t free_ops;
+ int32_t allocated_bytes;
+ int32_t freed_bytes;
+ int32_t alloc_overhead_bytes;
+ int32_t max_allocated_bytes;
};
//------------------------------------------------------------------------------
@@ -287,13 +305,7 @@ struct BASE_EXPORT DeathDataSnapshot {
struct DeathDataPhaseSnapshot {
DeathDataPhaseSnapshot(int profiling_phase,
- int count,
- int32_t run_duration_sum,
- int32_t run_duration_max,
- int32_t run_duration_sample,
- int32_t queue_duration_sum,
- int32_t queue_duration_max,
- int32_t queue_duration_sample,
+ const DeathData& death_data,
const DeathDataPhaseSnapshot* prev);
// Profiling phase at which completion this snapshot was taken.
@@ -326,9 +338,25 @@ class BASE_EXPORT DeathData {
// Update stats for a task destruction (death) that had a Run() time of
// |duration|, and has had a queueing delay of |queue_duration|.
- void RecordDeath(const int32_t queue_duration,
- const int32_t run_duration,
- const uint32_t random_number);
+ void RecordDurations(const int32_t queue_duration,
+ const int32_t run_duration,
+ const uint32_t random_number);
+ // Update stats for a task desctruction that performed |alloc_ops|
+ // allocations, |free_ops| frees, allocated |allocated_bytes| bytes, freed
+ // |freed_bytes|, where an estimated |alloc_overhead_bytes| went to heap
+ // overhead, and where at most |max_allocated_bytes| were outstanding at any
+ // one time.
+ // Note that |alloc_overhead_bytes|/|alloc_ops| yields the average estimated
+ // heap overhead of allocations in the task, and |allocated_bytes|/|alloc_ops|
+ // yields the average size of allocation.
+ // Note also that |allocated_bytes|-|freed_bytes| yields the net heap memory
+ // usage of the task, which can be negative.
+ void RecordAllocations(const uint32_t alloc_ops,
+ const uint32_t free_ops,
+ const uint32_t allocated_bytes,
+ const uint32_t freed_bytes,
+ const uint32_t alloc_overhead_bytes,
+ const uint32_t max_allocated_bytes);
// Metrics and past snapshots accessors, used only for serialization and in
// tests.
@@ -351,6 +379,22 @@ class BASE_EXPORT DeathData {
int32_t queue_duration_sample() const {
return base::subtle::NoBarrier_Load(&queue_duration_sample_);
}
+ int32_t alloc_ops() const {
+ return base::subtle::NoBarrier_Load(&alloc_ops_);
+ }
+ int32_t free_ops() const { return base::subtle::NoBarrier_Load(&free_ops_); }
+ int32_t allocated_bytes() const {
+ return base::subtle::NoBarrier_Load(&allocated_bytes_);
+ }
+ int32_t freed_bytes() const {
+ return base::subtle::NoBarrier_Load(&freed_bytes_);
+ }
+ int32_t alloc_overhead_bytes() const {
+ return base::subtle::NoBarrier_Load(&alloc_overhead_bytes_);
+ }
+ int32_t max_allocated_bytes() const {
+ return base::subtle::NoBarrier_Load(&max_allocated_bytes_);
+ }
const DeathDataPhaseSnapshot* last_phase_snapshot() const {
return last_phase_snapshot_;
}
@@ -388,6 +432,23 @@ class BASE_EXPORT DeathData {
base::subtle::Atomic32 run_duration_sample_;
base::subtle::Atomic32 queue_duration_sample_;
+ // The cumulative number of allocation and free operations.
+ base::subtle::Atomic32 alloc_ops_;
+ base::subtle::Atomic32 free_ops_;
+
+ // The number of bytes allocated by the task.
+ base::subtle::Atomic32 allocated_bytes_;
+
+ // The number of bytes freed by the task.
+ base::subtle::Atomic32 freed_bytes_;
+
+ // The cumulative number of overhead bytes. Where available this yields an
+ // estimate of the heap overhead for allocations.
+ base::subtle::Atomic32 alloc_overhead_bytes_;
+
+ // The high-watermark for the number of outstanding heap allocated bytes.
+ base::subtle::Atomic32 max_allocated_bytes_;
+
// Snapshot of this death data made at the last profiling phase completion, if
// any. DeathData owns the whole list starting with this pointer.
// Can be accessed only on the snapshot thread.
@@ -755,6 +816,10 @@ class BASE_EXPORT TaskStopwatch {
// this thread during that period.
int32_t RunDurationMs() const;
+#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
+ const base::debug::HeapUsageTracker& heap_usage() const;
+#endif
+
// Returns tracking info for the current thread.
ThreadData* GetThreadData() const;
@@ -762,6 +827,10 @@ class BASE_EXPORT TaskStopwatch {
// Time when the stopwatch was started.
TrackedTime start_time_;
+#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
+ base::debug::HeapUsageTracker heap_usage_;
+#endif
+
// Wallclock duration of the task.
int32_t wallclock_duration_ms_;

Powered by Google App Engine
This is Rietveld 408576698