Commit fe366514 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[heap profiler] Support allocation sizes > 2GB in memlog.

BUG=1002170

Change-Id: I81953154de3326f84e2a240c0ed879bec6ad91cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793358
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695029}
parent ba4a45e8
...@@ -234,10 +234,12 @@ base::Value BuildAllocations(const AllocationMap& allocations, ...@@ -234,10 +234,12 @@ base::Value BuildAllocations(const AllocationMap& allocations,
for (const auto& alloc : allocations) { for (const auto& alloc : allocations) {
int allocator = static_cast<int>(alloc.first.allocator); int allocator = static_cast<int>(alloc.first.allocator);
// We use double to store size and count, as it can precisely represent
// values up to 2^52 ~ 4.5 petabytes.
counts[allocator].push_back( counts[allocator].push_back(
base::Value(static_cast<int>(alloc.second.count))); base::Value(static_cast<double>(alloc.second.count)));
sizes[allocator].push_back( sizes[allocator].push_back(
base::Value(static_cast<int>(alloc.second.size))); base::Value(static_cast<double>(alloc.second.size)));
types[allocator].push_back(base::Value(alloc.first.context_id)); types[allocator].push_back(base::Value(alloc.first.context_id));
nodes[allocator].push_back(base::Value(alloc_to_node_id.at(&alloc.first))); nodes[allocator].push_back(base::Value(alloc_to_node_id.at(&alloc.first)));
} }
...@@ -300,7 +302,9 @@ std::string ExportMemoryMapsAndV2StackTraceToJSON(ExportParams* params) { ...@@ -300,7 +302,9 @@ std::string ExportMemoryMapsAndV2StackTraceToJSON(ExportParams* params) {
result.SetKey("heaps_v2", std::move(heaps_v2)); result.SetKey("heaps_v2", std::move(heaps_v2));
std::string result_json; std::string result_json;
bool ok = base::JSONWriter::Write(result, &result_json); bool ok = base::JSONWriter::WriteWithOptions(
result, base::JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION,
&result_json);
DCHECK(ok); DCHECK(ok);
return result_json; return result_json;
} }
......
...@@ -421,4 +421,43 @@ TEST(ProfilingJsonExporterTest, Context) { ...@@ -421,4 +421,43 @@ TEST(ProfilingJsonExporterTest, Context) {
ASSERT_TRUE(found_no_context); ASSERT_TRUE(found_no_context);
} }
#if defined(ARCH_CPU_64_BITS)
TEST(ProfilingJsonExporterTest, LargeAllocation) {
std::vector<Address> stack1{Address(0x5678), Address(0x1234)};
AllocationMap allocs;
InsertAllocation(&allocs, AllocatorType::kMalloc,
static_cast<size_t>(0x9876543210ul), stack1, 0);
ExportParams params;
params.allocs = std::move(allocs);
std::string json = ExportMemoryMapsAndV2StackTraceToJSON(&params);
// JSON should parse.
base::JSONReader json_reader(base::JSON_PARSE_RFC);
base::Optional<base::Value> result = json_reader.ReadToValue(json);
ASSERT_TRUE(result.has_value()) << json_reader.GetErrorMessage();
// Validate the allocators summary.
const base::Value* malloc_summary =
result.value().FindPath({"allocators", "malloc"});
ASSERT_TRUE(malloc_summary);
const base::Value* malloc_size =
malloc_summary->FindPath({"attrs", "size", "value"});
ASSERT_TRUE(malloc_size);
EXPECT_EQ("9876543210", malloc_size->GetString());
const base::Value* malloc_virtual_size =
malloc_summary->FindPath({"attrs", "virtual_size", "value"});
ASSERT_TRUE(malloc_virtual_size);
EXPECT_EQ("9876543210", malloc_virtual_size->GetString());
// Validate allocators details.
// heaps_v2.allocators.malloc.sizes.reduce((a,s)=>a+s,0).
const base::Value* malloc =
result.value().FindPath({"heaps_v2", "allocators", "malloc"});
const base::Value* malloc_sizes = malloc->FindKey("sizes");
EXPECT_EQ(1u, malloc_sizes->GetList().size());
EXPECT_EQ(0x9876543210ul, malloc_sizes->GetList()[0].GetDouble());
}
#endif
} // namespace heap_profiling } // namespace heap_profiling
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment