progress: render non-bars for structured renderer

Summary: Minimal effort rendering of io time series (and cache stats) for the "structured" renderer. In the future we can improve the styling to match that of the progress bars, but for now it is important to show the data.

Reviewed By: quark-zju

Differential Revision: D52305090

fbshipit-source-id: bc8c8fd7e99afe4d147c2b79ccd1cdb6e17d1567
This commit is contained in:
Muir Manders 2023-12-19 16:10:15 -08:00 committed by Facebook GitHub Bot
parent c029937afd
commit e3b941c99e
3 changed files with 31 additions and 5 deletions

View File

@ -15,6 +15,7 @@ use anyhow::bail;
use anyhow::Result;
use clidispatch::ReqCtx;
use cliparser::define_flags;
use progress_model::IoTimeSeries;
use progress_model::ProgressBar;
use progress_model::Registry;
@ -41,6 +42,11 @@ struct Bar {
pub fn run(ctx: ReqCtx<StructuredProgressOpts>, _config: &mut ConfigSet) -> Result<u8> {
let bars = Bar::from_spec_list(&ctx.opts.layout)?.1;
// Add a test io time series so we can see how things look.
let time_series = IoTimeSeries::new("HTTP", "requests");
time_series.populate_test_samples(1000, 1000, 1);
Registry::main().register_io_time_series(&time_series);
run_bars(bars).join().unwrap();
Ok(0)

View File

@ -38,7 +38,7 @@ pub fn render_string(registry: &Registry, config: &RenderingConfig) -> String {
let bar_list = registry.list_progress_bar();
render_cache_stats(&mut lines, &cache_list, config);
render_time_series(&mut lines, &series_list, config);
render_time_series(&mut lines, &series_list, config.max_topic_len());
render_progress_bars(&mut lines, &bar_list, config);
for line in lines.iter_mut() {
@ -48,10 +48,10 @@ pub fn render_string(registry: &Registry, config: &RenderingConfig) -> String {
lines.join("\r\n")
}
fn render_time_series(
pub(crate) fn render_time_series(
lines: &mut Vec<String>,
series_list: &[Arc<IoTimeSeries>],
config: &RenderingConfig,
topic_pad: usize,
) {
for model in series_list {
let mut phrases = Vec::with_capacity(4);
@ -60,7 +60,7 @@ fn render_time_series(
}
// Net [▁▂▄█▇▅▃▆] 3 MB/s
phrases.push(format!("{:>1$}", model.topic(), config.max_topic_len()));
phrases.push(format!("{:>1$}", model.topic(), topic_pad));
let ascii = ascii_time_series(model);
phrases.push(format!("[{}]", ascii));
@ -183,7 +183,11 @@ fn render_progress_bars(
}
}
fn render_cache_stats(lines: &mut Vec<String>, list: &[Arc<CacheStats>], config: &RenderingConfig) {
pub(crate) fn render_cache_stats(
lines: &mut Vec<String>,
list: &[Arc<CacheStats>],
config: &RenderingConfig,
) {
for model in list {
// topic [====> ] 12 / 56 files message
let topic = model.topic();

View File

@ -31,7 +31,23 @@ const MIN_TOPIC_LENGTH: usize = 30;
pub fn render(registry: &Registry, config: &RenderingConfig) -> Vec<Change> {
let mut changes = ChangeSequence::new(config.term_width, config.term_height);
// Defer to simple rendering for non-progress bars for now.
// TODO: make rendering style match that of structured bars.
let mut non_progress = Vec::new();
crate::simple::render_cache_stats(&mut non_progress, &registry.list_cache_stats(), config);
crate::simple::render_time_series(&mut non_progress, &registry.list_io_time_series(), 0);
if !non_progress.is_empty() {
// Add empty line separating non-progress bars from progress bars.
// Maybe get rid of this when we unify styling.
non_progress.push(String::new());
}
for line in non_progress {
changes.add(format!("{line}\r\n"));
}
render_progress_bars(&mut changes, &registry.list_progress_bar(), config);
changes.consume()
}