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

Side by Side Diff: components/leveldb_proto/proto_database_impl_unittest.cc

Issue 2340983002: [tracing] Memory dump provider for leveldb_proto (Closed)
Patch Set: Fixes. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « components/leveldb_proto/leveldb_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/leveldb_proto/proto_database_impl.h" 5 #include "components/leveldb_proto/proto_database_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/trace_event/process_memory_dump.h"
20 #include "components/leveldb_proto/leveldb_database.h" 21 #include "components/leveldb_proto/leveldb_database.h"
21 #include "components/leveldb_proto/testing/proto/test.pb.h" 22 #include "components/leveldb_proto/testing/proto/test.pb.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "third_party/leveldatabase/src/include/leveldb/options.h" 25 #include "third_party/leveldatabase/src/include/leveldb/options.h"
25 26
26 using base::MessageLoop; 27 using base::MessageLoop;
27 using base::ScopedTempDir; 28 using base::ScopedTempDir;
28 using testing::Invoke; 29 using testing::Invoke;
29 using testing::Return; 30 using testing::Return;
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 base::RunLoop run_loop; 481 base::RunLoop run_loop;
481 db_thread.task_runner()->PostTaskAndReply( 482 db_thread.task_runner()->PostTaskAndReply(
482 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure()); 483 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure());
483 run_loop.Run(); 484 run_loop.Run();
484 } 485 }
485 486
486 // Test that the LevelDB properly saves entries and that load returns the saved 487 // Test that the LevelDB properly saves entries and that load returns the saved
487 // entries. If |close_after_save| is true, the database will be closed after 488 // entries. If |close_after_save| is true, the database will be closed after
488 // saving and then re-opened to ensure that the data is properly persisted. 489 // saving and then re-opened to ensure that the data is properly persisted.
489 void TestLevelDBSaveAndLoad(bool close_after_save) { 490 void TestLevelDBSaveAndLoad(bool close_after_save) {
491 base::MessageLoop main_loop;
492
490 ScopedTempDir temp_dir; 493 ScopedTempDir temp_dir;
491 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 494 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
492 495
493 EntryMap model = GetSmallModel(); 496 EntryMap model = GetSmallModel();
494 497
495 KeyValueVector save_entries; 498 KeyValueVector save_entries;
496 std::vector<std::string> load_entries; 499 std::vector<std::string> load_entries;
497 KeyVector remove_keys; 500 KeyVector remove_keys;
498 501
499 for (const auto& pair : model) { 502 for (const auto& pair : model) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 KeyValueVector save_entries; 545 KeyValueVector save_entries;
543 std::vector<std::string> load_entries; 546 std::vector<std::string> load_entries;
544 KeyVector remove_keys; 547 KeyVector remove_keys;
545 548
546 EXPECT_FALSE(db->InitWithOptions(temp_dir.GetPath(), options)); 549 EXPECT_FALSE(db->InitWithOptions(temp_dir.GetPath(), options));
547 EXPECT_FALSE(db->Load(&load_entries)); 550 EXPECT_FALSE(db->Load(&load_entries));
548 EXPECT_FALSE(db->Save(save_entries, remove_keys)); 551 EXPECT_FALSE(db->Save(save_entries, remove_keys));
549 } 552 }
550 553
551 TEST(ProtoDatabaseImplLevelDBTest, TestMemoryDatabase) { 554 TEST(ProtoDatabaseImplLevelDBTest, TestMemoryDatabase) {
555 base::MessageLoop main_loop;
556
552 std::unique_ptr<LevelDB> db(new LevelDB(kTestLevelDBClientName)); 557 std::unique_ptr<LevelDB> db(new LevelDB(kTestLevelDBClientName));
553 558
554 std::vector<std::string> load_entries; 559 std::vector<std::string> load_entries;
555 560
556 ASSERT_TRUE(db->Init(base::FilePath())); 561 ASSERT_TRUE(db->Init(base::FilePath()));
557 562
558 ASSERT_TRUE(db->Load(&load_entries)); 563 ASSERT_TRUE(db->Load(&load_entries));
559 EXPECT_EQ(0u, load_entries.size()); 564 EXPECT_EQ(0u, load_entries.size());
560 565
561 KeyValueVector save_entries(1, std::make_pair("foo", "bar")); 566 KeyValueVector save_entries(1, std::make_pair("foo", "bar"));
562 KeyVector remove_keys; 567 KeyVector remove_keys;
563 568
564 ASSERT_TRUE(db->Save(save_entries, remove_keys)); 569 ASSERT_TRUE(db->Save(save_entries, remove_keys));
565 570
566 std::vector<std::string> second_load_entries; 571 std::vector<std::string> second_load_entries;
567 572
568 ASSERT_TRUE(db->Load(&second_load_entries)); 573 ASSERT_TRUE(db->Load(&second_load_entries));
569 EXPECT_EQ(1u, second_load_entries.size()); 574 EXPECT_EQ(1u, second_load_entries.size());
570 } 575 }
571 576
577 TEST(ProtoDatabaseImplLevelDBTest, TestOnMemoryDump) {
nyquist 2016/09/23 15:57:32 TestOnMemoryDumpEmitsData
ssid 2016/09/26 18:13:37 Done.
578 base::MessageLoop main_loop;
579 std::unique_ptr<LevelDB> db(new LevelDB(kTestLevelDBClientName));
580 std::vector<std::string> load_entries;
581 ASSERT_TRUE(db->Init(base::FilePath()));
582 KeyValueVector save_entries(1, std::make_pair("foo", "bar"));
583 KeyVector remove_keys;
584 ASSERT_TRUE(db->Save(save_entries, remove_keys));
585
586 base::trace_event::MemoryDumpArgs dump_args = {
587 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
588 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
589 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
590 db->OnMemoryDump(dump_args, process_memory_dump.get());
591
592 const auto& allocator_dumps = process_memory_dump->allocator_dumps();
593 EXPECT_EQ(2u, allocator_dumps.size());
594 for (const auto& dump : allocator_dumps) {
595 ASSERT_TRUE(dump.first.find("leveldb/leveldb_proto/") == 0 ||
596 dump.first.find("malloc/allocated_objects/") == 0);
597 }
598 }
599
572 } // namespace leveldb_proto 600 } // namespace leveldb_proto
OLDNEW
« no previous file with comments | « components/leveldb_proto/leveldb_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698