Compare commits

...

16 Commits

Author SHA1 Message Date
Robert Roth
063de1a712 Added reserved fields 2017-05-23 00:02:11 +03:00
Benoit Dejean
779386cb15 Implement disk_rbytes and disk_wbytes for FreeBSD. 2017-05-20 11:34:25 +02:00
Robert Roth
5880e04fcc Prepended disk io struct fields with disk_ prefix 2017-05-12 05:14:17 +03:00
Robert Roth
1bf16bfffd Renamed procdiskio to procio 2017-05-12 05:08:41 +03:00
Benoit Dejean
c29d7de9a0 Add dummy proc_diskio implementation for FreeBSD. 2017-02-25 16:30:18 +01:00
Benoit Dejean
07abbd2dfe Add slave proc_diskio handler. 2017-02-25 16:29:26 +01:00
Benoît Dejean
afec9bbf58 Add proc_diskio in sysdeps and timings tests. 2017-02-24 09:04:23 +01:00
Benoît Dejean
b7a684fbbc Also display the flags value. 2017-02-24 09:04:06 +01:00
Benoît Dejean
b589a4fcf0 Fix GLIBTOP_MAX variable name for diskio. 2017-02-21 13:01:04 +01:00
Benoît Dejean
1defc74f07 Set glibtop_proc_diskio.flags.
Check linux version code before reading /proc/PID/io.
2017-02-21 12:50:37 +01:00
Robert Roth
dff7c5588e New API to retrieve process io stats, with Linux implementation 2017-02-12 17:59:08 +02:00
Benoît Dejean
1a103bf142 When parsing /proc/cpuinfo, ignore paragraphs that do not describe a CPU/core. 2017-01-28 09:39:43 +01:00
Benoît Dejean
3ff313dd03 Update git ignore list. 2017-01-22 10:56:59 +01:00
Benoît Dejean
01a56e2e30 Use g_ascii_isspace instead of isspace because the later is slower and we
only need to deal with ascii.
2017-01-22 10:45:26 +01:00
Benoît Dejean
7afc81f99d Do not cache getpagesize(), it is already. 2017-01-22 10:45:26 +01:00
Benoît Dejean
b0ab056e99 Use a dynamically allocated buffer to read /proc/cpuinfo to handle computers
with a lot of CPUs.

https://bugzilla.gnome.org/show_bug.cgi?id=323354
2017-01-22 10:45:26 +01:00
32 changed files with 475 additions and 65 deletions

65
.gitignore vendored
View File

@@ -1,45 +1,38 @@
*~ *.a
*.bak *.bak
*.core
*.diff
*.gmo
*.header
*.in
*.la
*.lo
*.o *.o
*.out *.out
*.a *.patch
*.gmo *.pot
*.lo
*.la
*.core
*.s *.s
*.sed
*.sin
*.stamp *.stamp
.libs *.swp
*~
.deps .deps
Makefile .libs
Makefile.in ABOUT-NLS
src/daemon/libgtop_daemon2
src/daemon/libgtop_server2
stamp-h1
po/stamp-it
po/POTFILES
po/Makefile.in.in
missing
m4/
ltmain.sh
libtool
libgtopconfig.h
libgtop.spec
libgtop-2.0.pc
lib/lib.c
lib/GTop-2.0.gir
lib/GTop-2.0.typelib
INSTALL INSTALL
Makefile
Makevars.template
Rules-quot
aclocal.m4 aclocal.m4
autom4te.cache/ autom4te.cache/
compile
config.guess config.guess
config.h config.h
config.h.in
config.log config.log
config.status config.status
config.sub config.sub
configure configure
compile
depcomp depcomp
doc/libgtop2.info doc/libgtop2.info
doc/mdate-sh doc/mdate-sh
@@ -77,5 +70,23 @@ examples/smp
examples/sysdeps examples/sysdeps
examples/timings examples/timings
examples/wd examples/wd
examples/diskio
gtk-doc.make gtk-doc.make
install-sh install-sh
lib/GTop-2.0.gir
lib/GTop-2.0.typelib
lib/lib.c
libgtop-2.0.pc
libgtop.spec
libgtopconfig.h
libtool
ltmain.sh
m4/
missing
po/POTFILES
po/stamp-it
src/daemon/libgtop_daemon2
src/daemon/libgtop_server2
stamp-h1
stamp-po
tmp-*

