Huge (k)FreeBSD update. (k)FreeBSD support is freebsd/ Other BSD are in
2007-02-18 Benoît Dejean <benoit@placenet.org> * configure.in: * libgtop-sysdeps.m4: * sysdeps/Makefile.am: Huge (k)FreeBSD update. (k)FreeBSD support is freebsd/ Other BSD are in bsd/ Patch by Joe Marcus Clarke <marcus@freebsd.org> Alexander Nedotsukov <bland@FreeBSD.org> Closes #407693. svn path=/trunk/; revision=2557
This commit is contained in:
committed by
Benoît Dejean
parent
747438e334
commit
5a15e409cf
@@ -1,11 +1,4 @@
|
||||
#include <config.h>
|
||||
|
||||
/* Although FreeBSD ships with statvfs it seems incomplete, so prefer statfs */
|
||||
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
|
||||
#undef HAVE_SYS_STATVFS_H
|
||||
#undef STAT_STATVFS
|
||||
#endif
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/fsusage.h>
|
||||
@@ -16,10 +9,12 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#if defined (HAVE_SYS_STATVFS_H)
|
||||
#include <sys/statvfs.h>
|
||||
#else
|
||||
#include <sys/mount.h>
|
||||
#if __FreeBSD_version >= 600000 || defined(__FreeBSD_kernel__)
|
||||
#include <libgeom.h>
|
||||
#include <sys/resource.h>
|
||||
#include <devstat.h>
|
||||
#include <sys/devicestat.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -29,32 +24,115 @@
|
||||
void
|
||||
G_GNUC_INTERNAL
|
||||
_glibtop_freebsd_get_fsusage_read_write(glibtop *server,
|
||||
glibtop_fsusage *buf,
|
||||
const char *path);
|
||||
glibtop_fsusage *buf,
|
||||
const char *path);
|
||||
|
||||
void G_GNUC_INTERNAL
|
||||
_glibtop_freebsd_get_fsusage_read_write(glibtop *server,
|
||||
glibtop_fsusage *buf,
|
||||
const char *path)
|
||||
glibtop_fsusage *buf,
|
||||
const char *path)
|
||||
{
|
||||
int result;
|
||||
#if defined (STAT_STATVFS)
|
||||
struct statvfs sfs;
|
||||
#else
|
||||
struct statfs sfs;
|
||||
int result;
|
||||
struct statfs sfs;
|
||||
#if __FreeBSD_version >= 600000 || defined(__FreeBSD_kernel__)
|
||||
struct devstat *ds;
|
||||
void *sc;
|
||||
struct timespec ts;
|
||||
struct gprovider *gp;
|
||||
struct gident *gid;
|
||||
struct gmesh gmp;
|
||||
double etime;
|
||||
uint64_t ld[2];
|
||||
#endif
|
||||
|
||||
#if defined (STAT_STATVFS)
|
||||
result = statvfs (path, &sfs);
|
||||
result = statfs (path, &sfs);
|
||||
|
||||
if (result == -1) {
|
||||
glibtop_warn_io_r (server, "statfs");
|
||||
return;
|
||||
}
|
||||
#if __FreeBSD_version >= 600000 || defined(__FreeBSD_kernel__)
|
||||
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 != 0) {
|
||||
glibtop_warn_io_r (server, "geom_stats_open()");
|
||||
geom_deletetree (&gmp);
|
||||
return;
|
||||
}
|
||||
|
||||
sc = NULL;
|
||||
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
|
||||
result = statfs (path, &sfs);
|
||||
buf->read = sfs.f_syncreads + sfs.f_asyncreads;
|
||||
buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
|
||||
#endif
|
||||
|
||||
if (result == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
buf->read = sfs.f_syncreads + sfs.f_asyncreads;
|
||||
buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
|
||||
buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
|
||||
buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user