Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ucm/shared/metrics/cc/api/metrics_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "metrics_api.h"
namespace UC::Metrics {

void SetUp(size_t maxVectorLen) { Metrics::SetUp(maxVectorLen); }
void SetUp(size_t maxVectorLen) { Metrics::GetInstance().SetUp(maxVectorLen); }

void CreateStats(const std::string& name, const std::string& type)
{
Expand Down
8 changes: 4 additions & 4 deletions ucm/shared/metrics/cc/domain/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ thread_local std::shared_ptr<MetricBuffer> Metrics::threadBuffer_ =
std::make_shared<MetricBuffer>();
thread_local bool Metrics::isRegisteredThread_ = false;

std::atomic<bool> Metrics::isInited_{false};
size_t Metrics::maxVectorLen_{10000};

void Metrics::CreateStats(const std::string& name, const std::string& type)
{
std::unique_lock<std::shared_mutex> lock(mutex_);
if (!isInited_.load(std::memory_order_acquire)) {
throw std::runtime_error("Please call SetUp() first!");
}
std::string typeUpper = type;
std::transform(typeUpper.begin(), typeUpper.end(), typeUpper.begin(), ::toupper);
std::unique_lock<std::shared_mutex> lock(mutex_);
if (statsType_.count(name)) {
return;
} else {
Expand Down
9 changes: 4 additions & 5 deletions ucm/shared/metrics/cc/domain/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <tuple>
#include <unordered_map>
#include <vector>

namespace UC::Metrics {
struct MetricBuffer {
struct InnerBuffer {
Expand Down Expand Up @@ -74,13 +73,13 @@ class Metrics {
public:
static Metrics& GetInstance()
{
if (!isInited_) { throw std::runtime_error("Please call SetUp() first!"); }
static Metrics inst;
return inst;
}

static void SetUp(size_t maxVectorLen)
void SetUp(size_t maxVectorLen)
{
std::unique_lock<std::shared_mutex> lock(mutex_);
if (isInited_.load(std::memory_order_acquire)) { return; }
bool expected = false;
if (isInited_.compare_exchange_strong(expected, true, std::memory_order_release,
Expand Down Expand Up @@ -113,8 +112,8 @@ class Metrics {
Metrics() = default;
Metrics(const Metrics&) = delete;
Metrics& operator=(const Metrics&) = delete;
static std::atomic<bool> isInited_;
static size_t maxVectorLen_;
std::atomic<bool> isInited_{false};
size_t maxVectorLen_{10000};
};
} // namespace UC::Metrics

Expand Down
2 changes: 1 addition & 1 deletion ucm/shared/test/case/metrics/metrics_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UCMetricsUT : public testing::Test {
void SetUp() override
{
try {
Metrics::SetUp(1000000);
UC::Metrics::SetUp(1000000);
CreateStats("stats1", "counter");
CreateStats("stats2", "gauge");
CreateStats("stats3", "histogram");
Expand Down