Skip to contentSkip to conversation

fincore command

PATCH In review Masatake YAMATO 2 participants 12 messages Mar 7, 2017 – Mar 27, 2017 Util-Linux package

lore
Share & tools
lore
#4 lore raw

PATCH 4/4 bash-completion: add a function for fincore command

In reply to Masatake YAMATO
---
 bash-completion/Makemodule.am |  3 +++
 bash-completion/fincore       | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 bash-completion/fincore
bash-completion/Makemodule.am +3 -0
index 3ffd124..ff7b052 100644
@@ -18,6 +18,9 @@ endif
 if BUILD_COLUMN
 dist_bashcompletion_DATA += bash-completion/column
 endif
+if BUILD_FINCORE
+dist_bashcompletion_DATA += bash-completion/fincore
+endif
 if BUILD_FINDMNT
 dist_bashcompletion_DATA += bash-completion/findmnt
 endif
bash-completion/fincore new file +25 -0
new file mode 100644
index 0000000..d213586
@@ -0,0 +1,25 @@
+_fincore_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-h'|'--help'|'-V'|'--version')
+			return 0
+			;;
+	esac
+	case $cur in
+	    -*)
+			OPTS="--help
+				--version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local IFS=$'\n'
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- ${cur:-"/"}) )
+	return 0
+}
+complete -F _fincore_module fincore
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/4 fincore: new command for counting pages of file contents in core

In reply to Masatake YAMATO
---
 configure.ac              |   4 +
 misc-utils/Makemodule.am  |   5 +
 misc-utils/fincore.c      | 209 +++++++++++++++++++++++++++++++++++++++++
 misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 453 insertions(+)
 create mode 100644 misc-utils/fincore.c
 create mode 100644 misc-utils/fincore_orig.c
configure.ac +4 -0
index 8933afa..8ea4f0d 100644
@@ -1589,6 +1589,10 @@ dnl earlier than 2.x.
 UL_REQUIRES_HAVE([ctrlaltdel], [reboot], [reboot function])
 AM_CONDITIONAL([BUILD_CTRLALTDEL], [test "x$build_ctrlaltdel" = xyes])
 
+UL_BUILD_INIT([fincore], [check])
+UL_REQUIRES_LINUX([fincore])
+AM_CONDITIONAL([BUILD_FINCORE], [test "x$build_fincore" = xyes])
+
 UL_BUILD_INIT([fsfreeze], [check])
 UL_REQUIRES_LINUX([fsfreeze])
 AM_CONDITIONAL([BUILD_FSFREEZE], [test "x$build_fsfreeze" = xyes])
misc-utils/Makemodule.am +5 -0
index ce9df2c..6c7fab6 100644
@@ -180,3 +180,8 @@ dist_getoptexample_SCRIPTS = \
 	misc-utils/getopt-parse.bash \
 	misc-utils/getopt-parse.tcsh
 endif
+
+if BUILD_FINCORE
+usrbin_exec_PROGRAMS += fincore
+fincore_SOURCES = misc-utils/fincore.c
+endif
misc-utils/fincore.c new file +209 -0

209 lines not on this page · raw message

misc-utils/fincore_orig.c new file +235 -0

235 lines not on this page · raw message

Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/4 man: add a page for fincore command

In reply to Masatake YAMATO
---
 misc-utils/Makemodule.am |  1 +
 misc-utils/fincore.1     | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 misc-utils/fincore.1
misc-utils/Makemodule.am +1 -0
index 6c7fab6..8cad4d6 100644
@@ -183,5 +183,6 @@ endif
 
 if BUILD_FINCORE
 usrbin_exec_PROGRAMS += fincore
+dist_man_MANS += misc-utils/fincore.1
 fincore_SOURCES = misc-utils/fincore.c
 endif
misc-utils/fincore.1 new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/4 tests: add cases for testing fincore command

In reply to Masatake YAMATO
---
 tests/commands.sh            |   1 +
 tests/expected/fincore/count |  62 ++++++++++++++
 tests/ts/fincore/count       | 194 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 257 insertions(+)
 create mode 100644 tests/expected/fincore/count
 create mode 100755 tests/ts/fincore/count
