Revert "Revert "Code clean up and add example""
This reverts commit ea08151ae6
.
This commit is contained in:
committed by
Robert Roth
parent
48595809ed
commit
2ec1815e6c
28
autogen.sh
28
autogen.sh
@@ -1,5 +1,33 @@
|
||||
#!/bin/sh
|
||||
# Run this to generate all the initial makefiles, etc.
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
case "$(uname -s)" in
|
||||
Linux)
|
||||
if ! [ -x "$(command -v lsblk)" ]; then
|
||||
echo '' >&2
|
||||
echo -e "${RED}*** ERROR:${NC} lsblk cannot be found. Try installing util-linux or util-linux-ng ${RED}***${NC}" >&2
|
||||
echo '' >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -x "$(command -v sed)" ]; then
|
||||
echo '' >&2
|
||||
echo -e "${RED}*** ERROR:${NC} sed cannot be found. ***" >&2
|
||||
echo '' >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -x "$(command -v tr)" ]; then
|
||||
echo '' >&2
|
||||
echo -e "${RED}*** ERROR:${NC} tr cannot be found. ***" >&2
|
||||
echo '' >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
test -n "$srcdir" || srcdir=$(dirname "$0")
|
||||
test -n "$srcdir" || srcdir=.
|
||||
|
||||
|
10
configure.ac
10
configure.ac
@@ -71,6 +71,16 @@ dnl Most people should have a working perl interpreter on their system
|
||||
AC_CHECK_PROGS(PERL, perl5 perl)
|
||||
test -z "$PERL" && AC_MSG_ERROR([You need to have a working perl interpreter.])
|
||||
|
||||
case "${host_os}" in
|
||||
linux*)
|
||||
AC_CHECK_TOOL(LSBLK,lsblk)
|
||||
AC_CHECK_TOOL(SED,sed)
|
||||
AC_CHECK_TOOL(TR,tr)
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_TOOL(CC,gcc)
|
||||
AC_CHECK_TOOL(RANLIB,ranlib)
|
||||
AC_CHECK_TOOL(AS,as)
|
||||
|
@@ -29,6 +29,7 @@ glibtop_close_p
|
||||
GLIBTOP_CMND_QUIT
|
||||
GLIBTOP_CMND_SYSDEPS
|
||||
GLIBTOP_CMND_CPU
|
||||
GLIBTOP_CMND_DISK
|
||||
GLIBTOP_CMND_MEM
|
||||
GLIBTOP_CMND_SWAP
|
||||
GLIBTOP_CMND_UPTIME
|
||||
@@ -678,6 +679,39 @@ glibtop_init_cpu_s
|
||||
glibtop_get_cpu_s
|
||||
</SECTION>
|
||||
|
||||
<INCLUDE>glibtop/disk.h</INCLUDE>
|
||||
<SECTION>
|
||||
<FILE>disk</FILE>
|
||||
GLIBTOP_DISK_TOTAL
|
||||
GLIBTOP_DISK_USER
|
||||
GLIBTOP_DISK_NICE
|
||||
GLIBTOP_DISK_SYS
|
||||
GLIBTOP_DISK_IDLE
|
||||
GLIBTOP_DISK_FREQUENCY
|
||||
GLIBTOP_XDISK_TOTAL
|
||||
GLIBTOP_XDISK_USER
|
||||
GLIBTOP_XDISK_NICE
|
||||
GLIBTOP_XDISK_SYS
|
||||
GLIBTOP_XDISK_IDLE
|
||||
GLIBTOP_XDISK_FLAGS
|
||||
GLIBTOP_DISK_IOWAIT
|
||||
GLIBTOP_DISK_IRQ
|
||||
GLIBTOP_DISK_SOFTIRQ
|
||||
GLIBTOP_XDISK_IOWAIT
|
||||
GLIBTOP_XDISK_IRQ
|
||||
GLIBTOP_XDISK_SOFTIRQ
|
||||
GLIBTOP_MAX_DISK
|
||||
GLIBTOP_NDISK
|
||||
glibtop_disk
|
||||
glibtop_get_disk
|
||||
glibtop_get_disk_r
|
||||
glibtop_get_disk_l
|
||||
glibtop_init_disk_p
|
||||
glibtop_get_disk_p
|
||||
glibtop_init_disk_s
|
||||
glibtop_get_disk_s
|
||||
</SECTION>
|
||||
|
||||
<INCLUDE>glibtop/swap.h</INCLUDE>
|
||||
<SECTION>
|
||||
<FILE>swap</FILE>
|
||||
|
@@ -34,6 +34,9 @@ mountlist_LDADD = $(top_builddir)/lib/libgtop-2.0.la
|
||||
smp_SOURCES = smp.c
|
||||
smp_LDADD = $(top_builddir)/lib/libgtop-2.0.la -lm
|
||||
|
||||
disk_SOURCES = disk.c
|
||||
disk_LDADD = $(top_builddir)/lib/libgtop-2.0.la -lm
|
||||
|
||||
timings_SOURCES = timings.c
|
||||
timings_LDADD = $(top_builddir)/lib/libgtop-2.0.la
|
||||
|
||||
|
65
examples/disk.c
Normal file
65
examples/disk.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by James Dominic P. Guana <guana.histark@gmail.com>, May 2020.
|
||||
|
||||
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 <locale.h>
|
||||
#include <libintl.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/disk.h>
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{
|
||||
glibtop_disk disk;
|
||||
char separator [BUFSIZ];
|
||||
int ndisk, i;
|
||||
|
||||
glibtop_init();
|
||||
|
||||
glibtop_get_disk (&disk);
|
||||
|
||||
ndisk = glibtop_global_server->ndisk ? glibtop_global_server->ndisk : 1;
|
||||
|
||||
memset (separator, '-', 91);
|
||||
separator [92] = '\0';
|
||||
|
||||
printf("\n\n");
|
||||
printf ("ELAPSE ");
|
||||
printf ("Read Time Read Write Time Write\n");
|
||||
printf ("%s\n", separator);
|
||||
|
||||
for (i = 0; i < ndisk; i++) {
|
||||
printf ("DISK %3d : %12lu %12lu %12lu %12lu\n", i,
|
||||
(unsigned long) disk.xdisk_sectors_read [i],
|
||||
(unsigned long) disk.xdisk_time_read [i],
|
||||
(unsigned long) disk.xdisk_sectors_write [i],
|
||||
(unsigned long) disk.xdisk_time_write [i]);
|
||||
|
||||
}
|
||||
|
||||
printf ("%s\n\n\n", separator);
|
||||
|
||||
exit (0);
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
void|cpu
|
||||
void|disk
|
||||
void|mem
|
||||
void|swap
|
||||
void|uptime
|
||||
|
@@ -2,7 +2,7 @@ glibtopdir = $(includedir)/libgtop-2.0/glibtop
|
||||
|
||||
glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \
|
||||
sem_limits.h uptime.h command.h mem.h proclist.h \
|
||||
proctime.h shm_limits.h cpu.h msg_limits.h \
|
||||
proctime.h shm_limits.h cpu.h disk.h msg_limits.h \
|
||||
procmem.h procuid.h swap.h \
|
||||
procsegment.h sysdeps.h global.h \
|
||||
procsignal.h union.h gnuserv.h \
|
||||
|
@@ -60,8 +60,9 @@ G_BEGIN_DECLS
|
||||
#define GLIBTOP_CMND_PROC_WD 26
|
||||
#define GLIBTOP_CMND_PROC_AFFINITY 27
|
||||
#define GLIBTOP_CMND_PROC_IO 28
|
||||
#define GLIBTOP_CMND_DISK 29
|
||||
|
||||
#define GLIBTOP_MAX_CMND 29
|
||||
#define GLIBTOP_MAX_CMND 30
|
||||
|
||||
#define _GLIBTOP_PARAM_SIZE 16
|
||||
|
||||
|
@@ -46,16 +46,20 @@ struct _partition_info
|
||||
{
|
||||
char name[256];
|
||||
char type[256];
|
||||
char raid_num[256];
|
||||
char raid_num[256];
|
||||
int max;
|
||||
};
|
||||
|
||||
typedef struct _partition_info partition_info;
|
||||
|
||||
struct _glibtop_disk
|
||||
{
|
||||
guint64 flags;
|
||||
guint64 xdisk_sectors_read [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_SECTORS_READ */
|
||||
guint64 xdisk_time_read [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_TIME_READ */
|
||||
guint64 xdisk_sectors_write [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_SECTORS_WRITE */
|
||||
guint64 xdisk_time_write [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_TIME_WRITE */
|
||||
guint64 xdisk_flags;
|
||||
};
|
||||
|
||||
void glibtop_get_disk (glibtop_disk *buf);
|
||||
|
@@ -61,7 +61,7 @@ typedef union _glibtop_union glibtop_union;
|
||||
union _glibtop_union
|
||||
{
|
||||
glibtop_cpu cpu;
|
||||
glibtop_disk disk;
|
||||
glibtop_disk disk;
|
||||
glibtop_mem mem;
|
||||
glibtop_swap swap;
|
||||
glibtop_uptime uptime;
|
||||
|
@@ -139,6 +139,9 @@ const _glibtop_init_func_t _glibtop_init_hook_p [] = {
|
||||
#if GLIBTOP_SUID_CPU
|
||||
_glibtop_init_cpu_p,
|
||||
#endif
|
||||
#if GLIBTOP_SUID_DISK
|
||||
_glibtop_init_disk_p,
|
||||
#endif
|
||||
#if GLIBTOP_SUID_MEM
|
||||
_glibtop_init_mem_p,
|
||||
#endif
|
||||
|
@@ -5,7 +5,7 @@ includedir=@includedir@
|
||||
|
||||
Name: libgtop
|
||||
Description: Portable System Access Library
|
||||
Requires: glib-2.0
|
||||
Requires: glib-2.0, util-linux
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lgtop-2.0
|
||||
Cflags: -I${includedir}/libgtop-2.0
|
||||
|
@@ -5,6 +5,7 @@
|
||||
%define prefix /usr
|
||||
|
||||
Summary: LibGTop library
|
||||
Requires: util-linux, sed
|
||||
Name: libgtop
|
||||
Version: %ver
|
||||
Release: %rel
|
||||
|
@@ -98,7 +98,7 @@ handle_parent_connection (int s)
|
||||
do_output (s, resp, _offset_data (cpu), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_DISK:
|
||||
glibtop_get_disk_l (server, &resp->u.disk.cpu);
|
||||
glibtop_get_disk_l (server, &resp->u.data.disk);
|
||||
do_output (s, resp, _offset_data (disk), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_MEM:
|
||||
|
@@ -135,6 +135,12 @@ handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
|
||||
resp->offset = _offset_data (cpu);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_DISK
|
||||
case GLIBTOP_CMND_DISK:
|
||||
glibtop_get_disk_p (server, &resp->u.data.disk);
|
||||
resp->offset = _offset_data (disk);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_MEM
|
||||
case GLIBTOP_CMND_MEM:
|
||||
glibtop_get_mem_p (server, &resp->u.data.mem);
|
||||
|
@@ -72,9 +72,9 @@ glibtop_get_cpu(glibtop_cpu *buf)
|
||||
*
|
||||
*/
|
||||
void
|
||||
glibtop_get_cpu (glibtop_cpu *buf)
|
||||
glibtop_get_disk (glibtop_disk *buf)
|
||||
{
|
||||
glibtop_get_cpu_l (glibtop_global_server, buf);
|
||||
glibtop_get_disk_l (glibtop_global_server, buf);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -48,7 +48,7 @@ _glibtop_init_disk_s (glibtop *server)
|
||||
// Handle LVM and RAID //
|
||||
|
||||
void
|
||||
find_primary_part (_partition_info *primary_part, const char *m)
|
||||
find_primary_part (partition_info *primary_part, const char *m)
|
||||
{
|
||||
int n = 0, tlvl = 0;
|
||||
char name[256]="",type[256]="";
|
||||
@@ -190,7 +190,7 @@ find_primary_part (_partition_info *primary_part, const char *m)
|
||||
}
|
||||
|
||||
int
|
||||
is_virtual_drive (_partition_info *primary_part, const char *p)
|
||||
is_virtual_drive (partition_info *primary_part, const char *p)
|
||||
{
|
||||
int i;
|
||||
char name[256];
|
||||
@@ -220,10 +220,27 @@ is_virtual_drive (_partition_info *primary_part, const char *p)
|
||||
return test;
|
||||
}
|
||||
|
||||
int
|
||||
max_lines (const char *p)
|
||||
{
|
||||
char temp[10];
|
||||
int count = 0;
|
||||
|
||||
while (sscanf (p, "%s", temp) == 1)
|
||||
{
|
||||
|
||||
p = skip_line(p);
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_get_disk_s (glibtop *server, glibtop_disk *buf)
|
||||
{
|
||||
_partition_info primary_part[GLIBTOP_NDISK];
|
||||
partition_info primary_part[GLIBTOP_NDISK];
|
||||
char buffer [STAT_BUFSIZ], *p, map_buffer [STAT_BUFSIZ], *m;
|
||||
int i;
|
||||
|
||||
@@ -233,8 +250,6 @@ glibtop_get_disk_s (glibtop *server, glibtop_disk *buf)
|
||||
|
||||
get_from_pipe (map_buffer, CMD_PIPE);
|
||||
|
||||
server->ndisk = GLIBTOP_NDISK;
|
||||
|
||||
/*
|
||||
* GLOBAL
|
||||
*/
|
||||
@@ -246,23 +261,23 @@ glibtop_get_disk_s (glibtop *server, glibtop_disk *buf)
|
||||
* PER DISK
|
||||
*/
|
||||
|
||||
server->ndisk = max_lines(p);
|
||||
|
||||
find_primary_part (primary_part, m);
|
||||
|
||||
for (i = 0; i <= server->ndisk; i++) {
|
||||
for (i = 0; i < server->ndisk; i++) {
|
||||
|
||||
p = skip_multiple_token (p,2);
|
||||
|
||||
// skip if disk is the raw device
|
||||
if (!is_virtual_drive (primary_part, p)) {
|
||||
|
||||
server->ndisk--;
|
||||
p = skip_line (p); /* move to ^ */
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
}
|
||||
|
||||
if (!check_disk_line_warn (server, p, i))
|
||||
break;
|
||||
|
||||
p = skip_token (p); /* prev xdisk_name */
|
||||
p = skip_token (p); /* prev xdisk_reads_completed */
|
||||
p = skip_token (p); /* prev xdisk_reads_merged */
|
||||
|
@@ -62,7 +62,7 @@ skip_line (const char *p)
|
||||
}
|
||||
|
||||
void
|
||||
get_from_pipe (char *buffer, const char *cmd)
|
||||
get_from_pipe (char *buffer, const char *cmd);
|
||||
|
||||
/*
|
||||
* Smart strtoul which handles binary suffixes
|
||||
|
@@ -3,7 +3,7 @@ AM_CPPFLAGS = @AM_CPPFLAGS@
|
||||
|
||||
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la
|
||||
|
||||
libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
|
||||
libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c disk.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
|
@@ -7,7 +7,7 @@ libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c
|
||||
|
||||
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
|
||||
libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c siglist.c cpu.c disk.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
|
47
sysdeps/stub_suid/disk.c
Normal file
47
sysdeps/stub_suid/disk.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
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/disk.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_disk = 0;
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_disk_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.disk = _glibtop_sysdeps_disk;
|
||||
}
|
||||
|
||||
/* Provides information about disk usage. */
|
||||
|
||||
void
|
||||
glibtop_get_disk_p (glibtop *server, glibtop_disk *buf)
|
||||
{
|
||||
glibtop_init_p (server, GLIBTOP_SYSDEPS_DISK, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_disk));
|
||||
}
|
Reference in New Issue
Block a user