Skip to content

Commit

Permalink
Log debug tile specs and cache hits
Browse files Browse the repository at this point in the history
Related to #44.
  • Loading branch information
aschampion committed Jun 13, 2022
1 parent 662aaeb commit 470bb9e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ actix-cors = "0.6"
anymap = "0.12"
env_logger = "0.9"
lazy_static = "1"
log = "0"
lru-cache = "0.1.2"
n5 = "0.7"
ndarray = "0.13"
Expand Down
2 changes: 2 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anymap::{
any::Any,
Map,
};
use log::debug;
use lru_cache::LruCache;
use n5::prelude::*;
use n5::{
Expand Down Expand Up @@ -134,6 +135,7 @@ impl<N: N5Reader> N5Reader for N5CacheReader<N> {
let mut ds_block_cache = ds_cache.write().unwrap();

if let Some(block) = ds_block_cache.get_mut(&grid_position[..]) {
debug!("Block cache hit: {path_name} {grid_position:?}");
return Ok(block.clone());
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use actix_web::web::Bytes;
use actix_web::web::Data;
use actix_web::web::Query;
use actix_web::*;
use log::debug;
use lru_cache::LruCache;
use n5::filesystem::N5Filesystem;
use n5::smallvec::SmallVec;
Expand Down Expand Up @@ -81,7 +82,7 @@ impl ResponseError for TileImageSpecError {
}

/// Specifies a tile to slice from a dataset and an image format to encode it.
#[derive(PartialEq, Eq, Hash)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct TileImageSpec {
tile: TileSpec,
format: EncodingFormat,
Expand Down Expand Up @@ -155,6 +156,8 @@ async fn tile<N: N5Reader>(
spec
};

debug!("{spec:?}");

if spec.tile.tile_size.w > state.max_tile_size.w
|| spec.tile.tile_size.h > state.max_tile_size.h
{
Expand All @@ -166,6 +169,7 @@ async fn tile<N: N5Reader>(
if let Some(cache) = &state.tile_cache {
let mut cache_lock = cache.write().unwrap();
if let Some(tile) = cache_lock.get_mut(&spec) {
debug!("Tile cache hit");
return Ok(HttpResponse::Ok()
.content_type(spec.format.content_type())
.body(tile.clone()));
Expand Down

0 comments on commit 470bb9e

Please sign in to comment.