View File

@@ -11,7 +11,7 @@ AM_LDFLAGS = $(LIBGTOP_EXTRA_LIBS)
noinst_PROGRAMS = first second pprint procargs df netlist \ noinst_PROGRAMS = first second pprint procargs df netlist \
mountlist procmap netload sysdeps timings \ mountlist procmap netload sysdeps timings \
openfiles smp proclist free wd affinity openfiles smp proclist free wd affinity diskio
first_SOURCES = first.c first_SOURCES = first.c
first_LDADD = $(top_builddir)/lib/libgtop-2.0.la 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_SOURCES = procargs.c
procargs_LDADD = $(top_builddir)/lib/libgtop-2.0.la procargs_LDADD = $(top_builddir)/lib/libgtop-2.0.la
df_SOURCES = df.c df_SOURCES = df.c
df_LDADD = $(top_builddir)/lib/libgtop-2.0.la 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_SOURCES = affinity.c
affinity_LDADD = $(top_builddir)/lib/libgtop-2.0.la affinity_LDADD = $(top_builddir)/lib/libgtop-2.0.la
diskio_SOURCES = diskio.c
diskio_LDADD = $(top_builddir)/lib/libgtop-2.0.la

39
examples/diskio.c Normal file
View File

@@ -0,0 +1,39 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glibtop.h>
#include <glibtop/procio.h>
#include <stdlib.h>
#include <unistd.h>
static void show_diskio(pid_t pid)
{
glibtop_proc_io io;
glibtop_get_proc_io (&io, pid);
printf("<%ld>\t", (long)pid);
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);
}
int main(int argc, char **argv)
{
glibtop_init();
while(*++argv)
{
pid_t pid = strtol(*argv, NULL, 10);
show_diskio(pid);
}
glibtop_close();
return 0;
}

View File

@@ -92,9 +92,10 @@ main (int argc, char *argv [])
"\tproc_time:\t%d\t0x%08lx\n" "\tproc_time:\t%d\t0x%08lx\n"
"\tproc_signal:\t%d\t0x%08lx\n" "\tproc_signal:\t%d\t0x%08lx\n"
"\tproc_kernel:\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_args:\t%d\t0x%08lx\n"
"\tproc_map:\t%d\t0x%08lx\n\n" "\tproc_map:\t%d\t0x%08lx\n"
"\tproc_io:\t%d\t0x%08lx\n\n"
"\tmountlist:\t%d\t0x%08lx\n" "\tmountlist:\t%d\t0x%08lx\n"
"\tfsusage:\t%d\t0x%08lx\n\n" "\tfsusage:\t%d\t0x%08lx\n\n"
"\tnetload:\t%d\t0x%08lx\n" "\tnetload:\t%d\t0x%08lx\n"
@@ -137,6 +138,8 @@ main (int argc, char *argv [])
(unsigned long) sysdeps.proc_args, (unsigned long) sysdeps.proc_args,
FEATURE_CHECK(PROC_MAP), FEATURE_CHECK(PROC_MAP),
(unsigned long) sysdeps.proc_map, (unsigned long) sysdeps.proc_map,
FEATURE_CHECK(PROC_IO),
(unsigned long) sysdeps.proc_io,
FEATURE_CHECK(MOUNTLIST), FEATURE_CHECK(MOUNTLIST),
(unsigned long) sysdeps.mountlist, (unsigned long) sysdeps.mountlist,
FEATURE_CHECK(FSUSAGE), FEATURE_CHECK(FSUSAGE),

View File

