memory manage statistics

Summary:
Earlier Statistics object was a raw pointer. This meant the user had to clear up
the Statistics object after creating the database. In most use cases the database is created in a function and the statistics pointer is out of scope. Hence the statistics object would never be deleted.
Now Using a shared_ptr to manage this.

Want this in before the next release.

Test Plan: make all check.

Reviewers: dhruba, emayanke

Reviewed By: emayanke

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9735
This commit is contained in:
Abhishek Kona
2013-03-27 11:27:39 -07:00
parent ecd8db0200
commit 63f216ee0a
8 changed files with 15 additions and 23 deletions

View File

@@ -39,7 +39,6 @@ Options::Options()
expanded_compaction_factor(25),
source_compaction_factor(1),
max_grandparent_overlap_factor(10),
statistics(nullptr),
disableDataSync(false),
use_fsync(false),
db_stats_log_interval(1800),

View File

@@ -24,7 +24,7 @@ class DoNothingStopWatch : public StopWatch {
class ScopedRecordingStopWatch : public StopWatch {
public:
ScopedRecordingStopWatch(Env * const env,
Statistics * const statistics,
std::shared_ptr<Statistics> statistics,
const Histograms histogram_name) :
env_(env),
start_time_(env->NowMicros()),
@@ -43,7 +43,7 @@ class ScopedRecordingStopWatch : public StopWatch {
private:
Env* const env_;
const uint64_t start_time_;
Statistics* const statistics_;
std::shared_ptr<Statistics> statistics_;
const Histograms histogram_name_;
};
@@ -51,13 +51,13 @@ class ScopedRecordingStopWatch : public StopWatch {
namespace stats {
// Helper method
std::unique_ptr<StopWatch> StartStopWatch(Env * const env,
Statistics * const statistics,
std::shared_ptr<Statistics> stats,
Histograms histogram_name) {
assert(env);
if (statistics != nullptr) {
if (stats) {
return std::unique_ptr<StopWatch>(new ScopedRecordingStopWatch(
env,
statistics,
stats,
histogram_name));
} else {
return std::unique_ptr<StopWatch>(new DoNothingStopWatch());