Skip to content

Commit 242191b

Browse files
Provide get_started statistic
1 parent b34c071 commit 242191b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

bb8/src/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub struct State {
101101
#[derive(Debug, Default)]
102102
#[non_exhaustive]
103103
pub struct Statistics {
104+
/// Total gets started.
105+
pub get_started: u64,
104106
/// Total gets performed that did not have to wait for a connection.
105107
pub get_direct: u64,
106108
/// Total gets performed that had to wait for a connection available.

bb8/src/inner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ where
125125
}
126126
};
127127

128+
self.inner.statistics.record_get_started();
129+
128130
let result = match timeout(self.inner.statics.connection_timeout, future).await {
129131
Ok(result) => result,
130132
_ => {

bb8/src/internals.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl<C: Send> From<Conn<C>> for IdleConn<C> {
320320

321321
#[derive(Default)]
322322
pub(crate) struct AtomicStatistics {
323+
pub(crate) get_started: AtomicU64,
323324
pub(crate) get_direct: AtomicU64,
324325
pub(crate) get_waited: AtomicU64,
325326
pub(crate) get_timed_out: AtomicU64,
@@ -332,6 +333,10 @@ pub(crate) struct AtomicStatistics {
332333
}
333334

334335
impl AtomicStatistics {
336+
pub(crate) fn record_get_started(&self) {
337+
self.get_started.fetch_add(1, Ordering::Relaxed);
338+
}
339+
335340
pub(crate) fn record_get(&self, kind: StatsGetKind, wait_time_start: Option<Instant>) {
336341
match kind {
337342
StatsGetKind::Direct => self.get_direct.fetch_add(1, Ordering::Relaxed),
@@ -370,6 +375,7 @@ impl AtomicStatistics {
370375
impl From<&AtomicStatistics> for Statistics {
371376
fn from(item: &AtomicStatistics) -> Self {
372377
Self {
378+
get_started: item.get_started.load(Ordering::Relaxed),
373379
get_direct: item.get_direct.load(Ordering::Relaxed),
374380
get_waited: item.get_waited.load(Ordering::Relaxed),
375381
get_timed_out: item.get_timed_out.load(Ordering::Relaxed),

0 commit comments

Comments
 (0)