@@ -412,6 +412,26 @@ main (int argc, char *argv [])
(long double) ELAPSED_UTIME / PROFILE_COUNT, (long double) ELAPSED_UTIME / PROFILE_COUNT,
(long double) ELAPSED_STIME / PROFILE_COUNT); (long double) ELAPSED_STIME / PROFILE_COUNT);
getrusage (RUSAGE_SELF, &rusage_start);
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_io (&data.proc_io, 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_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);
getrusage (RUSAGE_SELF, &total_end); getrusage (RUSAGE_SELF, &total_end);
libgtop_timersub (&total_end.ru_utime, &total_start.ru_utime, libgtop_timersub (&total_end.ru_utime, &total_start.ru_utime,

View File

@@ -24,4 +24,5 @@ void|ppp|ushort(device)
char **|netlist char **|netlist
char **|proc_wd|pid_t(pid) char **|proc_wd|pid_t(pid)
guint16*|proc_affinity|pid_t(pid) guint16*|proc_affinity|pid_t(pid)
void|proc_io|pid_t(pid)

View File

@@ -9,6 +9,7 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \
parameter.h mountlist.h fsusage.h procmap.h signal.h \ parameter.h mountlist.h fsusage.h procmap.h signal.h \
sysinfo.h ppp.h procargs.h netload.h \ sysinfo.h ppp.h procargs.h netload.h \
procwd.h procaffinity.h \ procwd.h procaffinity.h \
procio.h \
netlist.h procopenfiles.h open.h netlist.h procopenfiles.h open.h
noinst_HEADERS = error.h write.h read_data.h read.h init_hooks.h machine.h \ noinst_HEADERS = error.h write.h read_data.h read.h init_hooks.h machine.h \

View File

@@ -59,8 +59,9 @@ G_BEGIN_DECLS
#define GLIBTOP_CMND_PROC_OPEN_FILES 25 #define GLIBTOP_CMND_PROC_OPEN_FILES 25
#define GLIBTOP_CMND_PROC_WD 26 #define GLIBTOP_CMND_PROC_WD 26
#define GLIBTOP_CMND_PROC_AFFINITY 27 #define GLIBTOP_CMND_PROC_AFFINITY 27
#define GLIBTOP_CMND_PROC_IO 28
#define GLIBTOP_MAX_CMND 28 #define GLIBTOP_MAX_CMND 29
#define _GLIBTOP_PARAM_SIZE 16 #define _GLIBTOP_PARAM_SIZE 16

93
include/glibtop/procio.h Normal file
View File

@@ -0,0 +1,93 @@
/* Copyright (C) 2017 Robert Roth
This file is part of LibGTop.
Contributed by Robert Roth <robert.roth.off@gmail.com>, 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_PROCIO_H__
#define __GLIBTOP_PROCIO_H__
#include <glibtop.h>
#include <glibtop/global.h>
G_BEGIN_DECLS
#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
typedef struct _glibtop_proc_io glibtop_proc_io;
/* Time section */
/**
* glibtop_proc_io:
* @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.
* @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.
* @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.
* @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().
*
*/
struct _glibtop_proc_io
{
/*< private >*/
guint64 flags;
/*< public >*/
guint64 disk_rchar;
guint64 disk_wchar;
guint64 disk_rbytes;
guint64 disk_wbytes;
/* reserved for future extensions, e.g. per-process netio */
guint64 reserved[10];
};
void glibtop_get_proc_io (glibtop_proc_io *buf, pid_t pid);
#if GLIBTOP_SUID_PROC_IO
#define glibtop_get_proc_io_r glibtop_get_proc_io_p
#else
#define glibtop_get_proc_io_r glibtop_get_proc_io_s
#endif
void glibtop_get_proc_io_l (glibtop *server, glibtop_proc_io *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_io_s (glibtop *server);
void glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid);
#endif
G_END_DECLS
#endif

View File

@@ -53,8 +53,9 @@ G_BEGIN_DECLS
#define GLIBTOP_SYSDEPS_PROC_OPEN_FILES 24 #define GLIBTOP_SYSDEPS_PROC_OPEN_FILES 24
#define GLIBTOP_SYSDEPS_PROC_WD 25 #define GLIBTOP_SYSDEPS_PROC_WD 25
#define GLIBTOP_SYSDEPS_PROC_AFFINITY 26 #define GLIBTOP_SYSDEPS_PROC_AFFINITY 26
#define GLIBTOP_SYSDEPS_PROC_IO 27
#define GLIBTOP_MAX_SYSDEPS 27 #define GLIBTOP_MAX_SYSDEPS 28
/* The 'features' args to glibtop_init_* is an unsigned long */ /* The 'features' args to glibtop_init_* is an unsigned long */
G_STATIC_ASSERT((1UL << (GLIBTOP_MAX_SYSDEPS - 1)) <= ULONG_MAX); G_STATIC_ASSERT((1UL << (GLIBTOP_MAX_SYSDEPS - 1)) <= ULONG_MAX);
@@ -93,6 +94,7 @@ struct _glibtop_sysdeps
guint64 ppp; /* glibtop_ppp */ guint64 ppp; /* glibtop_ppp */
guint64 proc_wd; /* glibtop_proc_wd */ guint64 proc_wd; /* glibtop_proc_wd */
guint64 proc_affinity; /* glibtop_proc_affinity */ guint64 proc_affinity; /* glibtop_proc_affinity */
guint64 proc_io; /* glibtop_proc_io */
}; };
void glibtop_get_sysdeps (glibtop_sysdeps *buf); void glibtop_get_sysdeps (glibtop_sysdeps *buf);

