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:
@ -641,6 +641,12 @@ static void statm2proc(const char* s, proc_t *restrict P) {
|
||||
&P->trs, &P->lrs, &P->drs, &P->dt);
|
||||
}
|
||||
|
||||
static void io2proc(const char* s, proc_t *restrict P) {
|
||||
int num;
|
||||
num = sscanf(s, "rchar: %lu wchar: %lu syscr: %lu syscw: %lu read_bytes: %lu write_bytes: %lu cancelled_write_bytes: %lu",
|
||||
&P->rchar, &P->wchar, &P->syscr,
|
||||
&P->syscw, &P->read_bytes, &P->write_bytes, &P->cancelled_write_bytes);
|
||||
}
|
||||
|
||||
static int file2str(const char *directory, const char *what, struct utlbuf_s *ub) {
|
||||
#define buffGRW 1024
|
||||
@ -1043,6 +1049,11 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
rc += stat2proc(ub.buf, p);
|
||||
}
|
||||
|
||||
if (flags & PROC_FILLIO) { // read /proc/#/io
|
||||
if (file2str(path, "io", &ub) != -1)
|
||||
io2proc(ub.buf, p);
|
||||
}
|
||||
|
||||
if (flags & PROC_FILLMEM) { // read /proc/#/statm
|
||||
if (file2str(path, "statm", &ub) != -1)
|
||||
statm2proc(ub.buf, p);
|
||||
@ -1153,6 +1164,11 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
rc += stat2proc(ub.buf, t);
|
||||
}
|
||||
|
||||
if (flags & PROC_FILLIO) { // read /proc/#/io
|
||||
if (file2str(path, "io", &ub) != -1)
|
||||
io2proc(ub.buf, t);
|
||||
}
|
||||
|
||||
if (flags & PROC_FILLMEM) { // read /proc/#/task/#statm
|
||||
if (file2str(path, "statm", &ub) != -1)
|
||||
statm2proc(ub.buf, t);
|
||||
|
Reference in New Issue
Block a user