| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/memory_allocator_dump.h" | 5 #include "base/trace_event/memory_allocator_dump.h" |
| 6 #include "base/trace_event/process_memory_dump.h" | 6 #include "base/trace_event/process_memory_dump.h" |
| 7 #include "base/trace_event/trace_event_argument.h" | 7 #include "base/trace_event/trace_event_argument.h" |
| 8 #include "components/tracing/common/graphics_memory_dump_provider_android.h" | 8 #include "components/tracing/common/graphics_memory_dump_provider_android.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace tracing { | 11 namespace tracing { |
| 12 | 12 |
| 13 TEST(GraphicsMemoryDumpProviderTest, ParseResponse) { | 13 TEST(GraphicsMemoryDumpProviderTest, ParseResponse) { |
| 14 const char* kDumpBaseName = GraphicsMemoryDumpProvider::kDumpBaseName; | 14 const char* kDumpBaseName = GraphicsMemoryDumpProvider::kDumpBaseName; |
| 15 | 15 |
| 16 base::trace_event::ProcessMemoryDump pmd( | 16 base::trace_event::ProcessMemoryDump pmd( |
| 17 nullptr, {base::trace_event::MemoryDumpLevelOfDetail::DETAILED}); | 17 nullptr, {base::trace_event::MemoryDumpLevelOfDetail::DETAILED}); |
| 18 auto* instance = GraphicsMemoryDumpProvider::GetInstance(); | 18 auto* instance = GraphicsMemoryDumpProvider::GetInstance(); |
| 19 char buf[] = "graphics_total 12\ngraphics_pss 34\ngl_total 56\ngl_pss 78"; | 19 char buf[] = "graphics_total 12\ngraphics_pss 34\ngl_total 56\ngl_pss 78"; |
| 20 instance->ParseResponseAndAddToDump(buf, strlen(buf), &pmd); | 20 instance->ParseResponseAndAddToDump(buf, strlen(buf), &pmd); |
| 21 | 21 |
| 22 // Check the "graphics" row. | 22 // Check the "graphics" row. |
| 23 auto* mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics")); | 23 auto* mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics")); |
| 24 ASSERT_TRUE(mad); | 24 ASSERT_TRUE(mad); |
| 25 std::string json; | 25 std::string json; |
| 26 mad->attributes_for_testing()->AppendAsTraceFormat(&json); | 26 mad->attributes_for_testing()->AppendAsTraceFormat(&json); |
| 27 ASSERT_EQ( | 27 ASSERT_EQ( |
| 28 "{\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | 28 "{\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" |
| 29 "\"22\"}," | 29 "\"c\"}," |
| 30 "\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | 30 "\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" |
| 31 "\"c\"}}", | 31 "\"22\"}}", |
| 32 json); | 32 json); |
| 33 | 33 |
| 34 // Check the "gl" row. | 34 // Check the "gl" row. |
| 35 mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("gl")); | 35 mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("gl")); |
| 36 ASSERT_TRUE(mad); | 36 ASSERT_TRUE(mad); |
| 37 json = ""; | 37 json = ""; |
| 38 mad->attributes_for_testing()->AppendAsTraceFormat(&json); | 38 mad->attributes_for_testing()->AppendAsTraceFormat(&json); |
| 39 ASSERT_EQ( | 39 ASSERT_EQ( |
| 40 "{\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | 40 "{\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" |
| 41 "\"4e\"}," | 41 "\"38\"}," |
| 42 "\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | 42 "\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" |
| 43 "\"38\"}}", | 43 "\"4e\"}}", |
| 44 json); | 44 json); |
| 45 | 45 |
| 46 // Test for truncated input. | 46 // Test for truncated input. |
| 47 pmd.Clear(); | 47 pmd.Clear(); |
| 48 instance->ParseResponseAndAddToDump(buf, strlen(buf) - 14, &pmd); | 48 instance->ParseResponseAndAddToDump(buf, strlen(buf) - 14, &pmd); |
| 49 ASSERT_TRUE(pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics"))); | 49 ASSERT_TRUE(pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics"))); |
| 50 ASSERT_FALSE(pmd.GetAllocatorDump(kDumpBaseName + std::string("gl"))); | 50 ASSERT_FALSE(pmd.GetAllocatorDump(kDumpBaseName + std::string("gl"))); |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace tracing | 53 } // namespace tracing |
| OLD | NEW |