From 37d4a79e99f48d45f608f77f926e8a4613ff140b Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Thu, 26 Jan 2017 15:18:07 -0800 Subject: [PATCH] Deserialize custom Statistics object in db_bench Summary: Added -statistics_string to deserialize a Statistics object using the factory functions registered by applications. Closes https://github.com/facebook/rocksdb/pull/1812 Differential Revision: D4469811 Pulled By: ajkr fbshipit-source-id: 2d80862 --- tools/db_bench_tool.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 88807d873..b2b52a2a5 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -459,6 +459,7 @@ DEFINE_bool(verify_checksum, false, "Verify checksum for every block read" " from storage"); DEFINE_bool(statistics, false, "Database statistics"); +DEFINE_string(statistics_string, "", "Serialized statistics string"); static class std::shared_ptr dbstats; DEFINE_int64(writes, -1, "Number of write operations to do. If negative, do" @@ -4878,6 +4879,24 @@ int db_bench_tool(int argc, char** argv) { ParseCommandLineFlags(&argc, &argv, true); FLAGS_compaction_style_e = (rocksdb::CompactionStyle) FLAGS_compaction_style; +#ifndef ROCKSDB_LITE + if (FLAGS_statistics && !FLAGS_statistics_string.empty()) { + fprintf(stderr, + "Cannot provide both --statistics and --statistics_string.\n"); + exit(1); + } + if (!FLAGS_statistics_string.empty()) { + std::unique_ptr custom_stats_guard; + dbstats.reset(NewCustomObject(FLAGS_statistics_string, + &custom_stats_guard)); + custom_stats_guard.release(); + if (dbstats == nullptr) { + fprintf(stderr, "No Statistics registered matching string: %s\n", + FLAGS_statistics_string.c_str()); + exit(1); + } + } +#endif // ROCKSDB_LITE if (FLAGS_statistics) { dbstats = rocksdb::CreateDBStatistics(); }