diff --git a/lib/libhammer/Makefile b/lib/libhammer/Makefile
index da99a10..bb25a40 100644
--- a/lib/libhammer/Makefile
+++ b/lib/libhammer/Makefile
@@ -1,12 +1,13 @@
 # DragonflyBSD Makefile
 
 LIB=	hammer
-SRCS=	crc32.c info.c misc.c
+SRCS=	crc32.c info.c misc.c stats.c
 INCS=	libhammer.h
 
 SRCS+= crc32.c
 
 MAN+=	 libhammer_get_volinfo.3
+MAN+=	 libhammer_btree_stats.3
 
 MLINKS+= libhammer_get_volinfo.3 libhammer_get_next_pfs.3
 MLINKS+= libhammer_get_volinfo.3 libhammer_get_prev_pfs.3
@@ -14,6 +15,27 @@ MLINKS+= libhammer_get_volinfo.3 libhammer_get_first_pfs.3
 MLINKS+= libhammer_get_volinfo.3 libhammer_get_last_pfs.3
 MLINKS+= libhammer_get_volinfo.3 libhammer_free_volinfo.3
 
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_redo
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_undo
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_commits
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_inode_flushes
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_disk_write
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_disk_read
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_file_iopsw
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_file_iopsr
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_file_write
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_file_read
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_record_iterations
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_root_iterations
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_iterations
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_splits
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_elements
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_deletes
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_inserts
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_lookups
+MLINKS+= libhammer_btree_stats.3 libhammer_stats_btree_searches
+MLINKS+= libhammer_btree_stats.3 libhammer_io_stats
+
 .PATH: ${.CURDIR}/../../sys/libkern
 SHLIB_MAJOR=	0
 
diff --git a/lib/libhammer/libhammer.h b/lib/libhammer/libhammer.h
index ee4283e..417a59c 100644
--- a/lib/libhammer/libhammer.h
+++ b/lib/libhammer/libhammer.h
@@ -33,6 +33,7 @@
  * SUCH DAMAGE.
  *
  */
+
 #ifndef _LIBHAMMER_H_
 #define _LIBHAMMER_H_
 
@@ -109,12 +110,58 @@ typedef struct libhammer_volinfo {
 	TAILQ_HEAD(pfslist, libhammer_pfsinfo) list_pseudo;
 } *libhammer_volinfo_t;
 
+struct libhammer_btree_stats {
+	int64_t iterations;
+	int64_t splits;
+	int64_t inserts;
+	int64_t deletes;
+	int64_t lookups;
+	int64_t searches;
+};
+
+struct libhammer_io_stats {
+	int64_t undo;
+	int64_t dev_writes;
+	int64_t dev_reads;
+	int64_t file_writes;
+	int64_t file_reads;
+	int64_t file_iop_writes;
+	int64_t file_iop_reads;
+	int64_t inode_flushes;
+	int64_t commits;
+};
+
 /*
- * INFO directive prototypes
+ * Function prototypes
  */
 __BEGIN_DECLS
 libhammer_volinfo_t libhammer_get_volinfo(const char *);
 void libhammer_free_volinfo(libhammer_volinfo_t);
+
+int libhammer_stats_redo(int64_t *);
+int libhammer_stats_undo(int64_t *);
+int libhammer_stats_commits(int64_t *);
+int libhammer_stats_inode_flushes(int64_t *);
+int libhammer_stats_disk_write(int64_t *);
+int libhammer_stats_disk_read(int64_t *);
+int libhammer_stats_file_iopsw(int64_t *);
+int libhammer_stats_file_iopsr(int64_t *);
+int libhammer_stats_file_write(int64_t *);
+int libhammer_stats_file_read(int64_t *);
+int libhammer_stats_record_iterations(int64_t *);
+int libhammer_stats_root_iterations(int64_t *);
+int libhammer_stats_btree_iterations(int64_t *);
+int libhammer_stats_btree_splits(int64_t *);
+int libhammer_stats_btree_elements(int64_t *);
+int libhammer_stats_btree_deletes(int64_t *);
+int libhammer_stats_btree_inserts(int64_t *);
+int libhammer_stats_btree_lookups(int64_t *);
+int libhammer_stats_btree_searches(int64_t *);
+int libhammer_btree_stats(struct libhammer_btree_stats *);
+int libhammer_io_stats(struct libhammer_io_stats *);
+
+char *libhammer_find_pfs_mount(int, uuid_t, int);
+void *_libhammer_malloc(size_t);
 __END_DECLS
 
 static __inline libhammer_pfsinfo_t
