New API to retrieve process io stats, with Linux implementation

This commit is contained in:
Robert Roth
2017-02-12 17:59:08 +02:00
parent 1a103bf142
commit dff7c5588e
21 changed files with 292 additions and 6 deletions

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);
}
/**
* 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);
}

View File

@@ -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
};

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 \
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@

View File

@@ -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__ */

View File

@@ -0,0 +1,66 @@
/* 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/procdiskio.h>
#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);
}

43
sysdeps/stub/procdiskio.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/procdiskio.h>
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));
}

View File

@@ -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