From dff7c5588e9761224f2811f0ce5792ff93d95e29 Mon Sep 17 00:00:00 2001 From: Robert Roth Date: Sun, 12 Feb 2017 17:59:08 +0200 Subject: [PATCH 01/11] New API to retrieve process io stats, with Linux implementation --- .gitignore | 1 + examples/Makefile.am | 6 +- examples/diskio.c | 39 +++++++++++++ features.def | 1 + include/glibtop/Makefile.am | 1 + include/glibtop/command.h | 3 +- include/glibtop/procdiskio.h | 90 ++++++++++++++++++++++++++++++ include/glibtop/sysdeps.h | 4 +- include/glibtop/union.h | 2 + lib/Makefile.am | 2 +- lib/command.c | 1 + lib/libgtop.sym | 2 + lib/sysdeps.c | 9 ++- src/daemon/main.c | 6 ++ sysdeps/common/default.c | 15 +++++ sysdeps/common/sysdeps_suid.c | 3 + sysdeps/linux/Makefile.am | 2 +- sysdeps/linux/glibtop_server.h | 1 + sysdeps/linux/procdiskio.c | 66 ++++++++++++++++++++++ sysdeps/stub/procdiskio.c | 43 ++++++++++++++ sysdeps/stub_suid/glibtop_server.h | 1 + 21 files changed, 292 insertions(+), 6 deletions(-) create mode 100644 examples/diskio.c create mode 100644 include/glibtop/procdiskio.h create mode 100644 sysdeps/linux/procdiskio.c create mode 100644 sysdeps/stub/procdiskio.c diff --git a/.gitignore b/.gitignore index b4738458..5446f725 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ examples/smp examples/sysdeps examples/timings examples/wd +examples/diskio gtk-doc.make install-sh lib/GTop-2.0.gir diff --git a/examples/Makefile.am b/examples/Makefile.am index 48ac4849..25585e04 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -11,7 +11,7 @@ AM_LDFLAGS = $(LIBGTOP_EXTRA_LIBS) noinst_PROGRAMS = first second pprint procargs df netlist \ mountlist procmap netload sysdeps timings \ - openfiles smp proclist free wd affinity + openfiles smp proclist free wd affinity diskio first_SOURCES = first.c first_LDADD = $(top_builddir)/lib/libgtop-2.0.la @@ -43,6 +43,7 @@ pprint_LDADD = $(top_builddir)/lib/libgtop-2.0.la procargs_SOURCES = procargs.c procargs_LDADD = $(top_builddir)/lib/libgtop-2.0.la + df_SOURCES = df.c df_LDADD = $(top_builddir)/lib/libgtop-2.0.la @@ -63,3 +64,6 @@ free_LDADD = $(top_builddir)/lib/libgtop-2.0.la affinity_SOURCES = affinity.c affinity_LDADD = $(top_builddir)/lib/libgtop-2.0.la + +diskio_SOURCES = diskio.c +diskio_LDADD = $(top_builddir)/lib/libgtop-2.0.la diff --git a/examples/diskio.c b/examples/diskio.c new file mode 100644 index 00000000..e52844aa --- /dev/null +++ b/examples/diskio.c @@ -0,0 +1,39 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include + +#include + +static void show_diskio(pid_t pid) +{ + glibtop_proc_diskio diskio; + + glibtop_get_proc_diskio (&diskio, pid); + + printf("<%ld>\t", (long)pid); + + printf("rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", diskio.rchar, diskio.wchar, diskio.rbytes, diskio.wbytes); + +} + + +int main(int argc, char **argv) +{ + glibtop_init(); + + while(*++argv) + { + pid_t pid = strtol(*argv, NULL, 10); + show_diskio(pid); + } + + glibtop_close(); + + return 0; +} + diff --git a/features.def b/features.def index 1025313e..065d8fa1 100644 --- a/features.def +++ b/features.def @@ -24,4 +24,5 @@ void|ppp|ushort(device) char **|netlist char **|proc_wd|pid_t(pid) guint16*|proc_affinity|pid_t(pid) +void|proc_diskio|pid_t(pid) diff --git a/include/glibtop/Makefile.am b/include/glibtop/Makefile.am index 66bdd344..b797385e 100644 --- a/include/glibtop/Makefile.am +++ b/include/glibtop/Makefile.am @@ -9,6 +9,7 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \ parameter.h mountlist.h fsusage.h procmap.h signal.h \ sysinfo.h ppp.h procargs.h netload.h \ procwd.h procaffinity.h \ + procdiskio.h \ netlist.h procopenfiles.h open.h noinst_HEADERS = error.h write.h read_data.h read.h init_hooks.h machine.h \ diff --git a/include/glibtop/command.h b/include/glibtop/command.h index 1d4d630c..6e9dc079 100644 --- a/include/glibtop/command.h +++ b/include/glibtop/command.h @@ -59,8 +59,9 @@ G_BEGIN_DECLS #define GLIBTOP_CMND_PROC_OPEN_FILES 25 #define GLIBTOP_CMND_PROC_WD 26 #define GLIBTOP_CMND_PROC_AFFINITY 27 +#define GLIBTOP_CMND_PROC_DISKIO 28 -#define GLIBTOP_MAX_CMND 28 +#define GLIBTOP_MAX_CMND 29 #define _GLIBTOP_PARAM_SIZE 16 diff --git a/include/glibtop/procdiskio.h b/include/glibtop/procdiskio.h new file mode 100644 index 00000000..5d7b18e3 --- /dev/null +++ b/include/glibtop/procdiskio.h @@ -0,0 +1,90 @@ +/* Copyright (C) 2017 Robert Roth + This file is part of LibGTop. + + Contributed by Robert Roth , February 2017. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __GLIBTOP_PROCDISKIO_H__ +#define __GLIBTOP_PROCDISKIO_H__ + +#include +#include + +G_BEGIN_DECLS + +#define GLIBTOP_PROC_DISKIO_RCHAR 0 +#define GLIBTOP_PROC_DISKIO_WCHAR 1 +#define GLIBTOP_PROC_DISKIO_RBYTES 2 +#define GLIBTOP_PROC_DISKIO_WBYTES 3 + +#define GLIBTOP_MAX_PROC_TIME 3 + +typedef struct _glibtop_proc_diskio glibtop_proc_diskio; + +/* Time section */ + +/** + * glibtop_proc_diskio: + * @rchar: The number of bytes which this task has caused to be read from storage. This + * is simply the sum of bytes which this process passed to read() and pread(), also including tty IO, + * and it is unaffected by whether or not actual physical disk IO was required. + * @wchar: The number of bytes which this task has caused, or shall cause to be written + * to disk. Similar caveats apply here as with rchar. + * @rbytes: Attempt to count the number of bytes which this process really did cause to + * be fetched from the storage layer. Done at the submit_bio() level, so it is + * accurate for block-backed filesystems. + * @wbytes: Attempt to count the number of bytes which this process caused to be sent to + * the storage layer. This is done at page-dirtying time. + * + * Process disk io data filled by glibtop_get_proc_diskio(). + * + */ +struct _glibtop_proc_diskio +{ + /*< private >*/ + guint64 flags; + /*< public >*/ + guint64 rchar; + guint64 wchar; + guint64 rbytes; + guint64 wbytes; +}; + + +void glibtop_get_proc_diskio (glibtop_proc_diskio *buf, pid_t pid); + +#if GLIBTOP_SUID_PROC_DISKIO +#define glibtop_get_proc_diskio_r glibtop_get_proc_diskio_p +#else +#define glibtop_get_proc_diskio_r glibtop_get_proc_diskio_s +#endif + +void glibtop_get_proc_diskio_l (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); + +#if GLIBTOP_SUID_PROC_DISKIO +void _glibtop_init_proc_diskio_p (glibtop *server); +void glibtop_get_proc_diskio_p (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); +#else +void _glibtop_init_proc_diskio_s (glibtop *server); +void glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); +#endif + + +G_END_DECLS + +#endif diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h index 61006a0a..39c2dad2 100644 --- a/include/glibtop/sysdeps.h +++ b/include/glibtop/sysdeps.h @@ -53,8 +53,9 @@ G_BEGIN_DECLS #define GLIBTOP_SYSDEPS_PROC_OPEN_FILES 24 #define GLIBTOP_SYSDEPS_PROC_WD 25 #define GLIBTOP_SYSDEPS_PROC_AFFINITY 26 +#define GLIBTOP_SYSDEPS_PROC_DISKIO 27 -#define GLIBTOP_MAX_SYSDEPS 27 +#define GLIBTOP_MAX_SYSDEPS 28 /* The 'features' args to glibtop_init_* is an unsigned long */ G_STATIC_ASSERT((1UL << (GLIBTOP_MAX_SYSDEPS - 1)) <= ULONG_MAX); @@ -93,6 +94,7 @@ struct _glibtop_sysdeps guint64 ppp; /* glibtop_ppp */ guint64 proc_wd; /* glibtop_proc_wd */ guint64 proc_affinity; /* glibtop_proc_affinity */ + guint64 proc_diskio; /* glibtop_proc_diskio */ }; void glibtop_get_sysdeps (glibtop_sysdeps *buf); diff --git a/include/glibtop/union.h b/include/glibtop/union.h index a140d71a..9148c408 100644 --- a/include/glibtop/union.h +++ b/include/glibtop/union.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,7 @@ union _glibtop_union glibtop_proc_open_files proc_open_files; glibtop_proc_wd proc_wd; glibtop_proc_affinity proc_affinity; + glibtop_proc_diskio proc_diskio; }; G_END_DECLS diff --git a/lib/Makefile.am b/lib/Makefile.am index dec24a04..b23ba5ea 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,7 +35,7 @@ introspection_sources = $(libgtop_2_0_la_SOURCES) lib.c ../glibtop.h ../libgtopc ../include/glibtop/procsignal.h ../include/glibtop/union.h ../include/glibtop/gnuserv.h \ ../include/glibtop/parameter.h ../include/glibtop/mountlist.h ../include/glibtop/fsusage.h ../include/glibtop/procmap.h ../include/glibtop/signal.h \ ../include/glibtop/sysinfo.h ../include/glibtop/ppp.h ../include/glibtop/procargs.h ../include/glibtop/netload.h \ - ../include/glibtop/procwd.h ../include/glibtop/procaffinity.h \ + ../include/glibtop/procwd.h ../include/glibtop/procaffinity.h ../include/glibtop/procdiskio.h \ ../include/glibtop/netlist.h ../include/glibtop/procopenfiles.h ../include/glibtop/open.h GTop-2.0.gir: libgtop-2.0.la diff --git a/lib/command.c b/lib/command.c index 414081c3..c2ad44d3 100644 --- a/lib/command.c +++ b/lib/command.c @@ -68,6 +68,7 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, CHECK_CMND(GLIBTOP_CMND_PROC_OPEN_FILES); CHECK_CMND(GLIBTOP_CMND_PROC_WD); CHECK_CMND(GLIBTOP_CMND_PROC_AFFINITY); + CHECK_CMND(GLIBTOP_CMND_PROC_DISKIO); default: glibtop_error_r(server, "CALL: command UNKNOWN(%d) sending %lu bytes", command, (unsigned long)send_size); break; } diff --git a/lib/libgtop.sym b/lib/libgtop.sym index d15adcc6..484b9061 100644 --- a/lib/libgtop.sym +++ b/lib/libgtop.sym @@ -52,6 +52,8 @@ glibtop_get_shm_limits glibtop_get_shm_limits_l glibtop_get_proc_affinity glibtop_get_proc_affinity_l +glibtop_get_proc_diskio +glibtop_get_proc_diskio_l glibtop_get_swap glibtop_get_swap_l glibtop_get_sysdeps diff --git a/lib/sysdeps.c b/lib/sysdeps.c index 3a90a54c..47333f98 100644 --- a/lib/sysdeps.c +++ b/lib/sysdeps.c @@ -48,7 +48,8 @@ GLIBTOP_SUID_NETLOAD + GLIBTOP_SUID_NETLIST + GLIBTOP_SUID_PROC_WD + GLIBTOP_SUID_PROC_AFFINITY + -GLIBTOP_SUID_PPP; +GLIBTOP_SUID_PPP + +GLIBTOP_SUID_PROC_DISKIO; const _glibtop_init_func_t _glibtop_init_hook_s [] = { #if !GLIBTOP_SUID_CPU @@ -119,6 +120,9 @@ const _glibtop_init_func_t _glibtop_init_hook_s [] = { #endif #if !GLIBTOP_SUID_PPP _glibtop_init_ppp_s, +#endif +#if !GLIBTOP_SUID_PROC_DISKIO + _glibtop_init_proc_diskio_s, #endif NULL }; @@ -192,6 +196,9 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = { #endif #if GLIBTOP_SUID_PPP _glibtop_init_ppp_p, +#endif +#if GLIBTOP_SUID_PROC_DISKIO + _glibtop_init_proc_diskio_p, #endif NULL }; diff --git a/src/daemon/main.c b/src/daemon/main.c index 11364229..14868765 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -221,6 +221,12 @@ handle_parent_connection (int s) do_output (s, resp, _offset_data (fsusage), 0, NULL); break; + case GLIBTOP_CMND_PROC_DISKIO: + glibtop_get_proc_diskio_l + (server, &resp->u.data.proc_diskio, parameter); + do_output (s, resp, _offset_data (proc_diskio), + 0, NULL); + break; case GLIBTOP_CMND_PPP: memcpy (&device, parameter, sizeof (device)); glibtop_get_ppp_l diff --git a/sysdeps/common/default.c b/sysdeps/common/default.c index 2df25ee6..6987fb20 100644 --- a/sysdeps/common/default.c +++ b/sysdeps/common/default.c @@ -431,3 +431,18 @@ glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid) { return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid); } + +/** + * glibtop_get_proc_diskio: Get the disk io stats for the given pid + * @buf: Buffer where the result will be given + * @pid: Process id to get the io stats for + * + * Get the io stats for a process + * + * Returns: A list of processor ID of 'buf.number' elements. + */ +void +glibtop_get_proc_diskio(glibtop_proc_diskio *buf, pid_t pid) +{ + return glibtop_get_proc_diskio_l(glibtop_global_server, buf, pid); +} diff --git a/sysdeps/common/sysdeps_suid.c b/sysdeps/common/sysdeps_suid.c index 91ff806c..70dd2256 100644 --- a/sysdeps/common/sysdeps_suid.c +++ b/sysdeps/common/sysdeps_suid.c @@ -89,6 +89,9 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = { #endif #if GLIBTOP_SUID_PPP _glibtop_init_ppp_p, +#endif +#if GLIBTOP_SUID_PROC_DISKIO + _glibtop_init_proc_diskio_p, #endif NULL }; diff --git a/sysdeps/linux/Makefile.am b/sysdeps/linux/Makefile.am index ae480f1f..0657fdc2 100644 --- a/sysdeps/linux/Makefile.am +++ b/sysdeps/linux/Makefile.am @@ -10,7 +10,7 @@ libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \ proctime.c procmem.c procsignal.c prockernel.c \ procsegment.c procargs.c procmap.c siglist.c \ sysinfo.c netload.c ppp.c glibtop_private.c \ - mountlist.c procaffinity.c \ + mountlist.c procaffinity.c procdiskio.c \ fsusage.c netlist.c procopenfiles.c procwd.c libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@ diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index 5912ad05..db81b71c 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -46,5 +46,6 @@ #define GLIBTOP_SUID_PROC_AFFINITY 0 #define GLIBTOP_SUID_PPP 0 #define GLIBTOP_SUID_PROC_FILE 0 +#define GLIBTOP_SUID_PROC_DISKIO 0 #endif /* __LINUX__GLIBTOP_SERVER_H__ */ diff --git a/sysdeps/linux/procdiskio.c b/sysdeps/linux/procdiskio.c new file mode 100644 index 00000000..fba687f1 --- /dev/null +++ b/sysdeps/linux/procdiskio.c @@ -0,0 +1,66 @@ +/* Copyright (C) 2017 Robert Roth + This file is part of LibGTop. + + Contributed by Robert Roth , February 2017. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include "glibtop_private.h" + +static const unsigned long _glibtop_sysdeps_proc_diskio = +(1L << GLIBTOP_PROC_DISKIO_RCHAR) + (1L << GLIBTOP_PROC_DISKIO_WCHAR) + +(1L << GLIBTOP_PROC_DISKIO_RBYTES) + (1L << GLIBTOP_PROC_DISKIO_WBYTES); + +/* Init function. */ + +void +_glibtop_init_proc_diskio_s (glibtop *server) +{ + server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; +} + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid) +{ + char buffer [BUFSIZ], *p; + memset (buf, 0, sizeof (glibtop_proc_diskio)); + + + if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/io", pid)) + return; + + p = skip_token (buffer); + buf->rchar = g_ascii_strtoull (p, &p, 10); + p = skip_line (p); + p = skip_token (p); + buf->wchar = g_ascii_strtoull (p, &p, 10); + p = skip_line (p); + p = skip_line (p); + p = skip_line (p); + p = skip_token (p); + buf->rbytes = g_ascii_strtoull (p, &p, 10); + p = skip_line (p); + p = skip_token (p); + buf->wbytes = g_ascii_strtoull (p, &p, 10); +} diff --git a/sysdeps/stub/procdiskio.c b/sysdeps/stub/procdiskio.c new file mode 100644 index 00000000..455fec6d --- /dev/null +++ b/sysdeps/stub/procdiskio.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2017 Robert Roth + This file is part of LibGTop. + + Contributed by Robert Roth , February 2017. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +static const unsigned long _glibtop_sysdeps_proc_diskio = 0; + +/* Init function. */ + +void +_glibtop_init_proc_diskio_s (glibtop *server) +{ + server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; +} + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_diskio)); +} diff --git a/sysdeps/stub_suid/glibtop_server.h b/sysdeps/stub_suid/glibtop_server.h index cf121212..ef0b191b 100644 --- a/sysdeps/stub_suid/glibtop_server.h +++ b/sysdeps/stub_suid/glibtop_server.h @@ -45,6 +45,7 @@ G_BEGIN_DECLS #define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD) #define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP) +#define GLIBTOP_SUID_PROC_DISKIO (1 << GLIBTOP_SYSDEPS_PROC_DISKIO) G_END_DECLS From 1defc74f078d77cf3e22b425de5425666c4e8087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Tue, 21 Feb 2017 12:50:37 +0100 Subject: [PATCH 02/11] Set glibtop_proc_diskio.flags. Check linux version code before reading /proc/PID/io. --- sysdeps/linux/procdiskio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sysdeps/linux/procdiskio.c b/sysdeps/linux/procdiskio.c index fba687f1..08bd5539 100644 --- a/sysdeps/linux/procdiskio.c +++ b/sysdeps/linux/procdiskio.c @@ -46,6 +46,8 @@ glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid) char buffer [BUFSIZ], *p; memset (buf, 0, sizeof (glibtop_proc_diskio)); + if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 20)) + return; if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/io", pid)) return; @@ -63,4 +65,6 @@ glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid) p = skip_line (p); p = skip_token (p); buf->wbytes = g_ascii_strtoull (p, &p, 10); + + buf->flags = _glibtop_sysdeps_proc_diskio; } From b589a4fcf0f7b5f9da07b458bbab8fc52749819f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Tue, 21 Feb 2017 13:01:04 +0100 Subject: [PATCH 03/11] Fix GLIBTOP_MAX variable name for diskio. --- include/glibtop/procdiskio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/glibtop/procdiskio.h b/include/glibtop/procdiskio.h index 5d7b18e3..6545ab36 100644 --- a/include/glibtop/procdiskio.h +++ b/include/glibtop/procdiskio.h @@ -32,7 +32,7 @@ G_BEGIN_DECLS #define GLIBTOP_PROC_DISKIO_RBYTES 2 #define GLIBTOP_PROC_DISKIO_WBYTES 3 -#define GLIBTOP_MAX_PROC_TIME 3 +#define GLIBTOP_MAX_PROC_DISKIO 3 typedef struct _glibtop_proc_diskio glibtop_proc_diskio; From b7a684fbbc7647395fb1a458baa7b58a9f54e110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Fri, 24 Feb 2017 09:04:06 +0100 Subject: [PATCH 04/11] Also display the flags value. --- examples/diskio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/diskio.c b/examples/diskio.c index e52844aa..60dd9338 100644 --- a/examples/diskio.c +++ b/examples/diskio.c @@ -17,7 +17,7 @@ static void show_diskio(pid_t pid) printf("<%ld>\t", (long)pid); - printf("rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", diskio.rchar, diskio.wchar, diskio.rbytes, diskio.wbytes); + printf("flags: %08lx rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", (unsigned long)diskio.flags, diskio.rchar, diskio.wchar, diskio.rbytes, diskio.wbytes); } From afec9bbf58127a63008b0fd7bced797565079c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Fri, 24 Feb 2017 09:04:23 +0100 Subject: [PATCH 05/11] Add proc_diskio in sysdeps and timings tests. --- examples/sysdeps.c | 7 +++++-- examples/timings.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/sysdeps.c b/examples/sysdeps.c index 5d55142c..a63a3545 100644 --- a/examples/sysdeps.c +++ b/examples/sysdeps.c @@ -92,9 +92,10 @@ main (int argc, char *argv []) "\tproc_time:\t%d\t0x%08lx\n" "\tproc_signal:\t%d\t0x%08lx\n" "\tproc_kernel:\t%d\t0x%08lx\n" - "\tproc_segment:\t%d\t0x%08lx\n\n" + "\tproc_segment:\t%d\t0x%08lx\n" "\tproc_args:\t%d\t0x%08lx\n" - "\tproc_map:\t%d\t0x%08lx\n\n" + "\tproc_map:\t%d\t0x%08lx\n" + "\tproc_diskio:\t%d\t0x%08lx\n\n" "\tmountlist:\t%d\t0x%08lx\n" "\tfsusage:\t%d\t0x%08lx\n\n" "\tnetload:\t%d\t0x%08lx\n" @@ -137,6 +138,8 @@ main (int argc, char *argv []) (unsigned long) sysdeps.proc_args, FEATURE_CHECK(PROC_MAP), (unsigned long) sysdeps.proc_map, + FEATURE_CHECK(PROC_DISKIO), + (unsigned long) sysdeps.proc_diskio, FEATURE_CHECK(MOUNTLIST), (unsigned long) sysdeps.mountlist, FEATURE_CHECK(FSUSAGE), diff --git a/examples/timings.c b/examples/timings.c index 6c85da0f..f7537a73 100644 --- a/examples/timings.c +++ b/examples/timings.c @@ -412,6 +412,26 @@ main (int argc, char *argv []) (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); + + getrusage (RUSAGE_SELF, &rusage_start); + + for (c = 0; c < PROFILE_COUNT; c++) + glibtop_get_proc_diskio (&data.proc_diskio, pid); + + getrusage (RUSAGE_SELF, &rusage_end); + + libgtop_timersub (&rusage_end.ru_utime, &rusage_start.ru_utime, + &elapsed_utime); + + libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, + &elapsed_stime); + + printf ("Proc_DiskIo (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", + (unsigned long) data.proc_diskio.flags, PROFILE_COUNT, + (long double) ELAPSED_UTIME / PROFILE_COUNT, + (long double) ELAPSED_STIME / PROFILE_COUNT); + + getrusage (RUSAGE_SELF, &total_end); libgtop_timersub (&total_end.ru_utime, &total_start.ru_utime, From 07abbd2dfe5c734cbeadc27e17196c4b1d3a7188 Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sat, 25 Feb 2017 16:29:26 +0100 Subject: [PATCH 06/11] Add slave proc_diskio handler. --- src/daemon/slave.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/daemon/slave.c b/src/daemon/slave.c index 2858ee8a..ea0c674b 100644 --- a/src/daemon/slave.c +++ b/src/daemon/slave.c @@ -209,6 +209,14 @@ handle_slave_command (glibtop_command *cmnd, glibtop_response *resp, resp->offset = _offset_data (proc_time); break; #endif +#if GLIBTOP_SUID_PROC_DISKIO + case GLIBTOP_CMND_PROC_DISKIO: + memcpy (&pid, parameter, sizeof (pid_t)); + glibtop_get_proc_diskio_p + (server, &resp->u.data.proc_diskio, pid); + resp->offset = _offset_data (proc_time); + break; +#endif #if GLIBTOP_SUID_PROC_SIGNAL case GLIBTOP_CMND_PROC_SIGNAL: memcpy (&pid, parameter, sizeof (pid_t)); From c29d7de9a087ff781be5463f4d9efc9a8f6abbe4 Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sat, 25 Feb 2017 16:30:18 +0100 Subject: [PATCH 07/11] Add dummy proc_diskio implementation for FreeBSD. --- sysdeps/freebsd/Makefile.am | 1 + sysdeps/freebsd/glibtop_server.h | 1 + sysdeps/freebsd/procdiskio.c | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 sysdeps/freebsd/procdiskio.c diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am index 6bd15894..5d92dc0d 100644 --- a/sysdeps/freebsd/Makefile.am +++ b/sysdeps/freebsd/Makefile.am @@ -16,6 +16,7 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = suid_open.c close.c swap.c \ proclist.c procstate.c procuid.c \ proctime.c procmem.c procsignal.c \ prockernel.c procsegment.c procargs.c \ + procdiskio.c \ procmap.c netload.c ppp.c libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO) diff --git a/sysdeps/freebsd/glibtop_server.h b/sysdeps/freebsd/glibtop_server.h index d9ea12d6..6d6b73f9 100644 --- a/sysdeps/freebsd/glibtop_server.h +++ b/sysdeps/freebsd/glibtop_server.h @@ -47,6 +47,7 @@ G_BEGIN_DECLS #define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_PROC_WD 0 #define GLIBTOP_SUID_PROC_AFFINITY 0 +#define GLIBTOP_SUID_PROC_DISKIO (1 << GLIBTOP_SYSDEPS_PROC_DISKIO) G_END_DECLS diff --git a/sysdeps/freebsd/procdiskio.c b/sysdeps/freebsd/procdiskio.c new file mode 100644 index 00000000..ed825861 --- /dev/null +++ b/sysdeps/freebsd/procdiskio.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2017 Robert Roth + This file is part of LibGTop. + + Contributed by Robert Roth , February 2017. + + LibGTop is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + LibGTop is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with LibGTop; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +static const unsigned long _glibtop_sysdeps_proc_diskio = 0; + +/* Init function. */ + +void +_glibtop_init_proc_diskio_p (glibtop *server) +{ + server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; +} + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_diskio_p (glibtop *server, glibtop_proc_diskio *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_diskio)); +} From 1bf16bfffd28e6724c35589e49db10a10cae594d Mon Sep 17 00:00:00 2001 From: Robert Roth Date: Fri, 12 May 2017 05:08:41 +0300 Subject: [PATCH 08/11] Renamed procdiskio to procio --- examples/diskio.c | 8 ++--- examples/sysdeps.c | 6 ++-- examples/timings.c | 6 ++-- features.def | 2 +- include/glibtop/Makefile.am | 2 +- include/glibtop/command.h | 2 +- include/glibtop/{procdiskio.h => procio.h} | 42 +++++++++++----------- include/glibtop/sysdeps.h | 4 +-- include/glibtop/union.h | 4 +-- lib/Makefile.am | 2 +- lib/command.c | 2 +- lib/libgtop.sym | 4 +-- lib/sysdeps.c | 10 +++--- src/daemon/main.c | 8 ++--- src/daemon/slave.c | 8 ++--- sysdeps/common/default.c | 6 ++-- sysdeps/common/sysdeps_suid.c | 4 +-- sysdeps/freebsd/Makefile.am | 2 +- sysdeps/freebsd/glibtop_server.h | 2 +- sysdeps/freebsd/{procdiskio.c => procio.c} | 12 +++---- sysdeps/linux/Makefile.am | 2 +- sysdeps/linux/glibtop_server.h | 2 +- sysdeps/linux/{procdiskio.c => procio.c} | 18 +++++----- sysdeps/stub/{procdiskio.c => procio.c} | 12 +++---- sysdeps/stub_suid/glibtop_server.h | 2 +- 25 files changed, 86 insertions(+), 86 deletions(-) rename include/glibtop/{procdiskio.h => procio.h} (65%) rename sysdeps/freebsd/{procdiskio.c => procio.c} (76%) rename sysdeps/linux/{procdiskio.c => procio.c} (76%) rename sysdeps/stub/{procdiskio.c => procio.c} (76%) diff --git a/examples/diskio.c b/examples/diskio.c index 60dd9338..112b4723 100644 --- a/examples/diskio.c +++ b/examples/diskio.c @@ -3,7 +3,7 @@ #endif #include -#include +#include #include @@ -11,13 +11,13 @@ static void show_diskio(pid_t pid) { - glibtop_proc_diskio diskio; + glibtop_proc_io io; - glibtop_get_proc_diskio (&diskio, pid); + glibtop_get_proc_io (&io, pid); printf("<%ld>\t", (long)pid); - printf("flags: %08lx rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", (unsigned long)diskio.flags, diskio.rchar, diskio.wchar, diskio.rbytes, diskio.wbytes); + printf("flags: %08lx rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", (unsigned long)io.flags, io.rchar, io.wchar, io.rbytes, io.wbytes); } diff --git a/examples/sysdeps.c b/examples/sysdeps.c index a63a3545..559f93ef 100644 --- a/examples/sysdeps.c +++ b/examples/sysdeps.c @@ -95,7 +95,7 @@ main (int argc, char *argv []) "\tproc_segment:\t%d\t0x%08lx\n" "\tproc_args:\t%d\t0x%08lx\n" "\tproc_map:\t%d\t0x%08lx\n" - "\tproc_diskio:\t%d\t0x%08lx\n\n" + "\tproc_io:\t%d\t0x%08lx\n\n" "\tmountlist:\t%d\t0x%08lx\n" "\tfsusage:\t%d\t0x%08lx\n\n" "\tnetload:\t%d\t0x%08lx\n" @@ -138,8 +138,8 @@ main (int argc, char *argv []) (unsigned long) sysdeps.proc_args, FEATURE_CHECK(PROC_MAP), (unsigned long) sysdeps.proc_map, - FEATURE_CHECK(PROC_DISKIO), - (unsigned long) sysdeps.proc_diskio, + FEATURE_CHECK(PROC_IO), + (unsigned long) sysdeps.proc_io, FEATURE_CHECK(MOUNTLIST), (unsigned long) sysdeps.mountlist, FEATURE_CHECK(FSUSAGE), diff --git a/examples/timings.c b/examples/timings.c index f7537a73..15bc1973 100644 --- a/examples/timings.c +++ b/examples/timings.c @@ -416,7 +416,7 @@ main (int argc, char *argv []) getrusage (RUSAGE_SELF, &rusage_start); for (c = 0; c < PROFILE_COUNT; c++) - glibtop_get_proc_diskio (&data.proc_diskio, pid); + glibtop_get_proc_io (&data.proc_io, pid); getrusage (RUSAGE_SELF, &rusage_end); @@ -426,8 +426,8 @@ main (int argc, char *argv []) libgtop_timersub (&rusage_end.ru_stime, &rusage_start.ru_stime, &elapsed_stime); - printf ("Proc_DiskIo (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", - (unsigned long) data.proc_diskio.flags, PROFILE_COUNT, + printf ("Proc_Io (0x%08lx): %7lu - %9.2Lf - %9.2Lf\n", + (unsigned long) data.proc_io.flags, PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_STIME / PROFILE_COUNT); diff --git a/features.def b/features.def index 065d8fa1..faab87b1 100644 --- a/features.def +++ b/features.def @@ -24,5 +24,5 @@ void|ppp|ushort(device) char **|netlist char **|proc_wd|pid_t(pid) guint16*|proc_affinity|pid_t(pid) -void|proc_diskio|pid_t(pid) +void|proc_io|pid_t(pid) diff --git a/include/glibtop/Makefile.am b/include/glibtop/Makefile.am index b797385e..6d0e055f 100644 --- a/include/glibtop/Makefile.am +++ b/include/glibtop/Makefile.am @@ -9,7 +9,7 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \ parameter.h mountlist.h fsusage.h procmap.h signal.h \ sysinfo.h ppp.h procargs.h netload.h \ procwd.h procaffinity.h \ - procdiskio.h \ + procio.h \ netlist.h procopenfiles.h open.h noinst_HEADERS = error.h write.h read_data.h read.h init_hooks.h machine.h \ diff --git a/include/glibtop/command.h b/include/glibtop/command.h index 6e9dc079..9a0e47b1 100644 --- a/include/glibtop/command.h +++ b/include/glibtop/command.h @@ -59,7 +59,7 @@ G_BEGIN_DECLS #define GLIBTOP_CMND_PROC_OPEN_FILES 25 #define GLIBTOP_CMND_PROC_WD 26 #define GLIBTOP_CMND_PROC_AFFINITY 27 -#define GLIBTOP_CMND_PROC_DISKIO 28 +#define GLIBTOP_CMND_PROC_IO 28 #define GLIBTOP_MAX_CMND 29 diff --git a/include/glibtop/procdiskio.h b/include/glibtop/procio.h similarity index 65% rename from include/glibtop/procdiskio.h rename to include/glibtop/procio.h index 6545ab36..48e2c617 100644 --- a/include/glibtop/procdiskio.h +++ b/include/glibtop/procio.h @@ -19,27 +19,27 @@ Boston, MA 02110-1301, USA. */ -#ifndef __GLIBTOP_PROCDISKIO_H__ -#define __GLIBTOP_PROCDISKIO_H__ +#ifndef __GLIBTOP_PROCIO_H__ +#define __GLIBTOP_PROCIO_H__ #include #include G_BEGIN_DECLS -#define GLIBTOP_PROC_DISKIO_RCHAR 0 -#define GLIBTOP_PROC_DISKIO_WCHAR 1 -#define GLIBTOP_PROC_DISKIO_RBYTES 2 -#define GLIBTOP_PROC_DISKIO_WBYTES 3 +#define GLIBTOP_PROC_IO_RCHAR 0 +#define GLIBTOP_PROC_IO_WCHAR 1 +#define GLIBTOP_PROC_IO_RBYTES 2 +#define GLIBTOP_PROC_IO_WBYTES 3 -#define GLIBTOP_MAX_PROC_DISKIO 3 +#define GLIBTOP_MAX_PROC_IO 3 -typedef struct _glibtop_proc_diskio glibtop_proc_diskio; +typedef struct _glibtop_proc_io glibtop_proc_io; /* Time section */ /** - * glibtop_proc_diskio: + * glibtop_proc_io: * @rchar: The number of bytes which this task has caused to be read from storage. This * is simply the sum of bytes which this process passed to read() and pread(), also including tty IO, * and it is unaffected by whether or not actual physical disk IO was required. @@ -51,10 +51,10 @@ typedef struct _glibtop_proc_diskio glibtop_proc_diskio; * @wbytes: Attempt to count the number of bytes which this process caused to be sent to * the storage layer. This is done at page-dirtying time. * - * Process disk io data filled by glibtop_get_proc_diskio(). + * Process disk io data filled by glibtop_get_proc_io(). * */ -struct _glibtop_proc_diskio +struct _glibtop_proc_io { /*< private >*/ guint64 flags; @@ -66,22 +66,22 @@ struct _glibtop_proc_diskio }; -void glibtop_get_proc_diskio (glibtop_proc_diskio *buf, pid_t pid); +void glibtop_get_proc_io (glibtop_proc_io *buf, pid_t pid); -#if GLIBTOP_SUID_PROC_DISKIO -#define glibtop_get_proc_diskio_r glibtop_get_proc_diskio_p +#if GLIBTOP_SUID_PROC_IO +#define glibtop_get_proc_io_r glibtop_get_proc_io_p #else -#define glibtop_get_proc_diskio_r glibtop_get_proc_diskio_s +#define glibtop_get_proc_io_r glibtop_get_proc_io_s #endif -void glibtop_get_proc_diskio_l (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); +void glibtop_get_proc_io_l (glibtop *server, glibtop_proc_io *buf, pid_t pid); -#if GLIBTOP_SUID_PROC_DISKIO -void _glibtop_init_proc_diskio_p (glibtop *server); -void glibtop_get_proc_diskio_p (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); +#if GLIBTOP_SUID_PROC_IO +void _glibtop_init_proc_io_p (glibtop *server); +void glibtop_get_proc_io_p (glibtop *server, glibtop_proc_io *buf, pid_t pid); #else -void _glibtop_init_proc_diskio_s (glibtop *server); -void glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid); +void _glibtop_init_proc_io_s (glibtop *server); +void glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid); #endif diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h index 39c2dad2..6b5682df 100644 --- a/include/glibtop/sysdeps.h +++ b/include/glibtop/sysdeps.h @@ -53,7 +53,7 @@ G_BEGIN_DECLS #define GLIBTOP_SYSDEPS_PROC_OPEN_FILES 24 #define GLIBTOP_SYSDEPS_PROC_WD 25 #define GLIBTOP_SYSDEPS_PROC_AFFINITY 26 -#define GLIBTOP_SYSDEPS_PROC_DISKIO 27 +#define GLIBTOP_SYSDEPS_PROC_IO 27 #define GLIBTOP_MAX_SYSDEPS 28 @@ -94,7 +94,7 @@ struct _glibtop_sysdeps guint64 ppp; /* glibtop_ppp */ guint64 proc_wd; /* glibtop_proc_wd */ guint64 proc_affinity; /* glibtop_proc_affinity */ - guint64 proc_diskio; /* glibtop_proc_diskio */ + guint64 proc_io; /* glibtop_proc_io */ }; void glibtop_get_sysdeps (glibtop_sysdeps *buf); diff --git a/include/glibtop/union.h b/include/glibtop/union.h index 9148c408..334f0217 100644 --- a/include/glibtop/union.h +++ b/include/glibtop/union.h @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include @@ -85,7 +85,7 @@ union _glibtop_union glibtop_proc_open_files proc_open_files; glibtop_proc_wd proc_wd; glibtop_proc_affinity proc_affinity; - glibtop_proc_diskio proc_diskio; + glibtop_proc_io proc_io; }; G_END_DECLS diff --git a/lib/Makefile.am b/lib/Makefile.am index b23ba5ea..90b82861 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,7 +35,7 @@ introspection_sources = $(libgtop_2_0_la_SOURCES) lib.c ../glibtop.h ../libgtopc ../include/glibtop/procsignal.h ../include/glibtop/union.h ../include/glibtop/gnuserv.h \ ../include/glibtop/parameter.h ../include/glibtop/mountlist.h ../include/glibtop/fsusage.h ../include/glibtop/procmap.h ../include/glibtop/signal.h \ ../include/glibtop/sysinfo.h ../include/glibtop/ppp.h ../include/glibtop/procargs.h ../include/glibtop/netload.h \ - ../include/glibtop/procwd.h ../include/glibtop/procaffinity.h ../include/glibtop/procdiskio.h \ + ../include/glibtop/procwd.h ../include/glibtop/procaffinity.h ../include/glibtop/procio.h \ ../include/glibtop/netlist.h ../include/glibtop/procopenfiles.h ../include/glibtop/open.h GTop-2.0.gir: libgtop-2.0.la diff --git a/lib/command.c b/lib/command.c index c2ad44d3..b6ccf1f2 100644 --- a/lib/command.c +++ b/lib/command.c @@ -68,7 +68,7 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, CHECK_CMND(GLIBTOP_CMND_PROC_OPEN_FILES); CHECK_CMND(GLIBTOP_CMND_PROC_WD); CHECK_CMND(GLIBTOP_CMND_PROC_AFFINITY); - CHECK_CMND(GLIBTOP_CMND_PROC_DISKIO); + CHECK_CMND(GLIBTOP_CMND_PROC_IO); default: glibtop_error_r(server, "CALL: command UNKNOWN(%d) sending %lu bytes", command, (unsigned long)send_size); break; } diff --git a/lib/libgtop.sym b/lib/libgtop.sym index 484b9061..afa9d070 100644 --- a/lib/libgtop.sym +++ b/lib/libgtop.sym @@ -52,8 +52,8 @@ glibtop_get_shm_limits glibtop_get_shm_limits_l glibtop_get_proc_affinity glibtop_get_proc_affinity_l -glibtop_get_proc_diskio -glibtop_get_proc_diskio_l +glibtop_get_proc_io +glibtop_get_proc_io_l glibtop_get_swap glibtop_get_swap_l glibtop_get_sysdeps diff --git a/lib/sysdeps.c b/lib/sysdeps.c index 47333f98..e942fd4a 100644 --- a/lib/sysdeps.c +++ b/lib/sysdeps.c @@ -49,7 +49,7 @@ GLIBTOP_SUID_NETLIST + GLIBTOP_SUID_PROC_WD + GLIBTOP_SUID_PROC_AFFINITY + GLIBTOP_SUID_PPP + -GLIBTOP_SUID_PROC_DISKIO; +GLIBTOP_SUID_PROC_IO; const _glibtop_init_func_t _glibtop_init_hook_s [] = { #if !GLIBTOP_SUID_CPU @@ -121,8 +121,8 @@ const _glibtop_init_func_t _glibtop_init_hook_s [] = { #if !GLIBTOP_SUID_PPP _glibtop_init_ppp_s, #endif -#if !GLIBTOP_SUID_PROC_DISKIO - _glibtop_init_proc_diskio_s, +#if !GLIBTOP_SUID_PROC_IO + _glibtop_init_proc_io_s, #endif NULL }; @@ -197,8 +197,8 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = { #if GLIBTOP_SUID_PPP _glibtop_init_ppp_p, #endif -#if GLIBTOP_SUID_PROC_DISKIO - _glibtop_init_proc_diskio_p, +#if GLIBTOP_SUID_PROC_IO + _glibtop_init_proc_io_p, #endif NULL }; diff --git a/src/daemon/main.c b/src/daemon/main.c index 14868765..b51addf6 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -221,10 +221,10 @@ handle_parent_connection (int s) do_output (s, resp, _offset_data (fsusage), 0, NULL); break; - case GLIBTOP_CMND_PROC_DISKIO: - glibtop_get_proc_diskio_l - (server, &resp->u.data.proc_diskio, parameter); - do_output (s, resp, _offset_data (proc_diskio), + case GLIBTOP_CMND_PROC_IO: + glibtop_get_proc_io_l + (server, &resp->u.data.proc_io, parameter); + do_output (s, resp, _offset_data (proc_io), 0, NULL); break; case GLIBTOP_CMND_PPP: diff --git a/src/daemon/slave.c b/src/daemon/slave.c index ea0c674b..e15f1efc 100644 --- a/src/daemon/slave.c +++ b/src/daemon/slave.c @@ -209,11 +209,11 @@ handle_slave_command (glibtop_command *cmnd, glibtop_response *resp, resp->offset = _offset_data (proc_time); break; #endif -#if GLIBTOP_SUID_PROC_DISKIO - case GLIBTOP_CMND_PROC_DISKIO: +#if GLIBTOP_SUID_PROC_IO + case GLIBTOP_CMND_PROC_IO: memcpy (&pid, parameter, sizeof (pid_t)); - glibtop_get_proc_diskio_p - (server, &resp->u.data.proc_diskio, pid); + glibtop_get_proc_io_p + (server, &resp->u.data.proc_io, pid); resp->offset = _offset_data (proc_time); break; #endif diff --git a/sysdeps/common/default.c b/sysdeps/common/default.c index 6987fb20..e3b096f2 100644 --- a/sysdeps/common/default.c +++ b/sysdeps/common/default.c @@ -433,7 +433,7 @@ glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid) } /** - * glibtop_get_proc_diskio: Get the disk io stats for the given pid + * glibtop_get_proc_io: Get the io stats for the given pid * @buf: Buffer where the result will be given * @pid: Process id to get the io stats for * @@ -442,7 +442,7 @@ glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid) * Returns: A list of processor ID of 'buf.number' elements. */ void -glibtop_get_proc_diskio(glibtop_proc_diskio *buf, pid_t pid) +glibtop_get_proc_io(glibtop_proc_io *buf, pid_t pid) { - return glibtop_get_proc_diskio_l(glibtop_global_server, buf, pid); + return glibtop_get_proc_io_l(glibtop_global_server, buf, pid); } diff --git a/sysdeps/common/sysdeps_suid.c b/sysdeps/common/sysdeps_suid.c index 70dd2256..24953176 100644 --- a/sysdeps/common/sysdeps_suid.c +++ b/sysdeps/common/sysdeps_suid.c @@ -90,8 +90,8 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = { #if GLIBTOP_SUID_PPP _glibtop_init_ppp_p, #endif -#if GLIBTOP_SUID_PROC_DISKIO - _glibtop_init_proc_diskio_p, +#if GLIBTOP_SUID_PROC_IO + _glibtop_init_proc_io_p, #endif NULL }; diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am index 5d92dc0d..7cacb707 100644 --- a/sysdeps/freebsd/Makefile.am +++ b/sysdeps/freebsd/Makefile.am @@ -16,7 +16,7 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = suid_open.c close.c swap.c \ proclist.c procstate.c procuid.c \ proctime.c procmem.c procsignal.c \ prockernel.c procsegment.c procargs.c \ - procdiskio.c \ + procio.c \ procmap.c netload.c ppp.c libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO) diff --git a/sysdeps/freebsd/glibtop_server.h b/sysdeps/freebsd/glibtop_server.h index 6d6b73f9..d908ea7c 100644 --- a/sysdeps/freebsd/glibtop_server.h +++ b/sysdeps/freebsd/glibtop_server.h @@ -47,7 +47,7 @@ G_BEGIN_DECLS #define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_PROC_WD 0 #define GLIBTOP_SUID_PROC_AFFINITY 0 -#define GLIBTOP_SUID_PROC_DISKIO (1 << GLIBTOP_SYSDEPS_PROC_DISKIO) +#define GLIBTOP_SUID_PROC_IO (1 << GLIBTOP_SYSDEPS_PROC_IO) G_END_DECLS diff --git a/sysdeps/freebsd/procdiskio.c b/sysdeps/freebsd/procio.c similarity index 76% rename from sysdeps/freebsd/procdiskio.c rename to sysdeps/freebsd/procio.c index ed825861..27a7a0b3 100644 --- a/sysdeps/freebsd/procdiskio.c +++ b/sysdeps/freebsd/procio.c @@ -21,23 +21,23 @@ #include #include -#include +#include -static const unsigned long _glibtop_sysdeps_proc_diskio = 0; +static const unsigned long _glibtop_sysdeps_proc_io = 0; /* Init function. */ void -_glibtop_init_proc_diskio_p (glibtop *server) +_glibtop_init_proc_io_p (glibtop *server) { - server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; + server->sysdeps.proc_io = _glibtop_sysdeps_proc_io; } /* Provides detailed information about a process. */ void -glibtop_get_proc_diskio_p (glibtop *server, glibtop_proc_diskio *buf, +glibtop_get_proc_io_p (glibtop *server, glibtop_proc_io *buf, pid_t pid) { - memset (buf, 0, sizeof (glibtop_proc_diskio)); + memset (buf, 0, sizeof (glibtop_proc_io)); } diff --git a/sysdeps/linux/Makefile.am b/sysdeps/linux/Makefile.am index 0657fdc2..7baabe0b 100644 --- a/sysdeps/linux/Makefile.am +++ b/sysdeps/linux/Makefile.am @@ -10,7 +10,7 @@ libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \ proctime.c procmem.c procsignal.c prockernel.c \ procsegment.c procargs.c procmap.c siglist.c \ sysinfo.c netload.c ppp.c glibtop_private.c \ - mountlist.c procaffinity.c procdiskio.c \ + mountlist.c procaffinity.c procio.c \ fsusage.c netlist.c procopenfiles.c procwd.c libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@ diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index db81b71c..8e591eab 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -46,6 +46,6 @@ #define GLIBTOP_SUID_PROC_AFFINITY 0 #define GLIBTOP_SUID_PPP 0 #define GLIBTOP_SUID_PROC_FILE 0 -#define GLIBTOP_SUID_PROC_DISKIO 0 +#define GLIBTOP_SUID_PROC_IO 0 #endif /* __LINUX__GLIBTOP_SERVER_H__ */ diff --git a/sysdeps/linux/procdiskio.c b/sysdeps/linux/procio.c similarity index 76% rename from sysdeps/linux/procdiskio.c rename to sysdeps/linux/procio.c index 08bd5539..55a37fe9 100644 --- a/sysdeps/linux/procdiskio.c +++ b/sysdeps/linux/procio.c @@ -22,29 +22,29 @@ #include #include #include -#include +#include #include "glibtop_private.h" -static const unsigned long _glibtop_sysdeps_proc_diskio = -(1L << GLIBTOP_PROC_DISKIO_RCHAR) + (1L << GLIBTOP_PROC_DISKIO_WCHAR) + -(1L << GLIBTOP_PROC_DISKIO_RBYTES) + (1L << GLIBTOP_PROC_DISKIO_WBYTES); +static const unsigned long _glibtop_sysdeps_proc_io = +(1L << GLIBTOP_PROC_IO_RCHAR) + (1L << GLIBTOP_PROC_IO_WCHAR) + +(1L << GLIBTOP_PROC_IO_RBYTES) + (1L << GLIBTOP_PROC_IO_WBYTES); /* Init function. */ void -_glibtop_init_proc_diskio_s (glibtop *server) +_glibtop_init_proc_io_s (glibtop *server) { - server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; + server->sysdeps.proc_io = _glibtop_sysdeps_proc_io; } /* Provides detailed information about a process. */ void -glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid) +glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid) { char buffer [BUFSIZ], *p; - memset (buf, 0, sizeof (glibtop_proc_diskio)); + memset (buf, 0, sizeof (glibtop_proc_io)); if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 20)) return; @@ -66,5 +66,5 @@ glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, pid_t pid) p = skip_token (p); buf->wbytes = g_ascii_strtoull (p, &p, 10); - buf->flags = _glibtop_sysdeps_proc_diskio; + buf->flags = _glibtop_sysdeps_proc_io; } diff --git a/sysdeps/stub/procdiskio.c b/sysdeps/stub/procio.c similarity index 76% rename from sysdeps/stub/procdiskio.c rename to sysdeps/stub/procio.c index 455fec6d..a4846aee 100644 --- a/sysdeps/stub/procdiskio.c +++ b/sysdeps/stub/procio.c @@ -21,23 +21,23 @@ #include #include -#include +#include -static const unsigned long _glibtop_sysdeps_proc_diskio = 0; +static const unsigned long _glibtop_sysdeps_proc_io = 0; /* Init function. */ void -_glibtop_init_proc_diskio_s (glibtop *server) +_glibtop_init_proc_io_s (glibtop *server) { - server->sysdeps.proc_diskio = _glibtop_sysdeps_proc_diskio; + server->sysdeps.proc_io = _glibtop_sysdeps_proc_io; } /* Provides detailed information about a process. */ void -glibtop_get_proc_diskio_s (glibtop *server, glibtop_proc_diskio *buf, +glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid) { - memset (buf, 0, sizeof (glibtop_proc_diskio)); + memset (buf, 0, sizeof (glibtop_proc_io)); } diff --git a/sysdeps/stub_suid/glibtop_server.h b/sysdeps/stub_suid/glibtop_server.h index ef0b191b..15fe2e11 100644 --- a/sysdeps/stub_suid/glibtop_server.h +++ b/sysdeps/stub_suid/glibtop_server.h @@ -45,7 +45,7 @@ G_BEGIN_DECLS #define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD) #define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP) -#define GLIBTOP_SUID_PROC_DISKIO (1 << GLIBTOP_SYSDEPS_PROC_DISKIO) +#define GLIBTOP_SUID_PROC_IO (1 << GLIBTOP_SYSDEPS_PROC_IO) G_END_DECLS From 5880e04fccef7c2e9a5f5a688e845bb1dc3b01a9 Mon Sep 17 00:00:00 2001 From: Robert Roth Date: Fri, 12 May 2017 05:14:17 +0300 Subject: [PATCH 09/11] Prepended disk io struct fields with disk_ prefix --- examples/diskio.c | 2 +- include/glibtop/procio.h | 24 ++++++++++++------------ sysdeps/linux/procio.c | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/diskio.c b/examples/diskio.c index 112b4723..de6d775c 100644 --- a/examples/diskio.c +++ b/examples/diskio.c @@ -17,7 +17,7 @@ static void show_diskio(pid_t pid) printf("<%ld>\t", (long)pid); - printf("flags: %08lx rchar : %lu, wchar : %lu, read_bytes : %lu, write_bytes : %lu\n", (unsigned long)io.flags, io.rchar, io.wchar, io.rbytes, io.wbytes); + printf("flags: %08lx disk_rchar : %lu, disk_wchar : %lu, disk_read_bytes : %lu, disk_write_bytes : %lu\n", (unsigned long)io.flags, io.disk_rchar, io.disk_wchar, io.disk_rbytes, io.disk_wbytes); } diff --git a/include/glibtop/procio.h b/include/glibtop/procio.h index 48e2c617..5eb36595 100644 --- a/include/glibtop/procio.h +++ b/include/glibtop/procio.h @@ -27,10 +27,10 @@ G_BEGIN_DECLS -#define GLIBTOP_PROC_IO_RCHAR 0 -#define GLIBTOP_PROC_IO_WCHAR 1 -#define GLIBTOP_PROC_IO_RBYTES 2 -#define GLIBTOP_PROC_IO_WBYTES 3 +#define GLIBTOP_PROC_IO_DISK_RCHAR 0 +#define GLIBTOP_PROC_IO_DISK_WCHAR 1 +#define GLIBTOP_PROC_IO_DISK_RBYTES 2 +#define GLIBTOP_PROC_IO_DISK_WBYTES 3 #define GLIBTOP_MAX_PROC_IO 3 @@ -40,15 +40,15 @@ typedef struct _glibtop_proc_io glibtop_proc_io; /** * glibtop_proc_io: - * @rchar: The number of bytes which this task has caused to be read from storage. This + * @disk_rchar: The number of bytes which this task has caused to be read from storage. This * is simply the sum of bytes which this process passed to read() and pread(), also including tty IO, * and it is unaffected by whether or not actual physical disk IO was required. - * @wchar: The number of bytes which this task has caused, or shall cause to be written + * @disk_wchar: The number of bytes which this task has caused, or shall cause to be written * to disk. Similar caveats apply here as with rchar. - * @rbytes: Attempt to count the number of bytes which this process really did cause to + * @disk_rbytes: Attempt to count the number of bytes which this process really did cause to * be fetched from the storage layer. Done at the submit_bio() level, so it is * accurate for block-backed filesystems. - * @wbytes: Attempt to count the number of bytes which this process caused to be sent to + * @disk_wbytes: Attempt to count the number of bytes which this process caused to be sent to * the storage layer. This is done at page-dirtying time. * * Process disk io data filled by glibtop_get_proc_io(). @@ -59,10 +59,10 @@ struct _glibtop_proc_io /*< private >*/ guint64 flags; /*< public >*/ - guint64 rchar; - guint64 wchar; - guint64 rbytes; - guint64 wbytes; + guint64 disk_rchar; + guint64 disk_wchar; + guint64 disk_rbytes; + guint64 disk_wbytes; }; diff --git a/sysdeps/linux/procio.c b/sysdeps/linux/procio.c index 55a37fe9..2240022f 100644 --- a/sysdeps/linux/procio.c +++ b/sysdeps/linux/procio.c @@ -27,8 +27,8 @@ #include "glibtop_private.h" static const unsigned long _glibtop_sysdeps_proc_io = -(1L << GLIBTOP_PROC_IO_RCHAR) + (1L << GLIBTOP_PROC_IO_WCHAR) + -(1L << GLIBTOP_PROC_IO_RBYTES) + (1L << GLIBTOP_PROC_IO_WBYTES); +(1L << GLIBTOP_PROC_IO_DISK_RCHAR) + (1L << GLIBTOP_PROC_IO_DISK_WCHAR) + +(1L << GLIBTOP_PROC_IO_DISK_RBYTES) + (1L << GLIBTOP_PROC_IO_DISK_WBYTES); /* Init function. */ @@ -53,18 +53,18 @@ glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid) return; p = skip_token (buffer); - buf->rchar = g_ascii_strtoull (p, &p, 10); + buf->disk_rchar = g_ascii_strtoull (p, &p, 10); p = skip_line (p); p = skip_token (p); - buf->wchar = g_ascii_strtoull (p, &p, 10); + buf->disk_wchar = g_ascii_strtoull (p, &p, 10); p = skip_line (p); p = skip_line (p); p = skip_line (p); p = skip_token (p); - buf->rbytes = g_ascii_strtoull (p, &p, 10); + buf->disk_rbytes = g_ascii_strtoull (p, &p, 10); p = skip_line (p); p = skip_token (p); - buf->wbytes = g_ascii_strtoull (p, &p, 10); + buf->disk_wbytes = g_ascii_strtoull (p, &p, 10); buf->flags = _glibtop_sysdeps_proc_io; } From 779386cb15e3dba3642ec378cde9fabbb024a4c1 Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sat, 20 May 2017 11:34:25 +0200 Subject: [PATCH 10/11] Implement disk_rbytes and disk_wbytes for FreeBSD. --- sysdeps/freebsd/procio.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/sysdeps/freebsd/procio.c b/sysdeps/freebsd/procio.c index 27a7a0b3..0525a2a7 100644 --- a/sysdeps/freebsd/procio.c +++ b/sysdeps/freebsd/procio.c @@ -22,8 +22,11 @@ #include #include #include +#include +#include -static const unsigned long _glibtop_sysdeps_proc_io = 0; +static const unsigned long _glibtop_sysdeps_proc_io = + (1UL << GLIBTOP_PROC_IO_DISK_RBYTES) + (1UL << GLIBTOP_PROC_IO_DISK_WBYTES); /* Init function. */ @@ -40,4 +43,38 @@ glibtop_get_proc_io_p (glibtop *server, glibtop_proc_io *buf, pid_t pid) { memset (buf, 0, sizeof (glibtop_proc_io)); + + struct kinfo_proc *pinfo; + int count; + + glibtop_suid_enter (server); + + /* Get the process information */ + pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count); + if ((pinfo == NULL) || (count != 1)) { + glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid); + glibtop_suid_leave (server); + return; + } + + glibtop_suid_leave (server); + + /* man getrusage + + long ru_inblock; == block input operations + long ru_oublock; == block output operations + + ru_inblock the number of times the file system had to perform input. + ru_oublock the number of times the file system had to perform output. + + And then it says 'account only for real IO'. + + But if I write 1MB in a process, I can see ru_oublock increased + 1024. So it's neither a number of operations or times. + + FIXME: seems the blocksize is 1024 but ... + */ + buf->disk_rbytes = pinfo->ki_rusage.ru_inblock << 10; + buf->disk_wbytes = pinfo->ki_rusage.ru_oublock << 10; + buf->flags = _glibtop_sysdeps_proc_io; } From 063de1a7126e0b4d978f51bb7e408c474a8c7755 Mon Sep 17 00:00:00 2001 From: Robert Roth Date: Tue, 23 May 2017 00:02:11 +0300 Subject: [PATCH 11/11] Added reserved fields --- include/glibtop/procio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/glibtop/procio.h b/include/glibtop/procio.h index 5eb36595..86c06e5d 100644 --- a/include/glibtop/procio.h +++ b/include/glibtop/procio.h @@ -63,6 +63,9 @@ struct _glibtop_proc_io guint64 disk_wchar; guint64 disk_rbytes; guint64 disk_wbytes; + + /* reserved for future extensions, e.g. per-process netio */ + guint64 reserved[10]; };