Skip to content

Improve lsmem#216

Merged
cakebaker merged 26 commits intouutils:mainfrom
Foorack:lsmem
Feb 15, 2025
Merged

Improve lsmem#216
cakebaker merged 26 commits intouutils:mainfrom
Foorack:lsmem

Conversation

@Foorack
Copy link
Copy Markdown
Contributor

@Foorack Foorack commented Feb 9, 2025

Implemented all options from the original lsmem, and added extensive tests to catch most general scenarios. Unexpected edge-cases errupted when combinding certain options, e.g. "size" not being printed as Number when running with -J -b.

Help

cargo run --quiet lsmem -h

List the ranges of available memory with their online status.

Usage: target/debug/util-linux lsmem [OPTION]...

Options:
  -J, --json              use JSON output format
  -P, --pairs             use key="value" output format
  -a, --all               list each individual memory block
  -b, --bytes             print SIZE in bytes rather than in human readable format
  -n, --noheadings        don't print headings
  -o, --output <list>     output columns [possible values: RANGE, SIZE, STATE, REMOVABLE, BLOCK, NODE, ZONES]
      --output-all        output all columns
  -r, --raw               use raw output format
  -S, --split <list>      split ranges by specified columns [possible values: STATE, REMOVABLE, NODE, ZONES]
  -s, --sysroot <dir>     use the specified directory as system root
      --summary [<when>]  print summary information [possible values: never, always, only]
  -h, --help              Print help (see more with '--help')
  -V, --version           Print version

Available output columns:
      RANGE  start and end address of the memory range
       SIZE  size of the memory range
      STATE  online status of the memory range
  REMOVABLE  memory is removable
      BLOCK  memory block number or blocks range
       NODE  numa node of memory
      ZONES  valid zones for the memory range

Usage

cargo run --quiet lsmem

RANGE                                  SIZE  STATE REMOVABLE  BLOCK
0x0000000000000000-0x0000000037ffffff  896M online       yes    0-6
0x0000000100000000-0x00000004afffffff 14.8G online       yes 32-149

Memory block size:       128M
Total online memory:    15.6G
Total offline memory:      0B

cargo run --quiet lsmem -J -b

{
   "memory": [
      {
         "range": "0x0000000000000000-0x0000000037ffffff",
         "size": 939524096,
         "state": "online",
         "removable": true,
         "block": "0-6"
      },{
         "range": "0x0000000100000000-0x00000004afffffff",
         "size": 15837691904,
         "state": "online",
         "removable": true,
         "block": "32-149"
      }
   ]
}

Impact

  • Removed dependency tabled, as it brought more styling headache than value provided. The library is too rigid to conform with the exact output of util-linux's lsmem. It was way easier to use space-padded printf/formatf statements than the library.

  • Added feature preserve_order to serde_json, in order to serialize objects in the same order as they were created.


Fixes #21

@Foorack
Copy link
Copy Markdown
Contributor Author

Foorack commented Feb 9, 2025

Dramatically it says "Files changed 537", but 531 of these are in the tests/fixtures/lsmem folder; as either .expected files or 1-line absolutely tiny txt files used as part of the input data to simulate a fake memory system.

@sylvestre
Copy link
Copy Markdown
Contributor

wahou, impressive :)

Instead of creating files, could you please create temporary files in the tests?
It is easier to read tests and verify them + won't create 500+ files on the disk

@Foorack
Copy link
Copy Markdown
Contributor Author

Foorack commented Feb 10, 2025

The virtual memory system is now not created during test-run, instead of putting 500+ files into source control.

Let me know if you want me to rebase on main and squash, so the files are not in history. Alternatively if you squash when merging.

@Foorack Foorack changed the title Add support for lsmem Improve lsmem Feb 10, 2025
Copy link
Copy Markdown
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive PR, kudos :)

@Foorack
Copy link
Copy Markdown
Contributor Author

Foorack commented Feb 15, 2025

Thank you both @cakebaker and @sylvestre for the reviews.

I've removed the un-necessary allow(dead_code) traits, good catch.

@cakebaker cakebaker merged commit 93de68e into uutils:main Feb 15, 2025
13 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (adaf45f) to head (088c023).
Report is 45 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #216   +/-   ##
===========================
===========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cakebaker
Copy link
Copy Markdown
Contributor

Thanks for your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement program lsmem

3 participants