Skip to content
Merged
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
105 changes: 11 additions & 94 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ clickhouse-rs = { git = "https://github.com/azat-rust/clickhouse-rs", branch = "
tokio = { version = "*", default-features = false, features = ["macros"] }
console-subscriber = { version = "*", default-features = false, optional = true }
# Flamegraphs
flamelens = { git = "https://github.com/ys-l/flamelens", branch = "main", default-features = false }
flamelens = { git = "https://github.com/azat-rust/flamelens", branch = "diff-mode", default-features = false }
ratatui = { version = "0.29.0", features = ["unstable-rendered-line-info"] }
# Should **only** with the flamelens, since cursive re-export it, while flamelens does not
crossterm = { version = "0.28.1", features = ["use-dev-tty"] }
Expand Down
51 changes: 28 additions & 23 deletions src/interpreter/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use ratatui::Terminal;
use ratatui::backend::CrosstermBackend;
use std::io;

pub fn show(block: Columns) -> AppResult<()> {
let data = block
pub fn block_to_folded(block: &Columns) -> String {
block
.rows()
.map(|x| {
[
Expand All @@ -21,15 +21,10 @@ pub fn show(block: Columns) -> AppResult<()> {
.join(" ")
})
.collect::<Vec<String>>()
.join("\n");

if data.trim().is_empty() {
return Err(Error::msg("Flamegraph is empty").into());
}

let flamegraph = FlameGraph::from_string(data, true);
let mut app = App::with_flamegraph("Query", flamegraph);
.join("\n")
}

fn run_flamelens(mut app: App) -> AppResult<()> {
let backend = CrosstermBackend::new(io::stderr());
let mut terminal = Terminal::new(backend)?;
let timeout = std::time::Duration::from_secs(1);
Expand Down Expand Up @@ -73,23 +68,33 @@ pub fn show(block: Columns) -> AppResult<()> {
Ok(())
}

pub fn show(title: &'static str, data: String) -> AppResult<()> {
if data.trim().is_empty() {
return Err(Error::msg("Flamegraph is empty").into());
}

let flamegraph = FlameGraph::from_string(data, true);
run_flamelens(App::with_flamegraph(title, flamegraph))
}

/// Show a differential flamegraph: `after` rendered with per-frame coloring
/// against the `before` baseline (handled by flamelens's `diff_mode`).
pub fn show_diff(title: &'static str, before: String, after: String) -> AppResult<()> {
if before.trim().is_empty() && after.trim().is_empty() {
return Err(Error::msg("Flamegraph diff is empty (both queries have no samples)").into());
}

let before_fg = FlameGraph::from_string(before, true);
let mut after_fg = FlameGraph::from_string(after, true);
after_fg.set_diff_against(&before_fg);
run_flamelens(App::with_flamegraph(title, after_fg))
}

pub async fn share(
block: Columns,
data: String,
pastila_clickhouse_host: &str,
pastila_url: &str,
) -> Result<String> {
let data = block
.rows()
.map(|x| {
[
x.get::<String, _>(0).unwrap(),
x.get::<u64, _>(1).unwrap().to_string(),
]
.join(" ")
})
.collect::<Vec<String>>()
.join("\n");

if data.trim().is_empty() {
return Err(Error::msg("Flamegraph is empty"));
}
Expand Down
Loading
Loading