tests/commands.sh +1 -0
index 2e3a276..2e5c11d 100644
@@ -50,6 +50,7 @@ TS_CMD_FALLOCATE=${TS_CMD_FALLOCATE-"$top_builddir/fallocate"}
 TS_CMD_FDISK=${TS_CMD_FDISK-"$top_builddir/fdisk"}
 TS_CMD_FLOCK=${TS_CMD_FLOCK-"$top_builddir/flock"}
 TS_CMD_SFDISK=${TS_CMD_SFDISK-"$top_builddir/sfdisk"}
+TS_CMD_FINCORE=${TS_CMD_FINCORE-"$top_builddir/fincore"}
 TS_CMD_FINDMNT=${TS_CMD_FINDMNT-"$top_builddir/findmnt"}
 TS_CMD_FSCKCRAMFS=${TS_CMD_FSCKCRAMFS:-"$top_builddir/fsck.cramfs"}
 TS_CMD_FSCKMINIX=${TS_CMD_FSCKMINIX:-"$top_builddir/fsck.minix"}
tests/expected/fincore/count new file +62 -0

62 lines not on this page · raw message

tests/ts/fincore/count new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.9.3
#0 lore raw

cover fincore command

This patch set proposes adding fincore command to util-linux distribution. The command counts pages of file contents being resident in memory(in core), and reports the numbers.

It helps system administrators understand how their systems use physical memory, especially about page caches when they have to do trouble shooting and/or performance tuning.

This is just my case. A person in other role may also get benefits from this command.

Masatake YAMATO (4):
fincore: new command for counting pages of file contents in core
man: add a page for fincore command
tests: add cases for testing fincore command
bash-completion: add a function for fincore command

 bash-completion/Makemodule.am |   3 +
 bash-completion/fincore       |  25 +++++
 configure.ac                  |   4 +
 misc-utils/Makemodule.am      |   6 ++
 misc-utils/fincore.1          |  76 ++++++++++++++
 misc-utils/fincore.c          | 209 +++++++++++++++++++++++++++++++++++++
 misc-utils/fincore_orig.c     | 235 ++++++++++++++++++++++++++++++++++++++++++
 tests/commands.sh             |   1 +
 tests/expected/fincore/count  |  62 +++++++++++
 tests/ts/fincore/count        | 194 ++++++++++++++++++++++++++++++++++
 10 files changed, 815 insertions(+)
 create mode 100644 bash-completion/fincore
 create mode 100644 misc-utils/fincore.1
 create mode 100644 misc-utils/fincore.c
 create mode 100644 misc-utils/fincore_orig.c
 create mode 100644 tests/expected/fincore/count
 create mode 100755 tests/ts/fincore/count
Signature · 1 line
2.9.3
maintainer
#5 lore raw
Quoted 10 lines · Masatake YAMATO

This patch set proposes adding fincore command to util-linux distribution. The command counts pages of file contents being resident in memory(in core), and reports the numbers.

It helps system administrators understand how their systems use physical memory, especially about page caches when they have to do trouble shooting and/or performance tuning.

This is just my case. A person in other role may also get benefits from this command.

Not sure if I like the format ;-)

 $ fincore /etc/fstab /bin/emacs
 1          1544       /etc/fstab
 4156       17163144   /bin/emacs

Why we need file size there? Would be better to use filename as the first column?

 $ fincore /etc/fstab /bin/emacs
 /etc/fstab 1
 /bin/emacs 4156

it would be also nice have a way how to print only the number if only one file specified. Then you can use it in scripts without awk (or so), just:

  FILEPAGES=$(fincore /bin/emacs)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#6 lore raw

Hi, thank you for comments.

Quoted 8 lines · Karel Zak

Not sure if I like the format ;-)

 $ fincore /etc/fstab /bin/emacs
 1          1544       /etc/fstab
 4156       17163144   /bin/emacs

Why we need file size there? Would be better to use filename as the first column?

* Why we need file size there?

I don't insist including the file size column.

The original reason was that I assumed that a user may want to know how much part of the file printed by fincore is in core. The file-size column is for the hint.

How about adding an option to control show the column (--file-size|-s)? Or should I delete the column fron the output completely?

* Would be better to use filename as the first column?

