diff --git a/src/metrics.cpp b/src/metrics.cpp index 9a30874..9ef5511 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -38,11 +38,7 @@ map Metrics::get_data() const { template map Metrics::get_data_and_clear() { - map data; - { - shared_lock lock(mtx); - auto data = get_data(); - } + map data = get_data(); clear(); return data; } @@ -57,9 +53,10 @@ template Metrics& Metrics::operator++(int n) { shared_lock lock(mtx); // Increment all counters by n as an example - for (auto& counter : counters) { - counter.second.fetch_add(n, memory_order_relaxed); - } + // for (auto& counter : counters) { + // counter.second.fetch_add(n, memory_order_relaxed); + // } + n++; return *this; } diff --git a/test/test.cpp b/test/test.cpp index 3af2468..e164d41 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -65,7 +65,11 @@ int main() { // map MyStats = {{"access", 3},{ "error", 0}}; // stats.set(MyStats); // // get and clear all counters - // auto dataWithClear = stats.get_data_and_clear(); + auto dataWithClear = metrika.get_data_and_clear(); + + for (auto& [key, value] : dataWithClear) { + cout << "Log analitic " << key << ", value: " << value << endl; + } return 0; }