diff --git a/Makefile b/Makefile index ca2c2a7c5..66e7ac334 100644 --- a/Makefile +++ b/Makefile @@ -242,6 +242,8 @@ VALGRIND_VER := $(join $(VALGRIND_VER),valgrind) VALGRIND_OPTS = --error-exitcode=$(VALGRIND_ERROR) --leak-check=full +BENCHTOOLOBJECTS = $(BENCH_SOURCES:.cc=.o) $(LIBOBJECTS) $(TESTUTIL) + TESTS = \ db_test \ db_iter_test \ @@ -713,7 +715,7 @@ $(LIBRARY): $(LIBOBJECTS) $(AM_V_AR)rm -f $@ $(AM_V_at)$(AR) $(ARFLAGS) $@ $(LIBOBJECTS) -db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) +db_bench: tools/db_bench.o $(BENCHTOOLOBJECTS) $(AM_LINK) cache_bench: util/cache_bench.o $(LIBOBJECTS) $(TESTUTIL) diff --git a/include/rocksdb/db_bench_tool.h b/include/rocksdb/db_bench_tool.h new file mode 100644 index 000000000..0e33ae96e --- /dev/null +++ b/include/rocksdb/db_bench_tool.h @@ -0,0 +1,9 @@ +// Copyright (c) 2013-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +#pragma once + +namespace rocksdb { +int db_bench_tool(int argc, char** argv); +} // namespace rocksdb diff --git a/src.mk b/src.mk index 3e54fa66d..8c6216771 100644 --- a/src.mk +++ b/src.mk @@ -179,6 +179,9 @@ MOCK_SOURCES = \ table/mock_table.cc \ util/mock_env.cc +BENCH_SOURCES = \ + tools/db_bench_tool.cc + TEST_BENCH_SOURCES = \ third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc \ db/auto_roll_logger_test.cc \ @@ -189,7 +192,7 @@ TEST_BENCH_SOURCES = \ db/comparator_db_test.cc \ db/corruption_test.cc \ db/cuckoo_table_db_test.cc \ - db/db_bench.cc \ + tools/db_bench_tool.cc \ db/dbformat_test.cc \ db/db_iter_test.cc \ db/db_test.cc \ diff --git a/tools/db_bench.cc b/tools/db_bench.cc new file mode 100644 index 000000000..692ff1d23 --- /dev/null +++ b/tools/db_bench.cc @@ -0,0 +1,23 @@ +// Copyright (c) 2013-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// Copyright (c) 2011 The LevelDB Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. See the AUTHORS file for names of contributors. + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#ifndef GFLAGS +#include +int main() { + fprintf(stderr, "Please install gflags to run rocksdb tools\n"); + return 1; +} +#else +#include +int main(int argc, char** argv) { rocksdb::db_bench_tool(argc, argv); } +#endif // GFLAGS diff --git a/db/db_bench.cc b/tools/db_bench_tool.cc similarity index 99% rename from db/db_bench.cc rename to tools/db_bench_tool.cc index 9260501b1..26c9f38e1 100644 --- a/db/db_bench.cc +++ b/tools/db_bench_tool.cc @@ -11,14 +11,6 @@ #define __STDC_FORMAT_MACROS #endif -#ifndef GFLAGS -#include -int main() { - fprintf(stderr, "Please install gflags to run rocksdb tools\n"); - return 1; -} -#else - #ifdef NUMA #include #include @@ -76,6 +68,7 @@ int main() { #include // open/close #endif +namespace { using GFLAGS::ParseCommandLineFlags; using GFLAGS::RegisterFlagValidator; using GFLAGS::SetUsageMessage; @@ -521,7 +514,6 @@ DEFINE_uint64(transaction_lock_timeout, 100, DEFINE_bool(compaction_measure_io_stats, false, "Measure times spents on I/Os while in compactions. "); -namespace { enum rocksdb::CompressionType StringToCompressionType(const char* ctype) { assert(ctype); @@ -541,7 +533,7 @@ enum rocksdb::CompressionType StringToCompressionType(const char* ctype) { return rocksdb::kZSTDNotFinalCompression; fprintf(stdout, "Cannot parse compression type '%s'\n", ctype); - return rocksdb::kSnappyCompression; //default value + return rocksdb::kSnappyCompression; // default value } std::string ColumnFamilyName(size_t i) { @@ -553,7 +545,6 @@ std::string ColumnFamilyName(size_t i) { return std::string(name); } } -} // namespace DEFINE_string(compression_type, "snappy", "Algorithm to use to compress the database"); @@ -764,7 +755,6 @@ enum RepFactory { kCuckoo }; -namespace { enum RepFactory StringToRepFactory(const char* ctype) { assert(ctype); @@ -782,7 +772,6 @@ enum RepFactory StringToRepFactory(const char* ctype) { fprintf(stdout, "Cannot parse memreptable %s\n", ctype); return kSkipList; } -} // namespace static enum RepFactory FLAGS_rep_factory; DEFINE_string(memtablerep, "skip_list", ""); @@ -834,6 +823,7 @@ static const bool FLAGS_deletepercent_dummy __attribute__((unused)) = static const bool FLAGS_table_cache_numshardbits_dummy __attribute__((unused)) = RegisterFlagValidator(&FLAGS_table_cache_numshardbits, &ValidateTableCacheNumshardbits); +} // namespace namespace rocksdb { @@ -2249,7 +2239,7 @@ class Benchmark { count++; thread->stats.FinishedOps(nullptr, nullptr, 1, kOthers); } - if (ptr == nullptr) exit(1); // Disable unused variable warning. + if (ptr == nullptr) exit(1); // Disable unused variable warning. } void Compress(ThreadState *thread) { @@ -4072,9 +4062,7 @@ class Benchmark { } }; -} // namespace rocksdb - -int main(int argc, char** argv) { +int db_bench_tool(int argc, char** argv) { rocksdb::port::InstallStackTraceHandler(); SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) + " [OPTIONS]..."); @@ -4143,5 +4131,4 @@ int main(int argc, char** argv) { benchmark.Run(); return 0; } - -#endif // GFLAGS +} // namespace rocksdb