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_HEAP_USAGE_H_ | |
6 #define BASE_DEBUG_SCOPED_HEAP_USAGE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 namespace base { | |
11 namespace debug { | |
12 | |
13 // By keeping a tally on heap operations, it's possible to track: | |
14 // - the number of alloc/free operations (realloc is one of each?) | |
chrisha
2016/07/21 14:23:31
Makes sense to count one of each, unless the reall
Sigurður Ásgeirsson
2016/08/19 18:21:50
Dunno - I guess there are degenerate cases either
| |
15 // - the number of bytes allocated/freed. | |
16 // - the number of estimated (lower bound) bytes of heap overhead used. | |
chrisha
2016/07/21 14:23:31
Will this always be a lower bound, or strictly an
Sigurður Ásgeirsson
2016/08/19 18:21:49
Dunno - gotta see how that works out. I've dropped
| |
17 // - the high-watermark amount of bytes allocated in the scope. | |
18 // This in turn allows measuring the memory usage and memory usage churn over | |
19 // a scope. | |
20 class ScopedHeapUsage { | |
21 public: | |
22 struct AllocatorUsage { | |
23 // The cumulative number of allocation operations. | |
24 uint64_t alloc_ops; | |
25 // The cumulative number of allocated bytes. | |
26 uint64_t alloc_bytes; | |
27 // The cumulative number of estimated heap overhead bytes. | |
28 uint64_t alloc_overhead_bytes; | |
29 | |
30 // The cumulative number of free operations. | |
31 uint64_t free_ops; | |
32 // The cumulative number of bytes freed. | |
33 // Only recorded if the underlying heap shim can return the size of an | |
34 // allocation. | |
35 uint64_t free_bytes; | |
36 | |
37 // The maximal value of alloc_bytes - free_bytes seen for this thread. | |
chrisha
2016/07/21 14:23:31
Very clear comments, great!
Sigurður Ásgeirsson
2016/08/19 18:21:49
Acknowledged.
| |
38 uint64_t max_allocated_bytes; | |
39 }; | |
40 | |
41 ScopedHeapUsage(); | |
42 ~ScopedHeapUsage(); | |
43 | |
44 const AllocatorUsage& usage_at_creation() const { return usage_at_creation_; } | |
45 | |
46 // TODO(siggi): Maybe add a GetUsageSinceCreation() for convenience? | |
47 | |
48 // Returns this thread's current allocator usage. | |
49 static AllocatorUsage Now(); | |
50 | |
51 // Initializes the underlying heap shim. Must be called zero or one times. | |
52 static void Initialize(); | |
53 static void TearDownForTesting(); | |
chrisha
2016/07/21 14:23:31
nit: protect the TearDownForTesting?
A comment ab
Sigurður Ásgeirsson
2016/08/19 18:21:49
Done.
| |
54 | |
55 private: | |
56 // The allocator usage for this thread, if any. | |
57 AllocatorUsage* thread_usage_; | |
58 | |
59 // The allocator usage captured at creation of this instance. | |
60 AllocatorUsage usage_at_creation_; | |
61 }; | |
62 | |
63 } // namespace debug | |
64 } // namespace base | |
65 | |
66 #endif // BASE_DEBUG_SCOPED_HEAP_USAGE_H_ | |
OLD | NEW |