mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-06-18 00:19:11 +00:00
Use u64 for SlowestQuery and TopQuery instead of i64
This commit is contained in:
@ -661,9 +661,9 @@ impl<W: WalHook> Connection<W> {
|
||||
fn update_stats(&self, sql: String, stmt: &rusqlite::Statement, elapsed: Duration) {
|
||||
histogram!("statement_execution_time", elapsed);
|
||||
let elapsed = elapsed.as_millis() as u64;
|
||||
let rows_read = stmt.get_status(StatementStatus::RowsRead);
|
||||
let rows_written = stmt.get_status(StatementStatus::RowsWritten);
|
||||
let mem_used = stmt.get_status(StatementStatus::MemUsed);
|
||||
let rows_read = stmt.get_status(StatementStatus::RowsRead) as u64;
|
||||
let rows_written = stmt.get_status(StatementStatus::RowsWritten) as u64;
|
||||
let mem_used = stmt.get_status(StatementStatus::MemUsed) as u64;
|
||||
histogram!("statement_mem_used_bytes", mem_used as f64);
|
||||
let rows_read = if rows_read == 0 && rows_written == 0 {
|
||||
1
|
||||
@ -672,7 +672,7 @@ impl<W: WalHook> Connection<W> {
|
||||
};
|
||||
self.stats.inc_rows_read(rows_read as u64);
|
||||
self.stats.inc_rows_written(rows_written as u64);
|
||||
let weight = (rows_read + rows_written) as i64;
|
||||
let weight = (rows_read + rows_written) as u64;
|
||||
if self.stats.qualifies_as_top_query(weight) {
|
||||
self.stats.add_top_query(crate::stats::TopQuery::new(
|
||||
sql.clone(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicI64, AtomicU64, Ordering};
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, RwLock, Weak};
|
||||
|
||||
use metrics::{counter, gauge, increment_counter};
|
||||
@ -15,16 +15,16 @@ use crate::replication::FrameNo;
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct TopQuery {
|
||||
#[serde(skip)]
|
||||
pub weight: i64,
|
||||
pub rows_written: i32,
|
||||
pub rows_read: i32,
|
||||
pub weight: u64,
|
||||
pub rows_written: u64,
|
||||
pub rows_read: u64,
|
||||
pub query: String,
|
||||
}
|
||||
|
||||
impl TopQuery {
|
||||
pub fn new(query: String, rows_read: i32, rows_written: i32) -> Self {
|
||||
pub fn new(query: String, rows_read: u64, rows_written: u64) -> Self {
|
||||
Self {
|
||||
weight: rows_read as i64 + rows_written as i64,
|
||||
weight: rows_read + rows_written,
|
||||
rows_read,
|
||||
rows_written,
|
||||
query,
|
||||
@ -36,12 +36,12 @@ impl TopQuery {
|
||||
pub struct SlowestQuery {
|
||||
pub elapsed_ms: u64,
|
||||
pub query: String,
|
||||
pub rows_written: i32,
|
||||
pub rows_read: i32,
|
||||
pub rows_written: u64,
|
||||
pub rows_read: u64,
|
||||
}
|
||||
|
||||
impl SlowestQuery {
|
||||
pub fn new(query: String, elapsed_ms: u64, rows_read: i32, rows_written: i32) -> Self {
|
||||
pub fn new(query: String, elapsed_ms: u64, rows_read: u64, rows_written: u64) -> Self {
|
||||
Self {
|
||||
elapsed_ms,
|
||||
query,
|
||||
@ -69,7 +69,7 @@ pub struct Stats {
|
||||
current_frame_no: AtomicU64,
|
||||
// Lowest value in currently stored top queries
|
||||
#[serde(default)]
|
||||
top_query_threshold: AtomicI64,
|
||||
top_query_threshold: AtomicU64,
|
||||
#[serde(default)]
|
||||
top_queries: Arc<RwLock<BTreeSet<TopQuery>>>,
|
||||
// Lowest value in currently stored slowest queries
|
||||
@ -172,7 +172,7 @@ impl Stats {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn qualifies_as_top_query(&self, weight: i64) -> bool {
|
||||
pub(crate) fn qualifies_as_top_query(&self, weight: u64) -> bool {
|
||||
weight >= self.top_query_threshold.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user