noheadings : 1,
raw : 1,
json : 1,
- recursive : 1;
+ recursive : 1,
+ total : 1;
};
} cstat_fields;
};
+static struct fincore_state total = {
+ .name = "TOTAL",
+};
static int column_name_to_id(const char *name, size_t namesz)
{
{
vec[n] = 0;
st->cstat.nr_cache++;
+ if (ctl->total)
+ total.cstat.nr_cache++;
}
}
st->cstat_fields.writeback = 1;
st->cstat_fields.evicted = 1;
st->cstat_fields.recently_evicted = 1;
+
+ if (ctl->total) {
+ total.cstat.nr_cache += st->cstat.nr_cache;
+ total.cstat.nr_dirty += st->cstat.nr_dirty;
+ total.cstat.nr_writeback += st->cstat.nr_writeback;
+ total.cstat.nr_evicted += st->cstat.nr_evicted;
+ total.cstat.nr_recently_evicted += st->cstat.nr_recently_evicted;
+ }
+
return 0;
}
if (!rc) {
st->name = showname;
+ if (ctl->total)
+ total.file_size += st->file_size;
rc = add_output_data(ctl, st);
}
fputs(USAGE_OPTIONS, out);
fputs(_(" -J, --json use JSON output format\n"), out);
fputs(_(" -b, --bytes print sizes in bytes rather than in human readable format\n"), out);
+ fputs(_(" -c, --total produce a grand total\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
fputs(_(" -o, --output <list> output columns\n"), out);
fputs(_(" --output-all output all columns\n"), out);
};
static const struct option longopts[] = {
{ "bytes", no_argument, NULL, 'b' },
+ { "total", no_argument, NULL, 'c' },
{ "noheadings", no_argument, NULL, 'n' },
{ "output", required_argument, NULL, 'o' },
{ "output-all", no_argument, NULL, OPT_OUTPUT_ALL },
textdomain(PACKAGE);
close_stdout_atexit();
- while ((c = getopt_long (argc, argv, "bno:JrRVh", longopts, NULL)) != -1) {
+ while ((c = getopt_long (argc, argv, "bcno:JrRVh", longopts, NULL)) != -1) {
switch (c) {
case 'b':
ctl.bytes = 1;
break;
+ case 'c':
+ ctl.total = 1;
+ break;
case 'n':
ctl.noheadings = 1;
break;
rc |= fincore_name(&ctl, argv[optind], argv[optind], NULL);
}
+ if (ctl.total)
+ rc |= add_output_data(&ctl, &total);
+
scols_print_table(ctl.tb);
scols_unref_table(ctl.tb);
OUT_COLUMNS="PAGES,FILE"
fi
+cat "$TS_EXPECTED.total" >>"$AGG_OUT"
cat "$TS_EXPECTED_ERR" >"$AGG_ERR"
if ! $TS_CMD_FINCORE --recursive |& grep -q 'recursive option is not supported' ; then
footer "$?"
} >> $TS_OUTPUT 2>> $TS_ERRLOG
+rm -f $INPUT
+INPUT=
+
+OLD_COLUMNS=$OUT_COLUMNS
+OUT_COLUMNS=SIZE,FILE
+
+{
+ run_dd_test "EMPTY" 0
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 1b 1
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 1k 1024
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 10k 10240
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+ts_log_both "[ GRAND TOTAL SIZE ]"
+{
+ $TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings --total $INPUT
+ footer "$?"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $INPUT
+INPUT=
+
+OUT_COLUMNS=PAGES,FILE
+
+{
+ run_dd_test "EMPTY" 0
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 1b 1
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 'ONE PAGE' $PAGE_SIZE
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 'TWO PAGES' $(( 2 * PAGE_SIZE ))
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test 'TEN PAGES' $(( 10 * PAGE_SIZE ))
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+ts_log_both "[ GRAND TOTAL PAGES ]"
+{
+ $TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings --total $INPUT
+ footer "$?"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+OUT_COLUMNS=$OLD_COLUMNS
+
if [ -n "$RECURSIVE" ]; then
dir=$(make_input_name dir)
mkdir -p "$dir"