@@ -141,12 +188,4 @@ libhammer_get_last_pfs(libhammer_volinfo_t volinfo)
 	return TAILQ_LAST(&volinfo->list_pseudo, pfslist);
 }
 
-/*
- * MISC directive prototypes
- */
-__BEGIN_DECLS
-char *libhammer_find_pfs_mount(int, uuid_t, int);
-void *_libhammer_malloc(size_t);
-__END_DECLS
-
 #endif
diff --git a/lib/libhammer/libhammer_btree_stats.3 b/lib/libhammer/libhammer_btree_stats.3
new file mode 100644
index 0000000..5d5ee69
--- /dev/null
+++ b/lib/libhammer/libhammer_btree_stats.3
@@ -0,0 +1,126 @@
+.\"
+.\" Copyright (c) 2013 The DragonFly Project.  All rights reserved.
+.\"
+.\" This code is derived from software contributed to The DragonFly Project
+.\" by Antonio Huete Jimenez <tuxillo@quantumachine.net>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. Neither the name of The DragonFly Project nor the names of its
+.\"    contributors may be used to endorse or promote products derived
+.\"    from this software without specific, prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd September 9, 2013
+.Dt LIBHAMMER 3
+.Os
+.Sh NAME
+.Nm libhammer_stats_redo ,
+.Nm libhammer_stats_undo ,
+.Nm libhammer_stats_commits ,
+.Nm libhammer_stats_inode_flushes ,
+.Nm libhammer_stats_disk_write ,
+.Nm libhammer_stats_disk_read ,
+.Nm libhammer_stats_file_iopsw ,
+.Nm libhammer_stats_file_iopsr ,
+.Nm libhammer_stats_file_write ,
+.Nm libhammer_stats_file_read ,
+.Nm libhammer_stats_record_iterations ,
+.Nm libhammer_stats_root_iterations ,
+.Nm libhammer_stats_btree_iterations ,
+.Nm libhammer_stats_btree_splits ,
+.Nm libhammer_stats_btree_elements ,
+.Nm libhammer_stats_btree_deletes ,
+.Nm libhammer_stats_btree_inserts ,
+.Nm libhammer_stats_btree_lookups ,
+.Nm libhammer_stats_btree_searches ,
+.Nm libhammer_btree_stats ,
+.Nm libhammer_io_stats
+.Nd libhammer statistics functions
+.Sh LIBRARY
+.Lb libhammer
+.Sh SYNOPSIS
+.In libhammer.h
+.Ft int
+.Fn libhammer_stats_redo "int64_t *value"
+.Ft int
+.Fn libhammer_stats_undo "int64_t *value"
+.Ft int
+.Fn libhammer_stats_commits "int64_t *value"
+.Ft int
+.Fn libhammer_stats_inode_flushes "int64_t *value"
+.Ft int
+.Fn libhammer_stats_disk_write "int64_t *value"
+.Ft int
+.Fn libhammer_stats_disk_read "int64_t *value"
+.Ft int
+.Fn libhammer_stats_file_iopsw "int64_t *value"
+.Ft int
+.Fn libhammer_stats_file_iopsr "int64_t *value"
+.Ft int
+.Fn libhammer_stats_file_write "int64_t *value"
+.Ft int
+.Fn libhammer_stats_file_read "int64_t *value"
+.Ft int
+.Fn libhammer_stats_record_iterations "int64_t *value"
+.Ft int
+.Fn libhammer_stats_root_iterations "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_iterations "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_splits "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_elements "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_deletes "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_inserts "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_lookups "int64_t *value"
+.Ft int
+.Fn libhammer_stats_btree_searches "int64_t *value"
+.Ft int
+.Fn libhammer_btree_stats "struct libhammer_btree_stats *bstats"
+.Ft int
+.Fn libhammer_io_stats "struct libhammer_io_stat *iostats"
+.Sh DESCRIPTION
+The set of functions described above will help to gather
+statistics of the mounted
+.Nm HAMMER
+filesystems in the system.
+.Pp
+All the functions will take argument
+.Ar value
+to store the value for the sysctl requested, except for
+.Fn libhammer_btree_stats ""
+and
+.Fn libhammer_io_stats ""
+which will take structures to store groups of values.
+.Sh RETURN VALUES
+.Rv -std
+.Sh SEE ALSO
+.Xr HAMMER 5 ,
+.Xr hammer 8 ,
+.Sh AUTHORS
+This manpage was written by
+.An Antonio Huete Jimenez.
diff --git a/lib/libhammer/stats.c b/lib/libhammer/stats.c
new file mode 100644
index 0000000..e139ddd
--- /dev/null
+++ b/lib/libhammer/stats.c
@@ -0,0 +1,199 @@
+ /*
+ * Copyright (c) 2013 The DragonFly Project.  All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ * by Antonio Huete Jimenez <tuxillo@quantumachine.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <sys/sysctl.h>
+
+#include "libhammer.h"
+
+static
+int
+dosysctl(const char *sname, int64_t *value)
+{
+	size_t len;
+	int error;
+
+	len = sizeof(*value);
+	error = sysctlbyname(sname, value, &len, NULL, 0);
+
+	return error;
+}
+
+int
+libhammer_stats_redo(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_redo", value));
+}
+
+int
+libhammer_stats_undo(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_undo", value));
+}
+
+int
+libhammer_stats_commits(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_commits", value));
+}
+
+int
+libhammer_stats_inode_flushes(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_inode_flushes", value));
+}
+
+int
+libhammer_stats_disk_write(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_disk_write", value));
+}
+
+int
+libhammer_stats_disk_read(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_disk_read", value));
+}
+
+int
+libhammer_stats_file_iopsw(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_file_iopsw", value));
+}
+
+int
+libhammer_stats_file_iopsr(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_file_iopsr", value));
+}
+
+int
+libhammer_stats_file_write(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_file_write", value));
+}
+
+int
+libhammer_stats_file_read(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_file_read", value));
+}
+
+int
+libhammer_stats_record_iterations(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_record_iterations", value));
+}
+
+int
+libhammer_stats_root_iterations(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_root_iterations", value));
+}
+
+int
+libhammer_stats_btree_iterations(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_iterations", value));
+}
+
+int
+libhammer_stats_btree_splits(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_splits", value));
+}
+
+int
+libhammer_stats_btree_elements(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_elements", value));
+}
+
+int
+libhammer_stats_btree_deletes(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_deletes", value));
+}
+
+int
+libhammer_stats_btree_inserts(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_inserts", value));
+}
+
+int
+libhammer_stats_btree_lookups(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_lookups", value));
+}
+
+int
+libhammer_stats_btree_searches(int64_t *value)
+{
+	return (dosysctl("vfs.hammer.stats_btree_searches", value));
+}
+
+int
+libhammer_btree_stats(struct libhammer_btree_stats *bstats)
+{
+	int error = 0;
+
+	error = libhammer_stats_btree_iterations(&bstats->iterations);
+	error = libhammer_stats_btree_splits(&bstats->splits);
+	error = libhammer_stats_btree_inserts(&bstats->inserts);
+	error = libhammer_stats_btree_deletes(&bstats->deletes);
+	error = libhammer_stats_btree_lookups(&bstats->lookups);
+	error = libhammer_stats_btree_searches(&bstats->searches);
+
+	return error;
+}
+
+int
+libhammer_io_stats(struct libhammer_io_stats *iostats)
+{
+	int error = 0;
+
+	error = libhammer_stats_undo(&iostats->undo);
+	error = libhammer_stats_commits(&iostats->commits);
+	error = libhammer_stats_inode_flushes(&iostats->inode_flushes);
+	error = libhammer_stats_disk_write(&iostats->dev_writes);
+	error = libhammer_stats_disk_read(&iostats->dev_reads);
+	error = libhammer_stats_file_iopsw(&iostats->file_iop_writes);
+	error = libhammer_stats_file_iopsr(&iostats->file_iop_reads);
+	error = libhammer_stats_file_write(&iostats->file_writes);
+	error = libhammer_stats_file_read(&iostats->file_reads);
+
+	return error;
+}
