mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-16 00:45:48 +08:00
Merge pull request #795 from indiosmo/queue_full_counter
Expose a counter for how many messages were dropped in async mode
This commit is contained in:
commit
c23f36c734
@ -31,6 +31,7 @@ public:
|
||||
if (tail_ == head_) // overrun last item if full
|
||||
{
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
++overrun_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,12 +54,19 @@ public:
|
||||
return ((tail_ + 1) % max_items_) == head_;
|
||||
}
|
||||
|
||||
size_t overrun_counter() const
|
||||
{
|
||||
return overrun_counter_;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t max_items_;
|
||||
typename std::vector<T>::size_type head_ = 0;
|
||||
typename std::vector<T>::size_type tail_ = 0;
|
||||
|
||||
std::vector<T> v_;
|
||||
|
||||
size_t overrun_counter_ = 0;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -30,6 +30,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
size_t overrun_counter() const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
#ifndef __MINGW32__
|
||||
// try to enqueue and block if no room left
|
||||
void enqueue(T &&item)
|
||||
|
@ -157,6 +157,11 @@ public:
|
||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||
}
|
||||
|
||||
size_t overrun_counter() const
|
||||
{
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
private:
|
||||
q_type q_;
|
||||
|
||||
|
@ -7,6 +7,7 @@ TEST_CASE("basic async test ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
size_t overrun_counter = 0;
|
||||
size_t queue_size = 128;
|
||||
size_t messages = 256;
|
||||
{
|
||||
@ -17,9 +18,11 @@ TEST_CASE("basic async test ", "[async]")
|
||||
logger->info("Hello message #{}", i);
|
||||
}
|
||||
logger->flush();
|
||||
overrun_counter = tp->overrun_counter();
|
||||
}
|
||||
REQUIRE(test_sink->msg_counter() == messages);
|
||||
REQUIRE(test_sink->flush_counter() == 1);
|
||||
REQUIRE(overrun_counter == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("discard policy ", "[async]")
|
||||
@ -37,6 +40,7 @@ TEST_CASE("discard policy ", "[async]")
|
||||
logger->info("Hello message");
|
||||
}
|
||||
REQUIRE(test_sink->msg_counter() < messages);
|
||||
REQUIRE(tp->overrun_counter() > 0);
|
||||
}
|
||||
|
||||
TEST_CASE("discard policy using factory ", "[async]")
|
||||
|
Loading…
Reference in New Issue
Block a user