View File

@@ -44,6 +44,7 @@
#include <glibtop/procopenfiles.h> #include <glibtop/procopenfiles.h>
#include <glibtop/procwd.h> #include <glibtop/procwd.h>
#include <glibtop/procaffinity.h> #include <glibtop/procaffinity.h>
#include <glibtop/procio.h>
#include <glibtop/mountlist.h> #include <glibtop/mountlist.h>
#include <glibtop/fsusage.h> #include <glibtop/fsusage.h>
@@ -84,6 +85,7 @@ union _glibtop_union
glibtop_proc_open_files proc_open_files; glibtop_proc_open_files proc_open_files;
glibtop_proc_wd proc_wd; glibtop_proc_wd proc_wd;
glibtop_proc_affinity proc_affinity; glibtop_proc_affinity proc_affinity;
glibtop_proc_io proc_io;
}; };
G_END_DECLS G_END_DECLS

View File

@@ -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/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/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/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/procio.h \
../include/glibtop/netlist.h ../include/glibtop/procopenfiles.h ../include/glibtop/open.h ../include/glibtop/netlist.h ../include/glibtop/procopenfiles.h ../include/glibtop/open.h
GTop-2.0.gir: libgtop-2.0.la GTop-2.0.gir: libgtop-2.0.la

View File

@@ -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_OPEN_FILES);
CHECK_CMND(GLIBTOP_CMND_PROC_WD); CHECK_CMND(GLIBTOP_CMND_PROC_WD);
CHECK_CMND(GLIBTOP_CMND_PROC_AFFINITY); CHECK_CMND(GLIBTOP_CMND_PROC_AFFINITY);
CHECK_CMND(GLIBTOP_CMND_PROC_IO);
default: default:
glibtop_error_r(server, "CALL: command UNKNOWN(%d) sending %lu bytes", command, (unsigned long)send_size); break; glibtop_error_r(server, "CALL: command UNKNOWN(%d) sending %lu bytes", command, (unsigned long)send_size); break;
} }

View File

@@ -52,6 +52,8 @@ glibtop_get_shm_limits
glibtop_get_shm_limits_l glibtop_get_shm_limits_l
glibtop_get_proc_affinity glibtop_get_proc_affinity
glibtop_get_proc_affinity_l glibtop_get_proc_affinity_l
glibtop_get_proc_io
glibtop_get_proc_io_l
glibtop_get_swap glibtop_get_swap
glibtop_get_swap_l glibtop_get_swap_l
glibtop_get_sysdeps glibtop_get_sysdeps

View File

