Skip to content

Commit

Permalink
Add bufread as an addon
Browse files Browse the repository at this point in the history
  • Loading branch information
kruss committed Jan 27, 2025
1 parent 61adc97 commit 9db429e
Show file tree
Hide file tree
Showing 17 changed files with 902 additions and 16 deletions.
50 changes: 46 additions & 4 deletions application/apps/indexer/Cargo.lock

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

6 changes: 3 additions & 3 deletions application/apps/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"addons/someip-tools",
"addons/file-tools",
"addons/text_grep",
"addons/bufread",
"indexer_base",
"indexer_cli",
"merging",
Expand All @@ -24,12 +25,10 @@ thiserror = "2.0"
lazy_static = "1.5"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
#dlt-core = "0.18.0"
dlt-core = { git = "https://github.com/kruss/dlt-core.git", branch = "remove_buf_redux" }
dlt-core = "0.18.0"
crossbeam-channel = "0.5"
futures = "0.3"
tokio-util = "0.7"
bufread = { git = "https://github.com/kruss/bufread" }
regex = "1"
grep-regex = "0.1"
rand = "0.8"
Expand All @@ -45,6 +44,7 @@ envvars = "0.1"
# Support for `html_reports` needs running the benchmarks via `cargo-criterion` tool.
criterion = { version = "0.5", features = ["html_reports"] }
insta = { version = "1.41", features = ["yaml"] }
proptest = "1.6"

# `insta` crate and its dependency `similar` will be compiled once and run many times,
# therefore it's suggested to compile them with more optimizations for faster runs.
Expand Down
19 changes: 19 additions & 0 deletions application/apps/indexer/addons/bufread/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "bufread"
version = "0.1.1"
edition = "2021"

[dependencies]

[dev-dependencies]
criterion.workspace = true
proptest.workspace = true
rand.workspace = true

[[bench]]
name = "buffer_benches"
harness = false

[[bench]]
name = "reader_benches"
harness = false
2 changes: 2 additions & 0 deletions application/apps/indexer/addons/bufread/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# bufread
A buffered reader implementation in Rust with special behavior.
23 changes: 23 additions & 0 deletions application/apps/indexer/addons/bufread/benches/bench_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2025 ESR Labs GmbH. All rights reserved.
//
// NOTICE: All information contained herein is, and remains
// the property of E.S.R.Labs and its suppliers, if any.
// The intellectual and technical concepts contained herein are
// proprietary to E.S.R.Labs and its suppliers and may be covered
// by German and Foreign Patents, patents in process, and are protected
// by trade secret or copyright law.
// Dissemination of this information or reproduction of this material
// is strictly forbidden unless prior written permission is obtained
// from E.S.R.Labs.

use criterion::Criterion;
use std::time::Duration;

pub fn bench_config(sample_size: usize) -> Criterion {
Criterion::default()
.warm_up_time(Duration::from_secs(5))
.measurement_time(Duration::from_secs(10))
.sample_size(sample_size)
.significance_level(0.01)
.noise_threshold(0.05)
}
62 changes: 62 additions & 0 deletions application/apps/indexer/addons/bufread/benches/buffer_benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2025 ESR Labs GmbH. All rights reserved.
//
// NOTICE: All information contained herein is, and remains
// the property of E.S.R.Labs and its suppliers, if any.
// The intellectual and technical concepts contained herein are
// proprietary to E.S.R.Labs and its suppliers and may be covered
// by German and Foreign Patents, patents in process, and are protected
// by trade secret or copyright law.
// Dissemination of this information or reproduction of this material
// is strictly forbidden unless prior written permission is obtained
// from E.S.R.Labs.

use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

#[path = "./bench_config.rs"]
mod bench_config;
use bench_config::bench_config;

use bufread::DeqBuffer;

fn write_buffer(buffer: &mut DeqBuffer, src: &[u8]) {
while buffer.write_available() >= src.len() {
buffer.write_from(src);
}
}

fn write_buffer_benchmark(c: &mut Criterion) {
let mut buffer = DeqBuffer::new(50 * 1000);
let src: [u8; 100] = [1; 100];

c.bench_function("write_buffer", |b| {
b.iter(|| write_buffer(black_box(&mut buffer), black_box(&src)))
});
}

fn write_read_buffer(buffer: &mut DeqBuffer, src: &[u8], dst: &mut [u8]) {
while buffer.write_available() >= src.len() {
buffer.write_from(src);
}
while buffer.read_available() != 0 {
buffer.read_to(dst);
}
}

fn write_read_buffer_benchmark(c: &mut Criterion) {
let mut buffer = DeqBuffer::new(50 * 1000);
let src: [u8; 100] = [1; 100];
let mut dst: [u8; 100] = [1; 100];

c.bench_function("write_read_buffer", |b| {
b.iter(|| write_read_buffer(black_box(&mut buffer), black_box(&src), black_box(&mut dst)))
});
}

criterion_group! {
name = benches;
config = bench_config(1000);
targets = write_buffer_benchmark, write_read_buffer_benchmark
}

criterion_main!(benches);
46 changes: 46 additions & 0 deletions application/apps/indexer/addons/bufread/benches/reader_benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#![allow(dead_code)]

// Copyright (c) 2025 ESR Labs GmbH. All rights reserved.
//
// NOTICE: All information contained herein is, and remains
// the property of E.S.R.Labs and its suppliers, if any.
// The intellectual and technical concepts contained herein are
// proprietary to E.S.R.Labs and its suppliers and may be covered
// by German and Foreign Patents, patents in process, and are protected
// by trade secret or copyright law.
// Dissemination of this information or reproduction of this material
// is strictly forbidden unless prior written permission is obtained
// from E.S.R.Labs.

use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

#[path = "./bench_config.rs"]
mod bench_config;
use bench_config::bench_config;

#[path = "../tests/proto.rs"]
mod proto;

use bufread::BufReader;
use proto::{Parser, Source, MAX_PACKET_LEN};

fn proto_benchmark(c: &mut Criterion) {
let source_min_size = 100 * MAX_PACKET_LEN;
let buffer_max_size = 3 * MAX_PACKET_LEN;
let buffer_min_size = MAX_PACKET_LEN;

let source = Source::fixed(source_min_size);
let reader = BufReader::new(buffer_max_size, buffer_min_size, source.data());
let mut parser = Parser::new(reader);

c.bench_function("proto", |b| b.iter(|| Parser::run(black_box(&mut parser))));
}

criterion_group! {
name = benches;
config = bench_config(1000);
targets = proto_benchmark
}

criterion_main!(benches);
Loading

0 comments on commit 9db429e

Please sign in to comment.