use std::fmt;
use crate::ctx::CompressorContext;
use crate::scheme::SchemeId;
pub(super) const TARGET_TRACE: &str = "vortex_compressor::encode";
#[inline]
pub(super) fn compress_span(
len: usize,
dtype: &impl fmt::Display,
before_nbytes: u64,
) -> tracing::Span {
tracing::debug_span!(
target: TARGET_TRACE,
"compress",
array_len = len,
dtype = %dtype,
input_nbytes = before_nbytes,
compressed_nbytes = tracing::field::Empty,
compression_ratio = tracing::field::Empty,
)
}
#[inline]
pub(super) fn generate_stats_span(kind: &'static str) -> tracing::Span {
tracing::debug_span!(
target: TARGET_TRACE,
"generate_stats",
stats_kind = kind,
)
}
#[inline]
pub(super) fn verdict_pass_span() -> tracing::Span {
tracing::debug_span!(
target: TARGET_TRACE,
"verdict_pass",
)
}
#[inline]
pub(super) fn scheme_eval_span(scheme: SchemeId) -> tracing::Span {
tracing::debug_span!(
target: TARGET_TRACE,
"scheme_eval",
scheme_candidate = %scheme,
)
}
#[inline]
pub(super) fn zero_byte_sample_result(scheme: SchemeId, sampled_before: u64) {
tracing::debug!(
target: TARGET_TRACE,
scheme = %scheme,
sampled_before,
sampled_after = 0_u64,
"sample.result",
);
}
#[inline]
pub(super) fn winner_compress_span(scheme: SchemeId, before_nbytes: u64) -> tracing::Span {
tracing::debug_span!(
target: TARGET_TRACE,
"winner_compress",
scheme_chosen = %scheme,
input_nbytes = before_nbytes,
compressed_nbytes = tracing::field::Empty,
estimated_ratio = tracing::field::Empty,
achieved_ratio = tracing::field::Empty,
accepted = tracing::field::Empty,
)
}
#[inline]
pub(super) fn record_winner_compress_result(
compressed_nbytes: u64,
estimated_ratio: Option<f64>,
achieved_ratio: Option<f64>,
accepted: bool,
) {
let span = tracing::Span::current();
span.record("compressed_nbytes", compressed_nbytes);
if let Some(r) = estimated_ratio {
span.record("estimated_ratio", r);
}
if let Some(r) = achieved_ratio {
span.record("achieved_ratio", r);
}
span.record("accepted", accepted);
}
#[inline]
pub(super) fn record_compress_outcome(
span: &tracing::Span,
input_nbytes: u64,
compressed_nbytes: u64,
) {
span.record("compressed_nbytes", compressed_nbytes);
if compressed_nbytes != 0 {
span.record(
"compression_ratio",
input_nbytes as f64 / compressed_nbytes as f64,
);
}
}
#[inline]
pub(super) fn cascade_exhausted(parent: SchemeId, child_index: usize) {
tracing::debug!(
target: TARGET_TRACE,
parent = %parent,
child_index,
"cascade_exhausted",
);
}
#[inline]
pub(super) fn enabled_error_context(ctx: &CompressorContext) -> Option<CompressorContext> {
tracing::enabled!(target: TARGET_TRACE, tracing::Level::ERROR).then(|| ctx.clone())
}
#[inline]
pub(super) fn scheme_compress_failed(
scheme: SchemeId,
before_nbytes: u64,
ctx: Option<&CompressorContext>,
err: &impl fmt::Display,
) {
if let Some(ctx) = ctx {
tracing::error!(
target: TARGET_TRACE,
scheme = %scheme,
before_nbytes,
cascade_path = %ctx.cascade_path(),
cascade_depth = ctx.cascade_depth(),
error = %err,
"scheme.compress_failed",
);
}
}
#[inline]
pub(super) fn sample_compress_failed(
scheme: SchemeId,
ctx: Option<&CompressorContext>,
err: &impl fmt::Display,
) {
if let Some(ctx) = ctx {
tracing::error!(
target: TARGET_TRACE,
scheme = %scheme,
cascade_path = %ctx.cascade_path(),
cascade_depth = ctx.cascade_depth(),
error = %err,
"sample.compress_failed",
);
}
}