@@ -48,7 +48,8 @@ GLIBTOP_SUID_NETLOAD +
GLIBTOP_SUID_NETLIST + GLIBTOP_SUID_NETLIST +
GLIBTOP_SUID_PROC_WD + GLIBTOP_SUID_PROC_WD +
GLIBTOP_SUID_PROC_AFFINITY + GLIBTOP_SUID_PROC_AFFINITY +
GLIBTOP_SUID_PPP; GLIBTOP_SUID_PPP +
GLIBTOP_SUID_PROC_IO;
const _glibtop_init_func_t _glibtop_init_hook_s [] = { const _glibtop_init_func_t _glibtop_init_hook_s [] = {
#if !GLIBTOP_SUID_CPU #if !GLIBTOP_SUID_CPU
@@ -119,6 +120,9 @@ const _glibtop_init_func_t _glibtop_init_hook_s [] = {
#endif #endif
#if !GLIBTOP_SUID_PPP #if !GLIBTOP_SUID_PPP
_glibtop_init_ppp_s, _glibtop_init_ppp_s,
#endif
#if !GLIBTOP_SUID_PROC_IO
_glibtop_init_proc_io_s,
#endif #endif
NULL NULL
}; };
@@ -192,6 +196,9 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = {
#endif #endif
#if GLIBTOP_SUID_PPP #if GLIBTOP_SUID_PPP
_glibtop_init_ppp_p, _glibtop_init_ppp_p,
#endif
#if GLIBTOP_SUID_PROC_IO
_glibtop_init_proc_io_p,
#endif #endif
NULL NULL
}; };

View File

@@ -221,6 +221,12 @@ handle_parent_connection (int s)
do_output (s, resp, _offset_data (fsusage), do_output (s, resp, _offset_data (fsusage),
0, NULL); 0, NULL);
break; break;
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: case GLIBTOP_CMND_PPP:
memcpy (&device, parameter, sizeof (device)); memcpy (&device, parameter, sizeof (device));
glibtop_get_ppp_l glibtop_get_ppp_l

View File

@@ -209,6 +209,14 @@ handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
resp->offset = _offset_data (proc_time); resp->offset = _offset_data (proc_time);
break; break;
#endif #endif
#if GLIBTOP_SUID_PROC_IO
case GLIBTOP_CMND_PROC_IO:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_io_p
(server, &resp->u.data.proc_io, pid);
resp->offset = _offset_data (proc_time);
break;
#endif
#if GLIBTOP_SUID_PROC_SIGNAL #if GLIBTOP_SUID_PROC_SIGNAL
case GLIBTOP_CMND_PROC_SIGNAL: case GLIBTOP_CMND_PROC_SIGNAL:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));

View File

@@ -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); return glibtop_get_proc_affinity_l(glibtop_global_server, buf, 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
*
* Get the io stats for a process
*
* Returns: A list of processor ID of 'buf.number' elements.
*/
void
glibtop_get_proc_io(glibtop_proc_io *buf, pid_t pid)
{
return glibtop_get_proc_io_l(glibtop_global_server, buf, pid);
}

View File

@@ -89,6 +89,9 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = {
#endif #endif
#if GLIBTOP_SUID_PPP #if GLIBTOP_SUID_PPP
_glibtop_init_ppp_p, _glibtop_init_ppp_p,
#endif
#if GLIBTOP_SUID_PROC_IO
_glibtop_init_proc_io_p,
#endif #endif
NULL NULL
}; };

View File

@@ -16,6 +16,7 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = suid_open.c close.c swap.c \
proclist.c procstate.c procuid.c \ proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c \ proctime.c procmem.c procsignal.c \
prockernel.c procsegment.c procargs.c \ prockernel.c procsegment.c procargs.c \
procio.c \
procmap.c netload.c ppp.c procmap.c netload.c ppp.c
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO) libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)

View File

@@ -47,6 +47,7 @@ G_BEGIN_DECLS
#define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PROC_WD 0 #define GLIBTOP_SUID_PROC_WD 0
#define GLIBTOP_SUID_PROC_AFFINITY 0 #define GLIBTOP_SUID_PROC_AFFINITY 0
#define GLIBTOP_SUID_PROC_IO (1 << GLIBTOP_SYSDEPS_PROC_IO)
G_END_DECLS G_END_DECLS

80
sysdeps/freebsd/procio.c Normal file
View File

