OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_DEBUG_SCOPED_THREAD_HEAP_USAGE_H_ | |
6 #define BASE_DEBUG_SCOPED_THREAD_HEAP_USAGE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/allocator/features.h" | |
11 #include "base/threading/thread_checker.h" | |
12 | |
13 namespace base { | |
14 namespace allocator { | |
15 struct AllocatorDispatch; | |
16 } // namespace allocator | |
17 | |
18 namespace debug { | |
19 | |
20 // By keeping a tally on heap operations, it's possible to track: | |
21 // - the number of alloc/free operations (realloc is one of each?) | |
chrisha
2016/09/01 20:29:18
Answer the question before landing this? Is reallo
Primiano Tucci (use gerrit)
2016/09/02 17:31:20
I think conceptually is fine counting realloc as o
Sigurður Ásgeirsson
2016/09/06 14:58:54
Done.
Sigurður Ásgeirsson
2016/09/06 14:58:54
Done.
| |
22 // - the number of bytes allocated/freed. | |
23 // - the number of estimated bytes of heap overhead used. | |
24 // - the high-watermark amount of bytes allocated in the scope. | |
25 // This in turn allows measuring the memory usage and memory usage churn over | |
26 // a scope. Note that scopes must be cleanly nested, and each scope must be | |
27 // destroyed on the thread where it's created. | |
28 class BASE_EXPORT ScopedThreadHeapUsage { | |
29 public: | |
30 struct ThreadAllocatorUsage { | |
31 // The cumulative number of allocation operations. | |
32 uint64_t alloc_ops; | |
33 | |
34 // The cumulative number of allocated bytes. Where available, this is | |
35 // inclusive heap padding and estimated or actual heap overhead. | |
36 uint64_t alloc_bytes; | |
37 | |
38 // Where available, cumulative number of heap padding heap | |
39 // and overhead bytes. | |
40 uint64_t alloc_overhead_bytes; | |
chrisha
2016/09/01 20:29:17
Is this ever available? There's no way to get this
Sigurður Ásgeirsson
2016/09/06 14:58:54
It's the difference between the requested size and
| |
41 | |
42 // The cumulative number of free operations. | |
43 uint64_t free_ops; | |
44 | |
45 // The cumulative number of bytes freed. | |
46 // Only recorded if the underlying heap shim can return the size of an | |
47 // allocation. | |
48 uint64_t free_bytes; | |
49 | |
50 // The maximal value of alloc_bytes - free_bytes seen for this thread. | |
51 // Only recorded if the underlying heap shim supports returning the size of | |
52 // an allocation. | |
53 uint64_t max_allocated_bytes; | |
54 }; | |
55 | |
56 ScopedThreadHeapUsage(); | |
57 ~ScopedThreadHeapUsage(); | |
58 | |
59 const ThreadAllocatorUsage& usage_at_creation() const { | |
60 return usage_at_creation_; | |
61 } | |
62 | |
63 // Returns this thread's current allocator usage. | |
64 static ThreadAllocatorUsage Now(); | |
65 | |
66 // Initializes the underlying heap shim. Must be called zero or one times. | |
67 // May only be called if the USE_EXPERIMENTAL_ALLOCATOR_SHIM is enabled. | |
68 static void Initialize(); | |
69 | |
70 protected: | |
71 // Exposed for testing only - note that it's safe to re-Initialize() after | |
72 // tearing down in tests. | |
73 static void TearDownForTesting(); | |
74 static base::allocator::AllocatorDispatch* GetDispatchForTesting(); | |
75 | |
76 private: | |
77 static void EnsureTLSInitalized(); | |
78 | |
79 ThreadChecker thread_checker_; | |
80 // The allocator usage captured at creation of this instance. | |
81 ThreadAllocatorUsage usage_at_creation_; | |
82 }; | |
83 | |
84 } // namespace debug | |
85 } // namespace base | |
86 | |
87 #endif // BASE_DEBUG_SCOPED_THREAD_HEAP_USAGE_H_ | |
OLD | NEW |