Skip to content

Commit

Permalink
progress: send IPC notifications from Sapling
Browse files Browse the repository at this point in the history
Summary:
After this diff, all commands should send progress bars to ISL (or whichever other process is communicating through NodeIPC). This feature will be gated through the `progress.ipc-report` config.

Sending progress bars is done under the same loop that renders progress bars and updates the runlog. Sending messages through NodeIPC shouldn't slow down anything else, as there is little information to be updated. Because nothing is slowed down, we don't need another thread to independently send messages through NodeIPC.

Notice that we don't put the logic for sending progress bars under the `progress::render` crate. That crate is very tightly couple with `wezterm` features, so it wouldn't make much sense to put it there.

Reviewed By: muirdm

Differential Revision: D65769370

fbshipit-source-id: d547a6a546d18713737983d40ee53129665ae018
  • Loading branch information
sggutier authored and facebook-github-bot committed Nov 15, 2024
1 parent 7acf5d5 commit e4c193f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
11 changes: 6 additions & 5 deletions eden/scm/lib/commands/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,6 @@ fn spawn_progress_thread(
disable_rendering = true;
}

let assume_tty = config.get_or("progress", "assume-tty", || false)?;
if !assume_tty && !io.error().is_tty() {
disable_rendering = true;
}

if global_opts.quiet || hgplain::is_plain(Some("progress")) {
disable_rendering = true;
}
Expand All @@ -515,8 +510,14 @@ fn spawn_progress_thread(
disable_rendering = true;
}

let assume_tty = config.get_or("progress", "assume-tty", || false)?;
if !assume_tty && !io.error().is_tty() && renderer_name != "nodeipc" {
disable_rendering = true;
}

let render_function = match renderer_name.as_str() {
"structured" => progress_render::structured::render,
"nodeipc" => progress_render::nodeipc::render,
_ => progress_render::simple::render,
};

Expand Down
3 changes: 3 additions & 0 deletions eden/scm/lib/progress/render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ license = "MIT"
name = "progress_render"

[dependencies]
sapling-nodeipc = { version = "0.1.0", path = "../../util/nodeipc" }
sapling-progress-model = { version = "0.1.0", path = "../model" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
termwiz = { version = "0.22", features = ["widgets"] }
tracing = { version = "0.1.40", features = ["attributes", "valuable"] }
unicode-segmentation = "1.6.0"
unicode-width = "=0.1.12"
3 changes: 3 additions & 0 deletions eden/scm/lib/progress/render/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ rust_library(
test_deps = [
],
deps = [
"fbsource//third-party/rust:serde",
"fbsource//third-party/rust:termwiz",
"fbsource//third-party/rust:tracing",
"fbsource//third-party/rust:unicode-segmentation",
"fbsource//third-party/rust:unicode-width",
"//eden/scm/lib/progress/model:progress-model",
"//eden/scm/lib/util/nodeipc:nodeipc",
],
)
1 change: 1 addition & 0 deletions eden/scm/lib/progress/render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Progress rendering.

mod config;
pub mod nodeipc;
pub mod simple;
pub mod structured;
mod unit;
Expand Down
60 changes: 60 additions & 0 deletions eden/scm/lib/progress/render/src/nodeipc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

use std::collections::HashMap;

use progress_model::Registry;
use serde::Deserialize;
use serde::Serialize;
use termwiz::surface::Change;

use crate::RenderingConfig;

#[derive(Serialize, Deserialize)]
struct IpcProgressBar {
pub id: u64,
pub topic: String,
pub unit: String,
pub total: u64,
pub position: u64,
pub parent_id: Option<u64>,
}

pub fn render(registry: &Registry, config: &RenderingConfig) -> Vec<Change> {
let ipc = if let Some(ipc) = nodeipc::get_singleton() {
ipc
} else {
tracing::trace!("nodeipc channel not available when rendering nodeipc progress bar");
return Vec::new();
};

let progress_bars: Vec<_> = registry
.list_progress_bar()
.into_iter()
.filter(|pb| config.delay.as_millis() == 0 || pb.since_creation() >= config.delay)
.map(|pb| {
let (position, total) = pb.position_total();
IpcProgressBar {
id: pb.id(),
topic: pb.topic().to_owned(),
unit: pb.unit().to_owned(),
total,
position,
parent_id: pb.parent().map(|p| p.id()),
}
})
.collect();

if let Err(err) = ipc.send(HashMap::from([(
"progress_bar_update".to_owned(),
progress_bars,
)])) {
tracing::trace!("nodeipc send error on progress: {:?}", err);
}

Vec::new()
}

0 comments on commit e4c193f

Please sign in to comment.