@@ -0,0 +1,80 @@
/* Copyright (C) 2017 Robert Roth
This file is part of LibGTop.
Contributed by Robert Roth <robert.roth.off@gmail.com>, 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 <config.h>
#include <glibtop.h>
#include <glibtop/procio.h>
#include <glibtop/error.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_io =
(1UL << GLIBTOP_PROC_IO_DISK_RBYTES) + (1UL << GLIBTOP_PROC_IO_DISK_WBYTES);
/* Init function. */
void
_glibtop_init_proc_io_p (glibtop *server)
{
server->sysdeps.proc_io = _glibtop_sysdeps_proc_io;
}
/* Provides detailed information about a process. */
void
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;
}

View File

@@ -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 \ proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procargs.c procmap.c siglist.c \ procsegment.c procargs.c procmap.c siglist.c \
sysinfo.c netload.c ppp.c glibtop_private.c \ sysinfo.c netload.c ppp.c glibtop_private.c \
mountlist.c procaffinity.c \ mountlist.c procaffinity.c procio.c \
fsusage.c netlist.c procopenfiles.c procwd.c fsusage.c netlist.c procopenfiles.c procwd.c
libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@ libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@

View File

@@ -51,7 +51,7 @@ char *
skip_token (const char *p) skip_token (const char *p)
{ {
p = next_token(p); p = next_token(p);
while (*p && !isspace(*p)) p++; while (*p && !g_ascii_isspace(*p)) p++;
p = next_token(p); p = next_token(p);
return (char *)p; return (char *)p;
} }
@@ -178,20 +178,6 @@ get_boot_time(glibtop *server)
} }
size_t
get_page_size(void)
{
static size_t pagesize = 0;
if(G_UNLIKELY(!pagesize))
{
pagesize = getpagesize();
}
return pagesize;
}
gboolean gboolean
check_cpu_line(glibtop *server, const char *line, unsigned i) check_cpu_line(glibtop *server, const char *line, unsigned i)

View File

@@ -37,7 +37,7 @@ G_BEGIN_DECLS
static inline char* static inline char*
next_token(const char *p) next_token(const char *p)
{ {
while (isspace(*p)) p++; while (g_ascii_isspace(*p)) p++;
return (char*) p; return (char*) p;
} }
@@ -122,10 +122,6 @@ unsigned long
get_boot_time(glibtop *server); get_boot_time(glibtop *server);
size_t
get_page_size(void);
gboolean gboolean
check_cpu_line(glibtop *server, const char *line, unsigned n); check_cpu_line(glibtop *server, const char *line, unsigned n);

View File

@@ -46,5 +46,6 @@
#define GLIBTOP_SUID_PROC_AFFINITY 0 #define GLIBTOP_SUID_PROC_AFFINITY 0
#define GLIBTOP_SUID_PPP 0 #define GLIBTOP_SUID_PPP 0
#define GLIBTOP_SUID_PROC_FILE 0 #define GLIBTOP_SUID_PROC_FILE 0
#define GLIBTOP_SUID_PROC_IO 0
#endif /* __LINUX__GLIBTOP_SERVER_H__ */ #endif /* __LINUX__GLIBTOP_SERVER_H__ */

70
sysdeps/linux/procio.c Normal file
View File

@@ -0,0 +1,70 @@
/* Copyright (C) 2017 Robert Roth
This file is part of LibGTop.
Contributed by Robert Roth <robert.roth.off@gmail.com>, 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 <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procio.h>
#include "glibtop_private.h"
static const unsigned long _glibtop_sysdeps_proc_io =
(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. */
void
_glibtop_init_proc_io_s (glibtop *server)
{
server->sysdeps.proc_io = _glibtop_sysdeps_proc_io;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
memset (buf, 0, sizeof (glibtop_proc_io));
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;
p = skip_token (buffer);
buf->disk_rchar = g_ascii_strtoull (p, &p, 10);
p = skip_line (p);
p = skip_token (p);
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->disk_rbytes = g_ascii_strtoull (p, &p, 10);
p = skip_line (p);
p = skip_token (p);
buf->disk_wbytes = g_ascii_strtoull (p, &p, 10);
buf->flags = _glibtop_sysdeps_proc_io;
}

