Skip to content

Commit

Permalink
Fix Statistics in db_stress (#9260)
Browse files Browse the repository at this point in the history
Summary:
The `Statistics` objects are meant to be shared across translation
units, but this was prevented by declaring them static. We need to
ensure they are defined once in the program. The effect is now
`StressTest::PrintStatistics()` can actually print statistics since it
now sees non-null values when `--statistics=1`.

Pull Request resolved: #9260

Reviewed By: zhichao-cao

Differential Revision: D32910162

Pulled By: ajkr

fbshipit-source-id: c926d6f556177987bee5fa3cbc87597803b230ee
  • Loading branch information
ajkr authored and facebook-github-bot committed Dec 8, 2021
1 parent a6a6aad commit ce42ae6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ cpp_library(
"db_stress_tool/db_stress_gflags.cc",
"db_stress_tool/db_stress_listener.cc",
"db_stress_tool/db_stress_shared_state.cc",
"db_stress_tool/db_stress_stat.cc",
"db_stress_tool/db_stress_test_base.cc",
"db_stress_tool/db_stress_tool.cc",
"db_stress_tool/expected_state.cc",
Expand Down
1 change: 1 addition & 0 deletions db_stress_tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_executable(db_stress${ARTIFACT_SUFFIX}
db_stress_gflags.cc
db_stress_listener.cc
db_stress_shared_state.cc
db_stress_stat.cc
db_stress_test_base.cc
db_stress_tool.cc
expected_state.cc
Expand Down
17 changes: 17 additions & 0 deletions db_stress_tool/db_stress_stat.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).

#ifdef GFLAGS

#include "db_stress_tool/db_stress_stat.h"

namespace ROCKSDB_NAMESPACE {

std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;

} // namespace ROCKSDB_NAMESPACE

#endif // GFLAGS
5 changes: 3 additions & 2 deletions db_stress_tool/db_stress_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ DECLARE_bool(histogram);
DECLARE_bool(progress_reports);

namespace ROCKSDB_NAMESPACE {

// Database statistics
static std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
static std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;
extern std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
extern std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;

class Stats {
private:
Expand Down
1 change: 1 addition & 0 deletions src.mk
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ STRESS_LIB_SOURCES = \
db_stress_tool/db_stress_gflags.cc \
db_stress_tool/db_stress_listener.cc \
db_stress_tool/db_stress_shared_state.cc \
db_stress_tool/db_stress_stat.cc \
db_stress_tool/db_stress_test_base.cc \
db_stress_tool/db_stress_tool.cc \
db_stress_tool/expected_state.cc \
Expand Down

0 comments on commit ce42ae6

Please sign in to comment.