Skip to content

Commit 54b0bef

Browse files
committed
Add dialog window for sharing flamegraph (same as for logs)
1 parent 7bae453 commit 54b0bef

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/interpreter/flamegraph.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::interpreter::clickhouse::Columns;
22
use crate::pastila;
3-
use crate::utils::open_url_command;
43
use anyhow::{Error, Result};
54
use crossterm::event::{self, Event as CrosstermEvent, KeyEventKind};
65
use flamelens::app::{App, AppResult};
@@ -71,7 +70,11 @@ pub fn show(block: Columns) -> AppResult<()> {
7170
Ok(())
7271
}
7372

74-
pub async fn share(block: Columns, pastila_clickhouse_host: &str, pastila_url: &str) -> Result<()> {
73+
pub async fn share(
74+
block: Columns,
75+
pastila_clickhouse_host: &str,
76+
pastila_url: &str,
77+
) -> Result<String> {
7578
let data = block
7679
.rows()
7780
.map(|x| {
@@ -90,19 +93,5 @@ pub async fn share(block: Columns, pastila_clickhouse_host: &str, pastila_url: &
9093

9194
let pastila_url =
9295
pastila::upload_encrypted(&data, pastila_clickhouse_host, pastila_url).await?;
93-
let url = format!("https://whodidit.you/#profileURL={}", pastila_url);
94-
95-
let mut child = open_url_command(&url)
96-
.spawn()
97-
.map_err(|e| Error::msg(format!("Cannot open URL: {}", e)))?;
98-
99-
let result = child.wait()?;
100-
if !result.success() {
101-
return Err(Error::msg(format!(
102-
"Error while opening flamegraph in browser: {:?} (Do you have some browser installed?)",
103-
result
104-
)));
105-
}
106-
107-
return Ok(());
96+
return Ok(format!("https://whodidit.you/#profileURL={}", pastila_url));
10897
}

src/interpreter/worker.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async fn start_tokio(context: ContextArc, receiver: ReceiverArc) {
297297
log::info!("Event worker finished");
298298
}
299299

300-
async fn render_flamegraph(
300+
async fn render_or_share_flamegraph(
301301
tui: bool,
302302
cb_sink: cursive::CbSink,
303303
block: Columns,
@@ -316,7 +316,22 @@ async fn render_flamegraph(
316316
}))
317317
.map_err(|_| anyhow!("Cannot send message to UI"))?;
318318
} else {
319-
flamegraph::share(block, &pastila_clickhouse_host, &pastila_url).await?;
319+
let url = flamegraph::share(block, &pastila_clickhouse_host, &pastila_url).await?;
320+
321+
let url_clone = url.clone();
322+
cb_sink
323+
.send(Box::new(move |siv: &mut cursive::Cursive| {
324+
siv.add_layer(
325+
views::Dialog::text(format!("Flamegraph shared (encrypted):\n\n{}", url))
326+
.title("Share Complete")
327+
.button("Close", |siv| {
328+
siv.pop_layer();
329+
}),
330+
);
331+
}))
332+
.map_err(|_| anyhow!("Cannot send message to UI"))?;
333+
334+
crate::utils::open_url_command(&url_clone).status()?;
320335
}
321336
return Ok(());
322337
}
@@ -403,7 +418,7 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
403418
selected_host.as_ref(),
404419
)
405420
.await?;
406-
render_flamegraph(
421+
render_or_share_flamegraph(
407422
tui,
408423
cb_sink,
409424
flamegraph_block,
@@ -423,7 +438,7 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
423438
selected_host.as_ref(),
424439
)
425440
.await?;
426-
render_flamegraph(
441+
render_or_share_flamegraph(
427442
tui,
428443
cb_sink,
429444
flamegraph_block,
@@ -437,7 +452,7 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
437452
let flamegraph_block = clickhouse
438453
.get_live_query_flamegraph(&query_ids, selected_host.as_ref())
439454
.await?;
440-
render_flamegraph(
455+
render_or_share_flamegraph(
441456
tui,
442457
cb_sink,
443458
flamegraph_block,

0 commit comments

Comments
 (0)