1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
Description: avoid not-in-Debian crate profiling
Author: Jonas Smedegaard <dr@jones.dk>
Forwarded: not-needed
Last-Update: 2026-01-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,8 +23,6 @@
iter_fixed = "0.4"
leptess = "0.14"
log = "0.4"
-profiling = "1.0"
-puffin = { version = "0.19", features = ["serialization"], optional = true }
rayon = "1.10"
scoped-tls-hkt = "0.1"
simple_logger = { version = "5.0", features = ["colors"] }
@@ -33,7 +31,6 @@
[features]
default = []
-profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin"]
[lints.rust]
missing_docs = "warn"
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -86,7 +86,6 @@
/// Will return [`Error::NotUtf8Extension`] if the file have an extension which is not utf8.
/// Will return [`Error::WriteSrtFile`] of [`Error::WriteSrtStdout`] if failed to write subtitles as `srt`.
/// Will forward error from `ocr` processing and [`check_subtitles`] if any.
-#[profiling::function]
pub fn run(opt: &Opt) -> Result<(), Error> {
rayon::ThreadPoolBuilder::new()
.thread_name(|idx| format!("Rayon_{idx}"))
@@ -136,16 +135,13 @@
/// Will return [`Error::PgsParserFromFile`] if `SupParser` failed to be init from file.
/// Will return [`Error::PgsParsing`] if the parsing of subtitles failed.
/// Will return [`Error::DumpImage`] if the dump of raw image failed.
-#[profiling::function]
pub fn process_pgs(opt: &Opt) -> Result<(Vec<TimeSpan>, Vec<GrayImage>), Error> {
let parser = {
- profiling::scope!("Create PGS parser");
subtile::pgs::SupParser::<BufReader<File>, DecodeTimeImage>::from_file(&opt.input)
.map_err(Error::PgsParserFromFile)?
};
let (times, rle_images) = {
- profiling::scope!("Parse PGS file");
parser
.collect::<Result<(Vec<_>, Vec<_>), _>>()
.map_err(Error::PgsParsing)?
@@ -161,7 +157,6 @@
let conv_fn = luma_a_to_luma::<_, _, 100, 100>; // Hardcoded value for alpha and luma threshold than work not bad.
let images = {
- profiling::scope!("Convert images for OCR");
let ocr_opt = ocr_opt(opt);
rle_images
.par_iter()
@@ -178,21 +173,17 @@
///
/// Will return [`Error::IndexOpen`] if the subtitle files can't be opened.
/// Will return [`Error::DumpImage`] if the dump of raw image failed.
-#[profiling::function]
pub fn process_vobsub(opt: &Opt) -> Result<(Vec<TimeSpan>, Vec<GrayImage>), Error> {
let mut input_path = opt.input.clone();
let sub = {
- profiling::scope!("Open sub");
input_path.set_extension("sub");
vobsub::Sub::open(&input_path).map_err(Error::SubOpen)?
};
let idx = {
- profiling::scope!("Open idx");
input_path.set_extension("idx");
vobsub::Index::open(&input_path).map_err(Error::IndexOpen)?
};
let (times, images): (Vec<_>, Vec<_>) = {
- profiling::scope!("Parse subtitles");
sub.subtitles::<(TimeSpan, VobSubIndexedImage)>()
.filter_map(|sub| match sub {
Ok(sub) => Some(sub),
@@ -216,8 +207,6 @@
}
let images_for_ocr = {
- profiling::scope!("Convert images for OCR");
-
let ocr_opt = ocr_opt(opt);
let palette = palette_rgb_to_luminance(idx.palette());
images
@@ -244,7 +233,6 @@
///
/// # Errors
/// Will return [`Error::OcrFails`] if the ocr return an error for at least one image.
-#[profiling::function]
pub fn check_subtitles<In>(subtitles: In) -> Result<Vec<(TimeSpan, String)>, Error>
where
In: IntoIterator<Item = (TimeSpan, Result<String, ocr::Error>)>,
@@ -274,7 +262,6 @@
}
}
-#[profiling::function]
fn write_srt(path: Option<&Path>, subtitles: &[(TimeSpan, String)]) -> Result<(), Error> {
if let Some(path) = &path {
write_to_file(path, subtitles).map_err(|source| Error::WriteSrtFile {
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,14 +5,7 @@
use log::LevelFilter;
use subtile_ocr::{run, Opt};
-#[cfg(not(feature = "profile-with-puffin"))]
-use no_profiling as prof;
-#[cfg(feature = "profile-with-puffin")]
-use puffin_profiling as prof;
-
fn main() -> anyhow::Result<()> {
- let profiling_data = prof::init();
-
simple_logger::SimpleLogger::new()
.without_timestamps()
.with_level(LevelFilter::Warn)
@@ -27,47 +20,5 @@
)
});
- profiling::finish_frame!();
- prof::write_perf_file(&profiling_data)?;
-
res
}
-
-#[cfg(not(feature = "profile-with-puffin"))]
-mod no_profiling {
- pub struct Empty;
- pub const fn init() -> Empty {
- Empty {}
- }
-
- #[expect(clippy::unnecessary_wraps)]
- pub const fn write_perf_file(_: &Empty) -> anyhow::Result<()> {
- Ok(())
- }
-}
-
-#[cfg(feature = "profile-with-puffin")]
-mod puffin_profiling {
- use chrono::Local;
- use profiling::puffin::{self, GlobalFrameView};
- use std::{
- fs::{self, File},
- io::BufWriter,
- };
-
- pub fn init() -> GlobalFrameView {
- let global_frame_view = GlobalFrameView::default();
- puffin::set_scopes_on(true);
- global_frame_view
- }
-
- pub fn write_perf_file(global_frame_view: &GlobalFrameView) -> anyhow::Result<()> {
- let now = Local::now().format("%Y-%m-%d-%T").to_string();
- let filename = format!("perf/capture_{now}.puffin");
-
- fs::create_dir_all("perf")?;
- let mut file = BufWriter::new(File::create(filename)?);
- (*global_frame_view.lock()).write(&mut file)?;
- Ok(())
- }
-}
--- a/src/ocr.rs
+++ b/src/ocr.rs
@@ -71,7 +71,6 @@
}
/// Process subtitles images with Tesseract `OCR`.
-#[profiling::function]
pub fn process<Img>(images: Img, opt: &OcrOpt) -> Result<Vec<Result<String>>>
where
Img: IntoParallelIterator<Item = GrayImage>,
@@ -85,7 +84,6 @@
}
// and on threadpool:
broadcast(|ctx| {
- profiling::scope!("Tesseract Init Wrapper");
trace!(
"Init tesseract with lang `{}` on thread {}",
opt.lang,
@@ -105,7 +103,6 @@
.into_par_iter()
.map(|image| {
let text = TESSERACT.with(|tesseract| {
- profiling::scope!("tesseract_ocr");
let mut tesseract = tesseract.borrow_mut();
let tesseract = tesseract.as_mut().unwrap();
tesseract.set_image(image, opt.dpi)?;
@@ -117,7 +114,6 @@
// Clean tesseract from Thread local vars for Threadpool
broadcast(|ctx| {
- profiling::scope!("Tesseract Drop Wrapper");
trace!("Drop TesseractWrapper local var on thread {}", ctx.index());
if let Some(tesseract) = TESSERACT.take() {
drop(tesseract);
@@ -141,8 +137,6 @@
language: impl AsRef<str>,
config: &[(Variable, String)],
) -> Result<Self> {
- profiling::scope!("TesseractWrapper new");
-
let mut leptess = LepTess::new(datapath, language.as_ref())?;
// Disable learning by default, though a user could re-enable this
// option with `-c`. We turn this off since we are are multithreading,
@@ -163,10 +157,8 @@
}
/// Set the tesseract image to the given image's contents.
- #[profiling::function]
fn set_image(&mut self, image: GrayImage, dpi: i32) -> Result<()> {
let bytes = {
- profiling::scope!("TesseractWrapper Pnm create");
let mut bytes: Cursor<Vec<u8>> = Cursor::new(Vec::new());
DynamicImage::ImageLuma8(image).write_to(&mut bytes, image::ImageFormat::Pnm)?;
bytes
@@ -177,7 +169,6 @@
}
/// Get text.
- #[profiling::function]
fn get_text(&mut self) -> Result<String> {
Ok(self.leptess.get_utf8_text()?)
}
|