I follow the format that du and ls commands use:

    $ du /etc/passwd
    4	/etc/passwd
    $ ls -i /tmp | head
    67003 emacs1000
    47611 systemd-private-dd34e7d700c6441db79e4caa7b3c3205-colord.service-N7dhub
    24891 systemd-private-dd34e7d700c6441db79e4caa7b3c3205-rtkit-daemon.service-WbOmt1

du and ls are popular enough. So potential users of fincore command may be familiar with the formats.

There are two benefits this(du style) format.

+ awk/read/cut commands friendly

White spaces can be included in a file name.
As the result, a user cannot assume the column
for the page counts easily if filename is at the
first column.

e.g.

    (the format in my patch)
    $ touch 'a b'
    $ ./util-linux/fincore 'a b'
    0          0          a b
    $ ./util-linux/fincore 'a b' | awk '{print $1}'
    0
    $ ./util-linux/fincore 'a b' | { read A REST; echo $A; }
    0
    $ ./util-linux/fincore 'a b' | cut -d ' ' -f1 
    0

+ beauty of output

If filename is at the first column, I wonder
how can I print lines in column aligned way:

0 -1 /foo/bar/baz/very---long---file---name
0 0 shortname

By finding the longest file name from arguments passed to fincore command, the column length can be calumniated, and fincore may be able to print following lines:

    /foo/bar/baz/very---long---file---name	0         -1         
    shortname					0          0

However, I wonder what I should do if multibyte characters are used in the file name.

Of course, the column alignment is less important than providing the way to know much file contents are incore to users.

Quoted 6 lines

it would be also nice have a way how to print only the number if only one file specified. Then you can use it in scripts without awk (or so), just:

  FILEPAGES=$(fincore /bin/emacs)

In the station(interactive use) that a user of fincore knows the number of file names passed to the command, printing only the number is bettern. However, there can be a situation(scripting) that a user cannot know the number of file names.

{
FILES=...
FILES="$FILES $tmp"
...

fincore $FILES
} | do_something

