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 "gin/v8_isolate_memory_dump_provider.h" | 5 #include "gin/v8_isolate_memory_dump_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/trace_event/process_memory_dump.h" | 9 #include "base/trace_event/process_memory_dump.h" |
10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
11 #include "gin/test/v8_test.h" | 11 #include "gin/test/v8_test.h" |
12 | 12 |
13 namespace gin { | 13 namespace gin { |
14 | 14 |
15 typedef V8Test V8MemoryDumpProviderTest; | 15 typedef V8Test V8MemoryDumpProviderTest; |
16 | 16 |
17 // Checks if the dump provider runs without crashing and dumps root objects. | 17 // Checks if the dump provider runs without crashing and dumps root objects. |
18 TEST_F(V8MemoryDumpProviderTest, DumpStatistics) { | 18 TEST_F(V8MemoryDumpProviderTest, DumpStatistics) { |
19 // Sets the track objects flag for dumping object statistics. Since this is | 19 // Sets the track objects flag for dumping object statistics. Since this is |
20 // not set before V8::InitializePlatform the sizes will not be accurate, but | 20 // not set before V8::InitializePlatform the sizes will not be accurate, but |
21 // this serves the purpose of this test. | 21 // this serves the purpose of this test. |
22 const char track_objects_flag[] = "--track-gc-object-stats"; | 22 const char track_objects_flag[] = "--track-gc-object-stats"; |
23 v8::V8::SetFlagsFromString(track_objects_flag, | 23 v8::V8::SetFlagsFromString(track_objects_flag, |
24 static_cast<int>(strlen(track_objects_flag))); | 24 static_cast<int>(strlen(track_objects_flag))); |
25 | 25 |
26 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | |
27 new base::trace_event::ProcessMemoryDump(nullptr)); | |
28 base::trace_event::MemoryDumpArgs dump_args = { | 26 base::trace_event::MemoryDumpArgs dump_args = { |
29 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | 27 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
| 28 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( |
| 29 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
30 instance_->isolate_memory_dump_provider_for_testing()->OnMemoryDump( | 30 instance_->isolate_memory_dump_provider_for_testing()->OnMemoryDump( |
31 dump_args, process_memory_dump.get()); | 31 dump_args, process_memory_dump.get()); |
32 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | 32 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& |
33 allocator_dumps = process_memory_dump->allocator_dumps(); | 33 allocator_dumps = process_memory_dump->allocator_dumps(); |
34 | 34 |
35 bool did_dump_isolate_stats = false; | 35 bool did_dump_isolate_stats = false; |
36 bool did_dump_space_stats = false; | 36 bool did_dump_space_stats = false; |
37 bool did_dump_objects_stats = false; | 37 bool did_dump_objects_stats = false; |
38 for (const auto& it : allocator_dumps) { | 38 for (const auto& it : allocator_dumps) { |
39 const std::string& dump_name = it.first; | 39 const std::string& dump_name = it.first; |
40 if (dump_name.find("v8/isolate") != std::string::npos) { | 40 if (dump_name.find("v8/isolate") != std::string::npos) { |
41 did_dump_isolate_stats = true; | 41 did_dump_isolate_stats = true; |
42 } | 42 } |
43 if (dump_name.find("heap_spaces") != std::string::npos) { | 43 if (dump_name.find("heap_spaces") != std::string::npos) { |
44 did_dump_space_stats = true; | 44 did_dump_space_stats = true; |
45 } else if (dump_name.find("heap_objects") != std::string::npos) { | 45 } else if (dump_name.find("heap_objects") != std::string::npos) { |
46 did_dump_objects_stats = true; | 46 did_dump_objects_stats = true; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 ASSERT_TRUE(did_dump_isolate_stats); | 50 ASSERT_TRUE(did_dump_isolate_stats); |
51 ASSERT_TRUE(did_dump_space_stats); | 51 ASSERT_TRUE(did_dump_space_stats); |
52 ASSERT_TRUE(did_dump_objects_stats); | 52 ASSERT_TRUE(did_dump_objects_stats); |
53 } | 53 } |
54 | 54 |
55 } // namespace gin | 55 } // namespace gin |
OLD | NEW |