Skip to content

Commit

Permalink
for apple clang
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed May 20, 2024
1 parent 60002df commit 1a6f523
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions include/cinatra/ylt/metric/summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class summary_t : public metric_t {

void observe(double value) {
count_ += 1;
sum_.fetch_add(value);
std::lock_guard<std::mutex> lock(mutex_);
sum_ += value;
quantile_values_.insert(value);
}

Expand All @@ -27,6 +27,11 @@ class summary_t : public metric_t {
return quantile_values_;
}

auto get_sum() {
std::lock_guard<std::mutex> lock(mutex_);
return sum_;
}

void serialize(std::string& str) override {
if (quantiles_.empty()) {
return;
Expand All @@ -49,7 +54,10 @@ class summary_t : public metric_t {
.append("\n");
}

str.append(name_).append("_sum ").append(std::to_string(sum_)).append("\n");
str.append(name_)
.append("_sum ")
.append(std::to_string(get_sum()))
.append("\n");
str.append(name_)
.append("_count ")
.append(std::to_string(count_))
Expand All @@ -60,7 +68,7 @@ class summary_t : public metric_t {
Quantiles quantiles_;
mutable std::mutex mutex_;
std::atomic<std::uint64_t> count_{};
std::atomic<double> sum_{};
double sum_{};
TimeWindowQuantiles quantile_values_;
};
} // namespace cinatra

0 comments on commit 1a6f523

Please sign in to comment.