summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/lsmem.114
-rw-r--r--sys-utils/lsmem.c49
2 files changed, 36 insertions, 27 deletions
diff --git a/sys-utils/lsmem.1 b/sys-utils/lsmem.1
index af65c2abb..8f72bbc1e 100644
--- a/sys-utils/lsmem.1
+++ b/sys-utils/lsmem.1
@@ -16,14 +16,12 @@ Always explicitly define expected columns by using the \fB\-\-output\fR option
together with a columns list in environments where a stable output is required.
The \fBlsmem\fP command lists a new memory range always when the current memory
-block distinguish from the previous block by STATE, REMOVABLE, NODE or ZONES
-attribute. This default behavior is possible to override by the
-\fB\-\-split\fR option (e.g. \fBlsmem \-\-split=STATE,ZONES\fR). The special
-word "none" may be used to ignore all differences between memory blocks and to
-create as large as possible continuous ranges. The opposite semantic is
-\fB\-\-all\fR to list individual memory blocks. The default split policy is
-subject to change. Always explicitly use \fB\-\-split\fR in environments where
-a stable output is required.
+block distinguish from the previous block by some output column. This default
+behavior is possible to override by the \fB\-\-split\fR option (e.g. \fBlsmem
+\-\-split=ZONES\fR). The special word "none" may be used to ignore all
+differences between memory blocks and to create as large as possible continuous
+ranges. The opposite semantic is \fB\-\-all\fR to list individual memory
+blocks.
Note that some output columns may provide inaccurate information if a split policy
forces \fBlsmem\fP to ignore diffrences in some attributes. For example if you
diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c
index 97376de38..19a727465 100644
--- a/sys-utils/lsmem.c
+++ b/sys-utils/lsmem.c
@@ -203,6 +203,32 @@ static inline void reset_split_policy(struct lsmem *l, int enable)
l->split_by_zones = enable;
}
+static void set_split_policy(struct lsmem *l, int cols[], size_t ncols)
+{
+ size_t i;
+
+ reset_split_policy(l, 0);
+
+ for (i = 0; i < ncols; i++) {
+ switch (cols[i]) {
+ case COL_STATE:
+ l->split_by_state = 1;
+ break;
+ case COL_NODE:
+ l->split_by_node = 1;
+ break;
+ case COL_REMOVABLE:
+ l->split_by_removable = 1;
+ break;
+ case COL_ZONES:
+ l->split_by_zones = 1;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
static void add_scols_line(struct lsmem *lsmem, struct memory_block *blk)
{
size_t i;
@@ -649,32 +675,17 @@ int main(int argc, char **argv)
int split[ARRAY_SIZE(coldescs)] = { 0 };
static size_t nsplits = 0;
- reset_split_policy(lsmem, 0); /* disable all */
-
if (strcasecmp(splitarg, "none") == 0)
;
else if (string_add_to_idarray(splitarg, split, ARRAY_SIZE(split),
&nsplits, column_name_to_id) < 0)
return EXIT_FAILURE;
- for (i = 0; i < nsplits; i++) {
- switch (split[i]) {
- case COL_STATE:
- lsmem->split_by_state = 1;
- break;
- case COL_NODE:
- lsmem->split_by_node = 1;
- break;
- case COL_REMOVABLE:
- lsmem->split_by_removable = 1;
- break;
- case COL_ZONES:
- lsmem->split_by_zones = 1;
- break;
- }
- }
+ set_split_policy(lsmem, split, nsplits);
+
} else
- reset_split_policy(lsmem, 1); /* enable all */
+ /* follow output columns */
+ set_split_policy(lsmem, columns, ncolumns);
/*
* Read data and print output