@@ -21,10 +21,20 @@ Timings::Timings() {
2121 reset ();
2222}
2323
24- void Timings::reset () {
24+ Timings::~Timings () {
25+ std::lock_guard<std::mutex> lg (histogram_mutex);
2526 for (auto & t : timings) {
26- if (t) {
27- t->reset ();
27+ delete t;
28+ }
29+ }
30+
31+ void Timings::reset () {
32+ {
33+ std::lock_guard<std::mutex> lg (histogram_mutex);
34+ for (auto & t : timings) {
35+ if (t) {
36+ t.load ()->reset ();
37+ }
2838 }
2939 }
3040
@@ -50,7 +60,7 @@ void Timings::collect(cb::mcbp::ClientOpcode opcode,
5060std::string Timings::generate (cb::mcbp::ClientOpcode opcode) {
5161 auto * histoPtr =
5262 timings[std::underlying_type<cb::mcbp::ClientOpcode>::type (opcode)]
53- .get ();
63+ .load ();
5464 if (histoPtr) {
5565 return histoPtr->to_string ();
5666 }
@@ -109,7 +119,7 @@ uint64_t Timings::get_aggregated_mutation_stats() {
109119 for (auto cmd : timings_mutations) {
110120 auto * histoPtr =
111121 timings[std::underlying_type<cb::mcbp::ClientOpcode>::type (cmd)]
112- .get ();
122+ .load ();
113123 if (histoPtr) {
114124 ret += histoPtr->getValueCount ();
115125 }
@@ -123,7 +133,7 @@ uint64_t Timings::get_aggregated_retrival_stats() {
123133 for (auto cmd : timings_retrievals) {
124134 auto * histoPtr =
125135 timings[std::underlying_type<cb::mcbp::ClientOpcode>::type (cmd)]
126- .get ();
136+ .load ();
127137 if (histoPtr) {
128138 ret += histoPtr->getValueCount ();
129139 }
@@ -143,17 +153,17 @@ cb::sampling::Interval Timings::get_interval_lookup_latency() {
143153
144154Hdr1sfMicroSecHistogram& Timings::get_or_create_timing_histogram (
145155 uint8_t opcode) {
146- if (timings[opcode] == nullptr ) {
156+ if (! timings[opcode]) {
147157 std::lock_guard<std::mutex> allocLock (histogram_mutex);
148- if (timings[opcode] == nullptr ) {
149- timings[opcode] = std::make_unique< Hdr1sfMicroSecHistogram> ();
158+ if (! timings[opcode]) {
159+ timings[opcode] = new Hdr1sfMicroSecHistogram ();
150160 }
151161 }
152- return *timings[opcode];
162+ return *( timings[opcode]. load ()) ;
153163}
154164
155165Hdr1sfMicroSecHistogram* Timings::get_timing_histogram (uint8_t opcode) const {
156- return timings[opcode].get ();
166+ return timings[opcode].load ();
157167}
158168
159169void Timings::sample (std::chrono::seconds sample_interval) {
0 commit comments