View File

@@ -82,7 +82,7 @@ void
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid) glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{ {
char buffer [BUFSIZ], *p; char buffer [BUFSIZ], *p;
const size_t pagesize = get_page_size(); const size_t pagesize = getpagesize();
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -53,7 +53,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid) pid_t pid)
{ {
char buffer [BUFSIZ], *p; char buffer [BUFSIZ], *p;
const size_t pagesize = get_page_size(); const size_t pagesize = getpagesize();
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));

View File

@@ -36,23 +36,34 @@ static glibtop_sysinfo sysinfo = { .flags = 0 };
static void static void
init_sysinfo (glibtop *server) init_sysinfo (glibtop *server)
{ {
char buffer [65536]; char* buffer;
gchar ** processors; gchar ** processors;
if(G_LIKELY(sysinfo.flags)) return; if(G_LIKELY(sysinfo.flags)) return;
file_to_buffer(server, buffer, sizeof buffer, FILENAME); if (!g_file_get_contents(FILENAME, &buffer, NULL, NULL)) {
glibtop_error_io_r(server, "g_file_get_contents(%s)", FILENAME);
}
/* cpuinfo records are seperated by a blank line */ /* cpuinfo records are seperated by a blank line */
processors = g_strsplit(buffer, "\n\n", 0); processors = g_strsplit(buffer, "\n\n", 0);
for(sysinfo.ncpu = 0; g_free(buffer);
sysinfo.ncpu < GLIBTOP_NCPU && processors[sysinfo.ncpu] && *processors[sysinfo.ncpu];
sysinfo.ncpu++) { sysinfo.ncpu = 0;
for (char** this_proc = &processors[0]; *this_proc && **this_proc; this_proc++) {
if (sysinfo.ncpu >= GLIBTOP_NCPU) {
glibtop_warn_r(server, "Cannot deal with more than %d CPUs", GLIBTOP_NCPU);
break;
}
gchar **parts, **p; gchar **parts, **p;
if (g_strrstr (processors[sysinfo.ncpu], "processor" ) == NULL) if (g_strrstr (*this_proc, "processor" ) == NULL) {
continue; /* skip unknown paragraph */
continue;
}
glibtop_entry * const cpuinfo = &sysinfo.cpuinfo[sysinfo.ncpu]; glibtop_entry * const cpuinfo = &sysinfo.cpuinfo[sysinfo.ncpu];
cpuinfo->labels = g_ptr_array_new (); cpuinfo->labels = g_ptr_array_new ();
@@ -64,7 +75,7 @@ init_sysinfo (glibtop *server)
g_free, g_free); g_free, g_free);
/* "<key> : <value>" */ /* "<key> : <value>" */
parts = g_strsplit_set(processors[sysinfo.ncpu], ":\n", 0); parts = g_strsplit_set(*this_proc, ":\n", 0);
for(p = parts; *p && *(p+1); p += 2) { for(p = parts; *p && *(p+1); p += 2) {
@@ -85,6 +96,7 @@ init_sysinfo (glibtop *server)
g_free(parts); g_free(parts);
sysinfo.ncpu++;
} }
g_strfreev(processors); g_strfreev(processors);

43
sysdeps/stub/procio.c Normal file
View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2017 Robert Roth
This file is part of LibGTop.
Contributed by Robert Roth <robert.roth.off@gmail.com>, 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 <config.h>
#include <glibtop.h>
#include <glibtop/procio.h>
static const unsigned long _glibtop_sysdeps_proc_io = 0;
/* Init function. */
void
_glibtop_init_proc_io_s (glibtop *server)
{
server->sysdeps.proc_io = _glibtop_sysdeps_proc_io;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_io));
}

View File

@@ -45,6 +45,7 @@ G_BEGIN_DECLS
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD) #define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
#define GLIBTOP_SUID_NETLIST 0 #define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP) #define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
#define GLIBTOP_SUID_PROC_IO (1 << GLIBTOP_SYSDEPS_PROC_IO)
G_END_DECLS G_END_DECLS