From d08fd701e9272767ce63c71f9e594a26b4b3ea70 Mon Sep 17 00:00:00 2001 From: Harrison Burt <57491488+ChillFish8@users.noreply.github.com> Date: Sun, 4 Jul 2021 19:09:34 +0100 Subject: [PATCH] add timings to debug logs to track format conversion speed. --- src/image.rs | 7 ++++++- tests/unit.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/image.rs b/src/image.rs index cfd9bc2..e9b8e76 100644 --- a/src/image.rs +++ b/src/image.rs @@ -3,11 +3,12 @@ use bytes::{BufMut, BytesMut}; use gotham::state::{FromState, State}; use gotham_derive::{StateData, StaticResponseExtender}; use hashbrown::HashMap; -use log::error; +use log::{error, debug}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use webp::Encoder; use std::sync::Arc; +use std::time::Instant; use image::imageops; use image::{load_from_memory_with_format, DynamicImage}; @@ -62,7 +63,9 @@ macro_rules! convert { || -> anyhow::Result { let buff = BytesMut::new(); let mut writer = buff.writer(); + let start = Instant::now; $e.write_to(&mut writer, $d)?; + debug!("format {:?} conversion took {:?}", $d, start.elapsed()); Ok(writer.into_inner()) }() }}; @@ -147,7 +150,9 @@ async fn convert_image(img: Arc, cfg: StateConfig) -> Result<(Imag if is_enabled!(ImageFormat::WebP, cfg.0.formats) { let cloned = img.clone(); let handle = tokio::task::spawn_blocking(move || -> Result<(ImageFormat, BytesMut)> { + let start = Instant::now(); let raw = Encoder::from_image(cloned.as_ref()).encode(); + debug!("format {:?} conversion took {:?}", image::ImageFormat::WebP, start.elapsed()); let webp = BytesMut::from(raw.as_ref()); Ok((ImageFormat::WebP, webp)) diff --git a/tests/unit.py b/tests/unit.py index 642ff0f..7d9cd41 100644 --- a/tests/unit.py +++ b/tests/unit.py @@ -14,9 +14,9 @@ def get_base_data(file: str) -> str: def test_png_upload1(): global working_ids - data = get_base_data("./samples/news.png") + data = get_base_data("./samples/sunset.jpeg") payload = { - "format": "png", + "format": "jpeg", "data": data, } r = requests.post("http://127.0.0.1:7070/admin/create/image", json=payload)