In such case the columns are fixed(the page numbers and file name) will be better for people writing `do_something'. For the such use case, I would like to add an option --print-filename-always. The default behavior (behavior without the option) should be implemented as what you wrote (just printing the number). Is it o.k.?

After getting feedback from you, I will submit v2 patches.

Masatake YAMATO

maintainer
#7 lore raw
Quoted 1 line · Masatake YAMATO

After getting feedback from you, I will submit v2 patches.

That's fine, the current version is good enough. Thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#8 lore raw
In reply to Masatake YAMATO
Quoted 9 lines · Masatake YAMATO
 bash-completion/Makemodule.am |   3 +
 bash-completion/fincore       |  25 +++++
 configure.ac                  |   4 +
 misc-utils/Makemodule.am      |   6 ++
 misc-utils/fincore.1          |  76 ++++++++++++++
 misc-utils/fincore.c          | 209 +++++++++++++++++++++++++++++++++++++
 misc-utils/fincore_orig.c     | 235 ++++++++++++++++++++++++++++++++++++++++++
 tests/commands.sh             |   1 +
 tests/expected/fincore/count  |  62 +++++++++++
Quoted 8 lines
 tests/ts/fincore/count        | 194 ++++++++++++++++++++++++++++++++++
 10 files changed, 815 insertions(+)
 create mode 100644 bash-completion/fincore
 create mode 100644 misc-utils/fincore.1
 create mode 100644 misc-utils/fincore.c
 create mode 100644 misc-utils/fincore_orig.c
 create mode 100644 tests/expected/fincore/count
 create mode 100755 tests/ts/fincore/count

Merged (except fincore_orig.c).

I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#9 lore raw
Quoted 19 lines · Karel Zak
Quoted 9 lines · Masatake YAMATO
 bash-completion/Makemodule.am |   3 +
 bash-completion/fincore       |  25 +++++
 configure.ac                  |   4 +
 misc-utils/Makemodule.am      |   6 ++
 misc-utils/fincore.1          |  76 ++++++++++++++
 misc-utils/fincore.c          | 209 +++++++++++++++++++++++++++++++++++++
 misc-utils/fincore_orig.c     | 235 ++++++++++++++++++++++++++++++++++++++++++
 tests/commands.sh             |   1 +
 tests/expected/fincore/count  |  62 +++++++++++
Quoted 8 lines
 tests/ts/fincore/count        | 194 ++++++++++++++++++++++++++++++++++
 10 files changed, 815 insertions(+)
 create mode 100644 bash-completion/fincore
 create mode 100644 misc-utils/fincore.1
 create mode 100644 misc-utils/fincore.c
 create mode 100644 misc-utils/fincore_orig.c
 create mode 100644 tests/expected/fincore/count
 create mode 100755 tests/ts/fincore/count
Quoted 5 lines

Merged (except fincore_orig.c).

I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).

Implemented, changes:

* errors are printed to stderr only, the output is not affected by errors
* use libsmartcols
* numbers aligned to the right
* add --bytes --raw --noheadings --json and --output <list>
* you can use $(fincore -o PAGES -nr /etc/passwd) to get only the number

The default output is:

$ fincore ~/Mail/Maildir/.notmuch/xapian/*
PAGES  SIZE FILE
    0    0B /home/kzak/Mail/Maildir/.notmuch/xapian/flintlock
    1   28B /home/kzak/Mail/Maildir/.notmuch/xapian/iamchert
   17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseA
   17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseB
 1185  4.2G /home/kzak/Mail/Maildir/.notmuch/xapian/position.DB
    9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseA
    9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseB
87831  2.2G /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.DB
    1  208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseA
    1  208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseB
   66 11.5M /home/kzak/Mail/Maildir/.notmuch/xapian/record.DB
    7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseA
    7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseB
 1941  1.7G /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.DB

I'd like to have also PAGES-IN-BYTES column to make it easy for humans, but not sure how to call the column... "RES" or "RSS"?

For example "343M" rather than "87831" (see above).

Nice util, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#10 lore raw

Thank you for merging.
The output looks sophisticated.

About RES and RSS, I don't know which is better. As you know top command users RES and ps command uses RSS...

Masatake YAMATO

Quoted 66 lines · Karel Zak
Quoted 19 lines · Masatake YAMATO
Quoted 9 lines
 bash-completion/Makemodule.am |   3 +
 bash-completion/fincore       |  25 +++++
 configure.ac                  |   4 +
 misc-utils/Makemodule.am      |   6 ++
 misc-utils/fincore.1          |  76 ++++++++++++++
 misc-utils/fincore.c          | 209 +++++++++++++++++++++++++++++++++++++
 misc-utils/fincore_orig.c     | 235 ++++++++++++++++++++++++++++++++++++++++++
 tests/commands.sh             |   1 +
 tests/expected/fincore/count  |  62 +++++++++++
Quoted 8 lines
 tests/ts/fincore/count        | 194 ++++++++++++++++++++++++++++++++++
 10 files changed, 815 insertions(+)
 create mode 100644 bash-completion/fincore
 create mode 100644 misc-utils/fincore.1
 create mode 100644 misc-utils/fincore.c
 create mode 100644 misc-utils/fincore_orig.c
 create mode 100644 tests/expected/fincore/count
 create mode 100755 tests/ts/fincore/count
Quoted 5 lines

Merged (except fincore_orig.c).

I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).

Implemented, changes:

* errors are printed to stderr only, the output is not affected by errors
* use libsmartcols
* numbers aligned to the right
* add --bytes --raw --noheadings --json and --output <list>
* you can use $(fincore -o PAGES -nr /etc/passwd) to get only the number

The default output is:

$ fincore ~/Mail/Maildir/.notmuch/xapian/*
PAGES  SIZE FILE
    0    0B /home/kzak/Mail/Maildir/.notmuch/xapian/flintlock
    1   28B /home/kzak/Mail/Maildir/.notmuch/xapian/iamchert
   17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseA
   17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseB
 1185  4.2G /home/kzak/Mail/Maildir/.notmuch/xapian/position.DB
    9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseA
    9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseB
87831  2.2G /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.DB
    1  208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseA
    1  208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseB
   66 11.5M /home/kzak/Mail/Maildir/.notmuch/xapian/record.DB
    7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseA
    7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseB
 1941  1.7G /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.DB

I'd like to have also PAGES-IN-BYTES column to make it easy for humans, but not sure how to call the column... "RES" or "RSS"?

For example "343M" rather than "87831" (see above).

Nice util, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#11 lore raw
Quoted 2 lines · Masatake YAMATO

About RES and RSS, I don't know which is better. As you know top command users RES and ps command uses RSS...

Added column RES.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com