1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-02-04 11:23:46 +00:00

Add support for getting disk read/write usage on -CURRENT using GEOM

and devstat.  Thanks to phk for providing insight on how to do this.

Tested by:	kwm
This commit is contained in:
Joe Marcus Clarke 2005-06-10 03:17:18 +00:00
parent 313e16c3ab
commit a090e304e4
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=137140
4 changed files with 159 additions and 2 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= libgtop2
PORTVERSION= 2.10.1
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= devel gnome
MASTER_SITES= ${MASTER_SITE_GNOME}
MASTER_SITE_SUBDIR= sources/${PORTNAME:S/2$//}/2.10
@ -32,6 +32,13 @@ CONFIGURE_ENV= CPPFLAGS="-I${LOCALBASE}/include" \
INFO= libgtop2
.include <bsd.port.pre.mk>
.if ${OSVERSION} >= 600000
PKGMESSAGE= ${FILESDIR}/pkg-message
EXTRA_PATCHES+= ${FILESDIR}/extra-patch-sysdeps_freebsd_Makefile.in
.endif
post-patch:
@${REINPLACE_CMD} -e 's|int64_t|gint64|g' \
${WRKSRC}/include/glibtop/command.h \
@ -41,5 +48,8 @@ post-patch:
post-install:
@${CHGRP} kmem ${PREFIX}/bin/libgtop_server2
@${CHMOD} 2555 ${PREFIX}/bin/libgtop_server2
.if ${OSVERSION} >= 600000
@${CAT} ${PKGMESSAGE}
.endif
.include <bsd.port.mk>
.include <bsd.port.post.mk>

View File

@ -0,0 +1,11 @@
--- sysdeps/freebsd/Makefile.in.orig Thu May 12 15:12:13 2005
+++ sysdeps/freebsd/Makefile.in Thu May 12 15:22:01 2005
@@ -175,7 +175,7 @@
X_PRE_LIBS = @X_PRE_LIBS@
libgtop_sysdeps_2_0_la_LIBADD =
libgtop_sysdeps_2_0_la_OBJECTS = nosuid.lo siglist.lo
-libgtop_sysdeps_suid_2_0_la_LIBADD =
+libgtop_sysdeps_suid_2_0_la_LIBADD = -lgeom -ldevstat
libgtop_sysdeps_suid_2_0_la_OBJECTS = open.lo close.lo cpu.lo mem.lo \
swap.lo uptime.lo loadavg.lo shm_limits.lo msg_limits.lo sem_limits.lo \
proclist.lo procstate.lo procuid.lo proctime.lo procmem.lo \

View File

@ -0,0 +1,123 @@
--- sysdeps/freebsd/fsusage.c.orig Mon Feb 28 03:54:41 2005
+++ sysdeps/freebsd/fsusage.c Tue May 24 01:49:42 2005
@@ -9,6 +9,12 @@
#include <unistd.h>
#include <sys/param.h>
#include <sys/mount.h>
+#if __FreeBSD_version >= 600000
+#include <libgeom.h>
+#include <sys/resource.h>
+#include <devstat.h>
+#include <sys/devicestat.h>
+#endif
#include <stdio.h>
#include <string.h>
@@ -27,15 +33,107 @@ _glibtop_freebsd_get_fsusage_read_write(
{
int result;
struct statfs sfs;
+#if __FreeBSD_version >= 600000
+ struct devstat *ds;
+ void *sc;
+ struct timespec ts;
+ struct gprovider *gp;
+ struct gident *gid;
+ struct gmesh gmp;
+ double etime;
+ uint64_t ld[2];
+#endif
result = statfs (path, &sfs);
if (result == -1) {
+ glibtop_warn_io_r (server, "statfs");
return;
}
+#if __FreeBSD_version >= 600000
+ ld[0] = 0;
+ ld[1] = 0;
+ result = geom_gettree (&gmp);
+ if (result != 0) {
+ glibtop_warn_io_r (server, "geom_gettree = %d", result);
+ return;
+ }
+
+ result = geom_stats_open ();
+ if (result) {
+ glibtop_warn_io_r (server, "geom_stats_open()");
+ geom_deletetree (&gmp);
+ return;
+ }
+
+ sc = geom_stats_snapshot_get ();
+ if (sc == NULL) {
+ glibtop_warn_io_r (server, "geom_stats_snapshot_get()");
+ geom_stats_close ();
+ geom_deletetree (&gmp);
+ return;
+ }
+
+ geom_stats_snapshot_timestamp (sc, &ts);
+ etime = ts.tv_sec + (ts.tv_nsec * 1e-9);
+ geom_stats_snapshot_reset (sc);
+
+ for (;;) {
+ ds = geom_stats_snapshot_next (sc);
+ if (ds == NULL) {
+ break;
+ }
+ if (ds->id == NULL) {
+ continue;
+ }
+
+ gid = geom_lookupid (&gmp, ds->id);
+ if (gid == NULL) {
+ geom_deletetree (&gmp);
+ result = geom_gettree (&gmp);
+ gid = geom_lookupid (&gmp, ds->id);
+ }
+
+ if (gid == NULL) {
+ continue;
+ }
+ if (gid->lg_what == ISCONSUMER) {
+ continue;
+ }
+
+ gp = gid->lg_ptr;
+
+ if (!g_str_has_suffix (sfs.f_mntfromname, gp->lg_name)) {
+ continue;
+ }
+ else {
+ result = devstat_compute_statistics (ds, NULL, etime,
+ DSM_TOTAL_TRANSFERS_READ,
+ &ld[0],
+ DSM_TOTAL_TRANSFERS_WRITE,
+ &ld[1], DSM_NONE);
+ if (result != 0) {
+ glibtop_warn_io_r (server,
+ "devstat_compute_statistics()");
+ geom_stats_snapshot_free (sc);
+ geom_stats_close ();
+ geom_deletetree (&gmp);
+ return;
+ }
+ break;
+ }
+ }
+ geom_stats_snapshot_free (sc);
+ geom_stats_close ();
+ geom_deletetree (&gmp);
+
+ buf->read = ld[0];
+ buf->write = ld[1];
+#else
buf->read = sfs.f_syncreads + sfs.f_asyncreads;
buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
+#endif
buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
}

View File

@ -0,0 +1,13 @@
===============================================================================
In order to use the File System read/write monitor, you must chmod
/dev/devstat so that all users can open it read-only. For example:
# chmod 0444 /dev/devstat
In order for this to persist across reboots, add the following to
/etc/devfs.conf:
perm devstat 0444
===============================================================================