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

Unified Diff: base/trace_event/heap_profiler_heap_dump_writer_unittest.cc

Issue 1877313003: [tracing] Track number of allocations in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indentation. Created 4 years, 8 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
« no previous file with comments | « base/trace_event/heap_profiler_heap_dump_writer.cc ('k') | base/trace_event/malloc_dump_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/heap_profiler_heap_dump_writer_unittest.cc
diff --git a/base/trace_event/heap_profiler_heap_dump_writer_unittest.cc b/base/trace_event/heap_profiler_heap_dump_writer_unittest.cc
index 894de6928ad543e4297de33282d94b5ddc839e93..8faa5cf2f91a1be164bf5973f6b17c0466766f80 100644
--- a/base/trace_event/heap_profiler_heap_dump_writer_unittest.cc
+++ b/base/trace_event/heap_profiler_heap_dump_writer_unittest.cc
@@ -68,11 +68,11 @@ std::unique_ptr<const DictionaryValue> WriteAndReadBackEntry(Entry entry) {
}
// Given a desired stack frame ID and type ID, looks up the entry in the set and
-// asserts that it is present and has the expected size.
-void AssertSizeEq(const std::set<Entry>& entries,
- int stack_frame_id,
- int type_id,
- size_t expected_size) {
+// asserts that it is present and has the expected size and count.
+void AssertSizeAndCountEq(const std::set<Entry>& entries,
+ int stack_frame_id,
+ int type_id,
+ const AllocationMetrics& expected) {
// The comparison operator for |Entry| does not take size into account, so by
// setting only stack frame ID and type ID, the real entry can be found.
Entry entry;
@@ -82,8 +82,11 @@ void AssertSizeEq(const std::set<Entry>& entries,
ASSERT_NE(entries.end(), it) << "No entry found for sf = " << stack_frame_id
<< ", type = " << type_id << ".";
- ASSERT_EQ(expected_size, it->size) << "Wrong size for sf = " << stack_frame_id
+ ASSERT_EQ(expected.size, it->size) << "Wrong size for sf = " << stack_frame_id
<< ", type = " << type_id << ".";
+ ASSERT_EQ(expected.count, it->count)
+ << "Wrong count for sf = " << stack_frame_id << ", type = " << type_id
+ << ".";
}
// Given a desired stack frame ID and type ID, asserts that no entry was dumped
@@ -107,6 +110,7 @@ TEST(HeapDumpWriterTest, BacktraceIndex) {
entry.stack_frame_id = -1; // -1 means empty backtrace.
entry.type_id = 0;
entry.size = 1;
+ entry.count = 1;
std::unique_ptr<const DictionaryValue> json_entry =
WriteAndReadBackEntry(entry);
@@ -129,6 +133,7 @@ TEST(HeapDumpWriterTest, TypeId) {
entry.type_id = -1; // -1 means sum over all types.
entry.stack_frame_id = 0;
entry.size = 1;
+ entry.count = 1;
std::unique_ptr<const DictionaryValue> json_entry =
WriteAndReadBackEntry(entry);
@@ -145,7 +150,7 @@ TEST(HeapDumpWriterTest, TypeId) {
ASSERT_EQ("2", type_id);
}
-TEST(HeapDumpWriterTest, SizeIsHexadecimalString) {
+TEST(HeapDumpWriterTest, SizeAndCountAreHexadecimal) {
// Take a number between 2^63 and 2^64 (or between 2^31 and 2^32 if |size_t|
// is not 64 bits).
const size_t large_value =
@@ -156,6 +161,7 @@ TEST(HeapDumpWriterTest, SizeIsHexadecimalString) {
entry.type_id = 0;
entry.stack_frame_id = 0;
entry.size = large_value;
+ entry.count = large_value;
std::unique_ptr<const DictionaryValue> json_entry =
WriteAndReadBackEntry(entry);
@@ -163,10 +169,14 @@ TEST(HeapDumpWriterTest, SizeIsHexadecimalString) {
std::string size;
ASSERT_TRUE(json_entry->GetString("size", &size));
ASSERT_EQ(large_value_str, size);
+
+ std::string count;
+ ASSERT_TRUE(json_entry->GetString("count", &count));
+ ASSERT_EQ(large_value_str, count);
}
TEST(HeapDumpWriterTest, BacktraceTypeNameTable) {
- hash_map<AllocationContext, size_t> bytes_by_context;
+ hash_map<AllocationContext, AllocationMetrics> metrics_by_context;
AllocationContext ctx = AllocationContext::Empty();
ctx.backtrace.frames[0] = kBrowserMain;
@@ -174,38 +184,39 @@ TEST(HeapDumpWriterTest, BacktraceTypeNameTable) {
ctx.type_name = kInt;
// 10 bytes with context { type: int, bt: [BrowserMain, CreateWidget] }.
- bytes_by_context[ctx] = 10;
+ metrics_by_context[ctx] = {10, 5};
ctx.type_name = kBool;
// 18 bytes with context { type: bool, bt: [BrowserMain, CreateWidget] }.
- bytes_by_context[ctx] = 18;
+ metrics_by_context[ctx] = {18, 18};
ctx.backtrace.frames[0] = kRendererMain;
ctx.backtrace.frames[1] = kInitialize;
// 30 bytes with context { type: bool, bt: [RendererMain, Initialize] }.
- bytes_by_context[ctx] = 30;
+ metrics_by_context[ctx] = {30, 30};
ctx.type_name = kString;
// 19 bytes with context { type: string, bt: [RendererMain, Initialize] }.
- bytes_by_context[ctx] = 19;
+ metrics_by_context[ctx] = {19, 4};
// At this point the heap looks like this:
//
- // | | CrWidget <- BrMain | Init <- RenMain | Sum |
- // +--------+--------------------+-----------------+-----+
- // | int | 10 | 0 | 10 |
- // | bool | 18 | 30 | 48 |
- // | string | 0 | 19 | 19 |
- // +--------+--------------------+-----------------+-----+
- // | Sum | 28 | 49 | 77 |
+ // | | CrWidget <- BrMain | Init <- RenMain | Sum |
+ // +--------+--------------------+-----------------+-------------+
+ // | | size count | size count | size count |
+ // | int | 10 5 | 0 0 | 10 5 |
+ // | bool | 18 18 | 30 30 | 48 48 |
+ // | string | 0 0 | 19 4 | 19 4 |
+ // +--------+--------------------+-----------------+-------------+
+ // | Sum | 28 23 | 49 34 | 77 57 |
auto sf_deduplicator = WrapUnique(new StackFrameDeduplicator);
auto tn_deduplicator = WrapUnique(new TypeNameDeduplicator);
HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get());
- const std::set<Entry>& dump = writer.Summarize(bytes_by_context);
+ const std::set<Entry>& dump = writer.Summarize(metrics_by_context);
// Get the indices of the backtraces and types by adding them again to the
// deduplicator. Because they were added before, the same number is returned.
@@ -220,57 +231,61 @@ TEST(HeapDumpWriterTest, BacktraceTypeNameTable) {
int type_id_string = tn_deduplicator->Insert(kString);
// Full heap should have size 77.
- AssertSizeEq(dump, -1, -1, 77);
+ AssertSizeAndCountEq(dump, -1, -1, {77, 57});
- // 49 bytes were allocated in RendererMain and children. Also check the type
- // breakdown.
- AssertSizeEq(dump, bt_renderer_main, -1, 49);
- AssertSizeEq(dump, bt_renderer_main, type_id_bool, 30);
- AssertSizeEq(dump, bt_renderer_main, type_id_string, 19);
+ // 49 bytes in 34 chunks were allocated in RendererMain and children. Also
+ // check the type breakdown.
+ AssertSizeAndCountEq(dump, bt_renderer_main, -1, {49, 34});
+ AssertSizeAndCountEq(dump, bt_renderer_main, type_id_bool, {30, 30});
+ AssertSizeAndCountEq(dump, bt_renderer_main, type_id_string, {19, 4});
- // 28 bytes were allocated in BrowserMain and children. Also check the type
- // breakdown.
- AssertSizeEq(dump, bt_browser_main, -1, 28);
- AssertSizeEq(dump, bt_browser_main, type_id_int, 10);
- AssertSizeEq(dump, bt_browser_main, type_id_bool, 18);
+ // 28 bytes in 23 chunks were allocated in BrowserMain and children. Also
+ // check the type breakdown.
+ AssertSizeAndCountEq(dump, bt_browser_main, -1, {28, 23});
+ AssertSizeAndCountEq(dump, bt_browser_main, type_id_int, {10, 5});
+ AssertSizeAndCountEq(dump, bt_browser_main, type_id_bool, {18, 18});
// In this test all bytes are allocated in leaf nodes, so check again one
// level deeper.
- AssertSizeEq(dump, bt_renderer_main_initialize, -1, 49);
- AssertSizeEq(dump, bt_renderer_main_initialize, type_id_bool, 30);
- AssertSizeEq(dump, bt_renderer_main_initialize, type_id_string, 19);
- AssertSizeEq(dump, bt_browser_main_create_widget, -1, 28);
- AssertSizeEq(dump, bt_browser_main_create_widget, type_id_int, 10);
- AssertSizeEq(dump, bt_browser_main_create_widget, type_id_bool, 18);
+ AssertSizeAndCountEq(dump, bt_renderer_main_initialize, -1, {49, 34});
+ AssertSizeAndCountEq(dump, bt_renderer_main_initialize, type_id_bool,
+ {30, 30});
+ AssertSizeAndCountEq(dump, bt_renderer_main_initialize, type_id_string,
+ {19, 4});
+ AssertSizeAndCountEq(dump, bt_browser_main_create_widget, -1, {28, 23});
+ AssertSizeAndCountEq(dump, bt_browser_main_create_widget, type_id_int,
+ {10, 5});
+ AssertSizeAndCountEq(dump, bt_browser_main_create_widget, type_id_bool,
+ {18, 18});
// The type breakdown of the entrie heap should have been dumped as well.
- AssertSizeEq(dump, -1, type_id_int, 10);
- AssertSizeEq(dump, -1, type_id_bool, 48);
- AssertSizeEq(dump, -1, type_id_string, 19);
+ AssertSizeAndCountEq(dump, -1, type_id_int, {10, 5});
+ AssertSizeAndCountEq(dump, -1, type_id_bool, {48, 48});
+ AssertSizeAndCountEq(dump, -1, type_id_string, {19, 4});
}
TEST(HeapDumpWriterTest, InsignificantValuesNotDumped) {
- hash_map<AllocationContext, size_t> bytes_by_context;
+ hash_map<AllocationContext, AllocationMetrics> metrics_by_context;
AllocationContext ctx = AllocationContext::Empty();
ctx.backtrace.frames[0] = kBrowserMain;
ctx.backtrace.frames[1] = kCreateWidget;
- // 0.5a KiB in BrowserMain -> CreateWidget itself.
- bytes_by_context[ctx] = 512;
+ // 0.5 KiB and 1 chunk in BrowserMain -> CreateWidget itself.
+ metrics_by_context[ctx] = {512, 1};
- // 1 MiB in BrowserMain -> CreateWidget -> GetBitmap.
+ // 1 MiB and 1 chunk in BrowserMain -> CreateWidget -> GetBitmap.
ctx.backtrace.frames[2] = kGetBitmap;
- bytes_by_context[ctx] = 1024 * 1024;
+ metrics_by_context[ctx] = {1024 * 1024, 1};
- // 0.5 KiB in BrowserMain -> CreateWidget -> Initialize.
+ // 0.5 KiB and 1 chunk in BrowserMain -> CreateWidget -> Initialize.
ctx.backtrace.frames[2] = kInitialize;
- bytes_by_context[ctx] = 512;
+ metrics_by_context[ctx] = {512, 1};
auto sf_deduplicator = WrapUnique(new StackFrameDeduplicator);
auto tn_deduplicator = WrapUnique(new TypeNameDeduplicator);
HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get());
- const std::set<Entry>& dump = writer.Summarize(bytes_by_context);
+ const std::set<Entry>& dump = writer.Summarize(metrics_by_context);
// Get the indices of the backtraces and types by adding them again to the
// deduplicator. Because they were added before, the same number is returned.
@@ -281,17 +296,19 @@ TEST(HeapDumpWriterTest, InsignificantValuesNotDumped) {
int bt_get_bitmap = sf_deduplicator->Insert(bt0, bt0 + 3);
int bt_initialize = sf_deduplicator->Insert(bt1, bt1 + 3);
- // Full heap should have size of 1 MiB + 1 KiB.
- AssertSizeEq(dump, -1, -1 /* No type specified */, 1024 * 1024 + 512 + 512);
+ // Full heap should have size of 1 MiB + 1 KiB and 3 chunks.
+ AssertSizeAndCountEq(dump, -1, -1 /* No type specified */,
+ {1024 * 1024 + 512 + 512, 3});
- // |GetBitmap| allocated 1 MiB.
- AssertSizeEq(dump, bt_get_bitmap, -1, 1024 * 1024);
+ // |GetBitmap| allocated 1 MiB and 1 chunk.
+ AssertSizeAndCountEq(dump, bt_get_bitmap, -1, {1024 * 1024, 1});
// Because |GetBitmap| was dumped, all of its parent nodes should have been
// dumped too. |CreateWidget| has 1 MiB in |GetBitmap|, 512 bytes in
- // |Initialize|, and 512 bytes of its own.
- AssertSizeEq(dump, bt_create_widget, -1, 1024 * 1024 + 512 + 512);
- AssertSizeEq(dump, bt_browser_main, -1, 1024 * 1024 + 512 + 512);
+ // |Initialize|, and 512 bytes of its own and each in 1 chunk.
+ AssertSizeAndCountEq(dump, bt_create_widget, -1,
+ {1024 * 1024 + 512 + 512, 3});
+ AssertSizeAndCountEq(dump, bt_browser_main, -1, {1024 * 1024 + 512 + 512, 3});
// Initialize was not significant, it should not have been dumped.
AssertNotDumped(dump, bt_initialize, -1);
« no previous file with comments | « base/trace_event/heap_profiler_heap_dump_writer.cc ('k') | base/trace_event/malloc_dump_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698