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