From: Karel Zak Date: Mon, 27 Mar 2017 11:08:40 +0000 (+0200) Subject: fincore: add column RES X-Git-Tag: v2.30-rc1~157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4e8b57be2b63fed82647e4d5efd0e0eaf36b19e;p=thirdparty%2Futil-linux.git fincore: add column RES Signed-off-by: Karel Zak --- diff --git a/misc-utils/fincore.1 b/misc-utils/fincore.1 index 942dd70d15..1625bf68d5 100644 --- a/misc-utils/fincore.1 +++ b/misc-utils/fincore.1 @@ -10,10 +10,9 @@ fincore \- count pages of file contents in core .I file ... .SH DESCRIPTION .B fincore -counts pages of file contents being resident in memory(in core), and -reports the numbers. An output line has 3 columns: the number of -pages in core, a file size, and a file name. If an error -occurs during counting, then an error message is printed to the stderr and +counts pages of file contents being resident in memory(in core), and reports +the numbers. If an error occurs during counting, then an error message is +printed to the stderr and .B fincore continues processing the rest of files listed in a command line. diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c index a2fc1d1113..b867c2d066 100644 --- a/misc-utils/fincore.c +++ b/misc-utils/fincore.c @@ -53,11 +53,13 @@ struct colinfo { enum { COL_PAGES, COL_SIZE, - COL_FILE + COL_FILE, + COL_RES }; static struct colinfo infos[] = { - [COL_PAGES] = { "PAGES", 1, SCOLS_FL_RIGHT, N_("number of memory page")}, + [COL_PAGES] = { "PAGES", 1, SCOLS_FL_RIGHT, N_("file data residend in memory in pages")}, + [COL_RES] = { "RES", 5, SCOLS_FL_RIGHT, N_("file data residend in memory in bytes")}, [COL_SIZE] = { "SIZE", 5, SCOLS_FL_RIGHT, N_("size of the file")}, [COL_FILE] = { "FILE", 4, 0, N_("file name")}, }; @@ -129,6 +131,17 @@ static int add_output_data(struct fincore_control *ctl, xasprintf(&tmp, "%jd", (intmax_t) count_incore); scols_line_refer_data(ln, i, tmp); break; + case COL_RES: + { + uintmax_t res = (uintmax_t) count_incore * ctl->pagesize; + + if (ctl->bytes) + xasprintf(&tmp, "%ju", res); + else + tmp = size_to_human_string(SIZE_SUFFIX_1LETTER, res); + scols_line_refer_data(ln, i, tmp); + break; + } case COL_SIZE: if (ctl->bytes) xasprintf(&tmp, "%jd", (intmax_t) file_size); @@ -327,6 +340,7 @@ int main(int argc, char ** argv) } if (!ncolumns) { + columns[ncolumns++] = COL_RES; columns[ncolumns++] = COL_PAGES; columns[ncolumns++] = COL_SIZE; columns[ncolumns++] = COL_FILE;