See also "FILTER EXAMPLES".
*-C*, *--counter* _label_:_filter_expr_::
-Define a counter used in *--summary* output. *lsfd* makes a
+Define a custom counter used in *--summary* output. *lsfd* makes a
counter named _label_. During collect information, *lsfd* counts files
satisfying _filter_expr_, and stores the counted number to the
counter named _label_. *lsfd* applies filters defined with *--filter*
*--summary*[=_when_]::
This option controls summary lines output. The optional argument _when_
-can be *never*, *always* or *only*. If the _when_ argument is omitted,
+can be *only*, *append* or *never*. If the _when_ argument is omitted,
it defaults to *"only"*.
+
The summary reports counters. A counter comes from a label and an
}
};
-enum {
- SUMMARY_EMIT = 1 << 0,
- SUMMARY_ONLY = 1 << 1,
-};
-
struct lsfd_control {
struct libscols_table *tb; /* output */
struct list_head procs; /* list of all processes */
json : 1,
notrunc : 1,
threads : 1,
- summary: 2;
+ show_main : 1, /* print main table */
+ show_summary : 1; /* print summary/counters */
struct lsfd_filter *filter;
struct lsfd_counter **counters; /* NULL terminated array. */
fputs(_(" -Q, --filter <expr> apply display filter\n"), out);
fputs(_(" --debug-filter dump the innternal data structure of filter and exit\n"), out);
fputs(_(" -C, --counter <name>:<expr>\n"
- " make a counter used in --summary output\n"), out);
+ " define custom counter for --summary output\n"), out);
fputs(_(" --dump-counters dump counter definitions\n"), out);
- fputs(_(" --summary[=when] print summary information (never,always or only)\n"), out);
+ fputs(_(" --summary[=when] print summary information (only, append, or never)\n"), out);
fputs(USAGE_SEPARATOR, out);
printf(USAGE_HELP_OPTIONS(23));
int c;
size_t i;
char *outarg = NULL;
- struct lsfd_control ctl = {};
char *filter_expr = NULL;
bool debug_filter = false;
bool dump_counters = false;
int n_pids = 0;
struct list_head counter_specs;
+ struct lsfd_control ctl = {
+ .show_main = 1
+ };
+
INIT_LIST_HEAD(&counter_specs);
enum {
case OPT_SUMMARY:
if (optarg) {
if (strcmp(optarg, "never") == 0)
- ctl.summary = 0;
+ ctl.show_summary = 0, ctl.show_main = 1;
else if (strcmp(optarg, "only") == 0)
- ctl.summary |= (SUMMARY_ONLY|SUMMARY_EMIT);
- else if (strcmp(optarg, "always") == 0)
- ctl.summary |= SUMMARY_EMIT;
+ ctl.show_summary = 1, ctl.show_main = 0;
+ else if (strcmp(optarg, "append") == 0)
+ ctl.show_summary = 1, ctl.show_main = 1;
else
errx(EXIT_FAILURE, _("unsupported --summary argument"));
} else
- ctl.summary |= SUMMARY_EMIT;
+ ctl.show_summary = 1, ctl.show_main = 0;
break;
case OPT_DUMP_COUNTERS:
dump_counters = true;
}
/* make counters */
- if (ctl.summary & SUMMARY_EMIT) {
+ if (ctl.show_summary) {
if (list_empty(&counter_specs))
ctl.counters = new_default_counters(&ctl);
else {
free(pids);
convert(&ctl.procs, &ctl);
- if (!(ctl.summary & SUMMARY_ONLY))
+
+ /* print */
+ if (ctl.show_main)
emit(&ctl);
- if (ctl.counters && (ctl.summary & SUMMARY_EMIT))
+
+ if (ctl.show_summary && ctl.counters)
emit_summary(&ctl, ctl.counters);
/* cleanup */