Skip to content

Commit

Permalink
ksm view
Browse files Browse the repository at this point in the history
Summary: adds ksm tab to system view

Reviewed By: lnyng

Differential Revision: D56961743

fbshipit-source-id: f4b13ccea93236cf49afced64ab270add2b6642e
  • Loading branch information
inwardvessel authored and facebook-github-bot committed Jun 3, 2024
1 parent 68ecd3e commit 4f8e6a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions below/view/src/default_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ impl HasViewStyle for model::VmModel {}

impl HasViewStyle for model::SingleSlabModel {}

impl HasViewStyle for model::KsmModel {}

impl HasViewStyle for model::SingleDiskModel {}

impl HasViewStyle for model::BtrfsModel {}
32 changes: 32 additions & 0 deletions below/view/src/system_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use base_render::RenderConfigBuilder as Rc;
use common::util::get_prefix;
use cursive::utils::markup::StyledString;
use model::system::BtrfsModelFieldId;
use model::system::KsmModelFieldId;
use model::system::MemoryModelFieldId;
use model::system::SingleCpuModelFieldId;
use model::system::SingleDiskModelFieldId;
Expand Down Expand Up @@ -207,6 +208,37 @@ impl SystemTab for SystemSlab {
}
}

#[derive(Default, Clone)]
pub struct SystemKsm;

impl SystemTab for SystemKsm {
fn get_rows(&self, state: &SystemState, _offset: Option<usize>) -> Vec<(StyledString, String)> {
if let Some(ksm_model) = state.get_model().ksm.as_ref() {
enum_iterator::all::<KsmModelFieldId>()
.map(|field_id| {
let mut line = StyledString::new();
let item =
ViewItem::from_default(field_id).update(Rc::new().width(FIELD_NAME_WIDTH));
line.append_plain(item.config.render_title());
line.append_plain(" ");
line.append(item.update(Rc::new().width(FIELD_WIDTH)).render(ksm_model));
line
})
.filter(|s| {
if let Some((_, filter)) = &state.filter_info {
s.source().contains(filter)
} else {
true
}
})
.map(|s| (s.clone(), "".into()))
.collect()
} else {
Vec::new()
}
}
}

#[derive(Default, Clone)]
pub struct SystemDisk;

Expand Down
8 changes: 8 additions & 0 deletions below/view/src/system_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use cursive::views::ViewRef;
use cursive::Cursive;
use model::system::SystemModel;
use model::BtrfsModelFieldId;
use model::KsmModelFieldId;
use model::MemoryModelFieldId;
use model::SingleCpuModelFieldId;
use model::SingleDiskModelFieldId;
Expand Down Expand Up @@ -64,6 +65,7 @@ pub enum SystemStateFieldId {
Mem(MemoryModelFieldId),
Vm(VmModelFieldId),
Slab(SingleSlabModelFieldId),
Ksm(KsmModelFieldId),
}

impl std::string::ToString for SystemStateFieldId {
Expand All @@ -75,6 +77,7 @@ impl std::string::ToString for SystemStateFieldId {
Self::Mem(field) => field.to_string(),
Self::Vm(field) => field.to_string(),
Self::Slab(field) => field.to_string(),
Self::Ksm(field) => field.to_string(),
}
}
}
Expand Down Expand Up @@ -126,6 +129,7 @@ impl StateCommon for SystemState {
.nth(idx)
.expect("Tag out of range"),
),
"Ksm" => SystemStateFieldId::Ksm(KsmModelFieldId::FullScans),
_ => panic!("bug: got unsupported tab {}", tab),
}
}
Expand Down Expand Up @@ -204,6 +208,7 @@ pub enum SystemView {
Mem(SystemMem),
Vm(SystemVm),
Slab(SystemSlab),
Ksm(SystemKsm),
Disk(SystemDisk),
Btrfs(SystemBtrfs),
}
Expand Down Expand Up @@ -233,6 +238,7 @@ impl SystemView {
"Mem".into(),
"Vm".into(),
"Slab".into(),
"Ksm".into(),
"Disk".into(),
"Btrfs".into(),
];
Expand All @@ -241,6 +247,7 @@ impl SystemView {
tabs_map.insert("Mem".into(), SystemView::Mem(Default::default()));
tabs_map.insert("Vm".into(), SystemView::Vm(Default::default()));
tabs_map.insert("Slab".into(), SystemView::Slab(Default::default()));
tabs_map.insert("Ksm".into(), SystemView::Ksm(Default::default()));
tabs_map.insert("Disk".into(), SystemView::Disk(Default::default()));
tabs_map.insert("Btrfs".into(), SystemView::Btrfs(Default::default()));
let user_data = c
Expand Down Expand Up @@ -273,6 +280,7 @@ impl SystemView {
Self::Mem(inner) => Box::new(inner.clone()),
Self::Vm(inner) => Box::new(inner.clone()),
Self::Slab(inner) => Box::new(inner.clone()),
Self::Ksm(inner) => Box::new(inner.clone()),
Self::Disk(inner) => Box::new(inner.clone()),
Self::Btrfs(inner) => Box::new(inner.clone()),
}
Expand Down

0 comments on commit 4f8e6a3

Please sign in to comment.