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
49 changes: 34 additions & 15 deletions src/uu/pmap/src/pmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

// Options independent with field selection:
pmap_config.quiet = matches.get_flag(options::QUIET);
if matches.get_flag(options::SHOW_PATH) {
pmap_config.show_path = true;
}
Expand Down Expand Up @@ -142,15 +143,19 @@ fn output_default_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Erro
total += map_line.size_in_kb;
})?;

println!(" total {total:>16}K");
if !pmap_config.quiet {
println!(" total {total:>16}K");
}

Ok(())
}

fn output_extended_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Error> {
let smap_table = get_smap_table(pid)?;

println!("Address Kbytes RSS Dirty Mode Mapping");
if !pmap_config.quiet {
println!("Address Kbytes RSS Dirty Mode Mapping");
}

for smap_entry in smap_table.entries {
println!(
Expand All @@ -164,13 +169,16 @@ fn output_extended_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Err
);
}

println!("---------------- ------- ------- ------- ");
println!(
"total kB {:>7} {:>7} {:>7}",
smap_table.info.total_size_in_kb,
smap_table.info.total_rss_in_kb,
smap_table.info.total_shared_dirty_in_kb + smap_table.info.total_private_dirty_in_kb,
);
if !pmap_config.quiet {
println!("---------------- ------- ------- ------- ");
println!(
"total kB {:>7} {:>7} {:>7}",
smap_table.info.total_size_in_kb,
smap_table.info.total_rss_in_kb,
smap_table.info.total_shared_dirty_in_kb + smap_table.info.total_private_dirty_in_kb,
);
}

Ok(())
}

Expand All @@ -185,15 +193,20 @@ fn output_custom_format(pid: &str, pmap_config: &mut PmapConfig) -> Result<(), E
}

// Header
{
if !pmap_config.quiet {
let mut line = format!(
"{:>width$} ",
pmap_field_name::ADDRESS,
width = smap_table.info.get_width(pmap_field_name::ADDRESS)
);

pmap_config.quiet = true;
for field_name in pmap_config.get_field_list() {
if pmap_config.is_enabled(field_name) {
// If there is any field that needs footer, we can't suppress the footer
if pmap_config.needs_footer(field_name) {
pmap_config.quiet = false;
}
line += &format!(
"{:>width$} ",
field_name,
Expand Down Expand Up @@ -230,7 +243,7 @@ fn output_custom_format(pid: &str, pmap_config: &mut PmapConfig) -> Result<(), E
}

// Footer
{
if !pmap_config.quiet {
// Separator
let mut line = format!(
"{:>width$} ",
Expand Down Expand Up @@ -292,7 +305,11 @@ fn output_device_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Error

process_maps(
pid,
Some("Address Kbytes Mode Offset Device Mapping"),
if !pmap_config.quiet {
Some("Address Kbytes Mode Offset Device Mapping")
} else {
None
},
|map_line| {
println!(
"{} {:>7} {} {} {} {}",
Expand All @@ -315,9 +332,11 @@ fn output_device_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Error
},
)?;

println!(
"mapped: {total_mapped}K writeable/private: {total_writeable_private}K shared: {total_shared}K"
);
if !pmap_config.quiet {
println!(
"mapped: {total_mapped}K writeable/private: {total_writeable_private}K shared: {total_shared}K"
);
}

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/uu/pmap/src/pmap_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct PmapConfig {
// [Mapping] category
pub show_path: bool,
// Misc
pub quiet: bool,
pub custom_format_enabled: bool,
}

Expand Down
Loading
Loading