Skip to content

scxtop: add search module with fuzzy matching #1971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 163 additions & 7 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions tools/scxtop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ log-panics = { version = "2", features = ["with-backtrace"]}
hashbrown = "0.15.2"
smartstring = { version = "1.0.1", features = ["serde"] }
nix = { version = "0.29", features = ["time"] }
fuzzy-matcher = "0.3.7"
criterion = "0.6.0"

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

[build-dependencies]
prost-build = "0.13.5"
Expand Down
69 changes: 69 additions & 0 deletions tools/scxtop/benches/my_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use scxtop::available_perf_events;
use scxtop::Search;

fn get_search() -> Search {
let available_perf_events_list: Vec<String> = available_perf_events()
.unwrap()
.iter()
.flat_map(|(subsystem, events)| {
events
.iter()
.map(|event| format!("{}:{}", subsystem.clone(), event.clone()))
})
.collect();
Search::new(available_perf_events_list)
}

fn bench_empty(c: &mut Criterion) {
let search = get_search();
let i = "";

let mut group = c.benchmark_group("Empty String Search");

group.bench_with_input(BenchmarkId::new("Fuzzy Empty", i), i, |b, i| {
b.iter(|| search.fuzzy_search(i))
});
group.bench_with_input(BenchmarkId::new("Substring Empty", i), i, |b, i| {
b.iter(|| search.substring_search(i))
});
group.finish();
}

fn bench_easy_string(c: &mut Criterion) {
let search = get_search();
let i = "alarm";

let mut group = c.benchmark_group("Easy String Search");

group.bench_with_input(BenchmarkId::new("Fuzzy Easy String", i), i, |b, i| {
b.iter(|| search.fuzzy_search(i))
});
group.bench_with_input(BenchmarkId::new("Substring Easy String", i), i, |b, i| {
b.iter(|| search.substring_search(i))
});
group.finish();
}

fn bench_complex_string(c: &mut Criterion) {
let search = get_search();
let i = "alrMcacEL";

let mut group = c.benchmark_group("Complex String Search");

group.bench_with_input(BenchmarkId::new("Fuzzy Complex String", i), i, |b, i| {
b.iter(|| search.fuzzy_search(i))
});
group.bench_with_input(BenchmarkId::new("Substring Complex", i), i, |b, i| {
b.iter(|| search.substring_search(i))
});
group.finish();
}

criterion_group!(
benches,
bench_empty,
bench_easy_string,
bench_complex_string
);
criterion_main!(benches);
Loading
Loading