library: adding IO accounting

This is a modification of MR !122 by @renit1609 to fit the new
library.

Problem statement:
The procps library has no PROC_FILLIO flag to
fetch the proc field "/proc/[pid]/io" data
process-wise.
IO Accounting is not included as part of procps.

Requirement:
We have a requirement to fetch process wise
IO utilization which can be used for monitoring.

When looking through the procps library, I see
that IO Accounting (/proc/[pid]/io) is not being
included as part of procps. There is no such
flag like PROC_FILLIO being included in readproc.h .

Solution:
While looking at the implementation done for
other proc fields, I used the spare bits in app code.
I renamed PROC_SPARE_1 as PROC_FILLIO, the spare bit from
PROC_SPARE_* and used it for fetching /proc/[pid]/io
data as part of the procps library similar to other
fields. I moved the PROC_SPARE_* bits each by 1 bit
to retain the spare bits. Meanwhile added the IO fields
in proc_t structure.

References:
 procps-ng/procps!122
 procps-ng/procps#184
This commit is contained in:
Craig Small
2021-04-24 22:38:48 +10:00
parent fa31656f07
commit a7afe06e6f
4 changed files with 51 additions and 5 deletions

View File

@ -193,6 +193,13 @@ REG_set(ID_SUSER, str, suser)
REG_set(ID_TGID, s_int, tgid)
REG_set(ID_TID, s_int, tid)
REG_set(ID_TPGID, s_int, tpgid)
REG_set(IO_READ_BYTES, ul_int, read_bytes)
REG_set(IO_READ_CHARS, ul_int, rchar)
REG_set(IO_READ_OPS, ul_int, syscr)
REG_set(IO_WRITE_BYTES, ul_int, write_bytes)
REG_set(IO_WRITE_CBYTES, ul_int, cancelled_write_bytes)
REG_set(IO_WRITE_CHARS, ul_int, wchar)
REG_set(IO_WRITE_OPS, ul_int, syscw)
REG_set(LXCNAME, str, lxcname)
CVT_set(MEM_CODE, ul_int, trs)
REG_set(MEM_CODE_PGS, ul_int, trs)
@ -341,6 +348,7 @@ srtDECL(noop) {
#define f_grp PROC_FILLGRP
#define f_login PROC_FILL_LUID
#define f_lxc PROC_FILL_LXC
#define f_io PROC_FILLIO
#define f_ns PROC_FILLNS
#define f_oom PROC_FILLOOM
#define f_stat PROC_FILLSTAT
@ -442,6 +450,13 @@ static struct {
{ RS(ID_TGID), 0, NULL, QS(s_int), 0, TS(s_int) }, // oldflags: free w/ simple_nextpid
{ RS(ID_TID), 0, NULL, QS(s_int), 0, TS(s_int) }, // oldflags: free w/ simple_nexttid
{ RS(ID_TPGID), f_stat, NULL, QS(s_int), 0, TS(s_int) },
{ RS(IO_READ_BYTES), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_READ_CHARS), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_READ_OPS), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_WRITE_BYTES), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_WRITE_CBYTES), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_WRITE_CHARS), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(IO_WRITE_OPS), f_io, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(LXCNAME), f_lxc, NULL, QS(str), 0, TS(str) }, // freefunc NULL w/ cached string
{ RS(MEM_CODE), f_statm, NULL, QS(ul_int), 0, TS(ul_int) },
{ RS(MEM_CODE_PGS), f_statm, NULL, QS(ul_int), 0, TS(ul_int) },