Monday, March 22, 2010

Top with ZFS ARC

This is a patch i developed to add zfs arc cache stats to unix top ( 3.8 beta 1 ) for solaris



machine.h:

--- top-3.8beta1/machine.h Wed May 7 13:41:39 2008
+++ top-zfs/machine.h Thu Jan 21 09:26:00 2010
@@ -84,6 +84,7 @@
int *cpustates;
int *kernel;
long *memory;
+ long *zfs_cache;
long *swap;
};

machine/m_sunos5.c:

--- top-3.8beta1/machine/m_sunos5.c Wed May 7 13:41:38 2008
+++ top-zfs/machine/m_sunos5.c Thu Jan 21 09:26:02 2010
@@ -286,13 +286,14 @@


/* these are for detailing the memory statistics */
-long memory_stats[5];
+long memory_stats[6];
char *memorynames[] =
-{"K phys mem, ", "K free mem, ", "K total swap, ", "K free swap", NULL};
+{"K phys mem, ", "K free mem, ", "K total swap, ", "K free swap, ", "K zfs cache", NULL};
#define MEMORY_TOTALMEM 0
#define MEMORY_FREEMEM 1
#define MEMORY_TOTALSWAP 2
#define MEMORY_FREESWAP 3
+#define ZFS_CACHE 4

/* these are for detailing kernel statistics */
int kernel_stats[8];
@@ -1105,6 +1106,38 @@
return (0);
}

+int
+get_zfscache ( long *total )
+{
+
+ long cache;
+ static kstat_t *ks = NULL;
+ kstat_named_t *kn;
+
+ /* only need to grab kstat chain once */
+ if (ks == NULL)
+ {
+ ks = kstat_lookup(kc, "zfs", 0, "arcstats");
+ }
+
+ if (ks != NULL &&
+ kstat_read(kc, ks, 0) != -1 &&
+ (kn = kstat_data_lookup(ks, "size")) != NULL)
+ {
+ cache = kstat_data_value_l(kn) / 1024 ;
+ }
+ else
+ {
+ cache = -1;
+ }
+
+ *total = cache;
+
+ return (0);
+
+
+
+}
/*
* void get_swapinfo(long *total, long *fr)
*
@@ -1466,6 +1499,13 @@
memory_stats[MEMORY_TOTALSWAP] = memory_stats[MEMORY_FREESWAP] = -1;
}

+ if ( get_zfscache(&memory_stats[ZFS_CACHE]) == -1 )
+ {
+
+ memory_stats[ZFS_CACHE] = -1;
+ }
+
+
/* get kernel data */
kernel_stats[KERNEL_CSWITCH] = diff_per_second(sum_current.pswitch, sum_old.pswitch);
kernel_stats[KERNEL_TRAP] = diff_per_second(sum_current.trap, sum_old.trap);


No comments: