mirror of https://github.com/xzeldon/htop.git
ZFS arcstats for Darwin (macOS / OS X)
This commit is contained in:
parent
070fe90461
commit
fc8e9a2d3e
|
@ -134,14 +134,16 @@ darwin_platform_headers = \
|
||||||
darwin/DarwinProcess.h \
|
darwin/DarwinProcess.h \
|
||||||
darwin/DarwinProcessList.h \
|
darwin/DarwinProcessList.h \
|
||||||
darwin/DarwinCRT.h \
|
darwin/DarwinCRT.h \
|
||||||
darwin/Battery.h
|
darwin/Battery.h \
|
||||||
|
$(zfs_platform_headers)
|
||||||
|
|
||||||
all_platform_headers += $(darwin_platform_headers)
|
all_platform_headers += $(darwin_platform_headers)
|
||||||
|
|
||||||
if HTOP_DARWIN
|
if HTOP_DARWIN
|
||||||
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \
|
||||||
|
$(zfs_platform_sources)
|
||||||
|
|
||||||
myhtopplatheaders = $(darwin_platform_headers)
|
myhtopplatheaders = $(darwin_platform_headers)
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -54,6 +54,7 @@ int CompareKernelVersion(short int major, short int minor, short int component)
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
@ -67,10 +68,28 @@ typedef struct DarwinProcessList_ {
|
||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
|
|
||||||
|
int zfsArcEnabled;
|
||||||
|
unsigned long long int zfsArcMax;
|
||||||
|
unsigned long long int zfsArcSize;
|
||||||
|
unsigned long long int zfsArcMFU;
|
||||||
|
unsigned long long int zfsArcMRU;
|
||||||
|
unsigned long long int zfsArcAnon;
|
||||||
|
unsigned long long int zfsArcHeader;
|
||||||
|
unsigned long long int zfsArcOther;
|
||||||
|
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_c_max[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_size[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_mfu_size[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_mru_size[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_anon_size[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_hdr_size[5];
|
||||||
|
static int MIB_kstat_zfs_misc_arcstats_other_size[5];
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
|
@ -131,8 +150,50 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||||
return processes;
|
return processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void DarwinProcessList_scanZfsArcstats(DarwinProcessList* dpl) {
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (dpl->zfsArcEnabled) {
|
||||||
|
len = sizeof(dpl->zfsArcSize);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(dpl->zfsArcSize), &len , NULL, 0);
|
||||||
|
/* TODO: adjust reported memory in use to move ARC from wired to inactive
|
||||||
|
Like:
|
||||||
|
// In bytes
|
||||||
|
dpl->vm_stats.wire_count -= dpl->zfsArcSize / vm_page_size;
|
||||||
|
dpl->vm_stats.inactive_count += dpl->zfsArcSize / vm_page_size;
|
||||||
|
// Would purgable_count be more true?
|
||||||
|
// Then convert to KB:
|
||||||
|
*/
|
||||||
|
dpl->zfsArcSize /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcMax);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(dpl->zfsArcMax), &len , NULL, 0);
|
||||||
|
dpl->zfsArcMax /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcMFU);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(dpl->zfsArcMFU), &len , NULL, 0);
|
||||||
|
dpl->zfsArcMFU /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcMRU);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(dpl->zfsArcMRU), &len , NULL, 0);
|
||||||
|
dpl->zfsArcMRU /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcAnon);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(dpl->zfsArcAnon), &len , NULL, 0);
|
||||||
|
dpl->zfsArcAnon /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcHeader);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(dpl->zfsArcHeader), &len , NULL, 0);
|
||||||
|
dpl->zfsArcHeader /= 1024;
|
||||||
|
|
||||||
|
len = sizeof(dpl->zfsArcOther);
|
||||||
|
sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(dpl->zfsArcOther), &len , NULL, 0);
|
||||||
|
dpl->zfsArcOther /= 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||||
|
size_t len;
|
||||||
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
||||||
|
|
||||||
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
||||||
|
@ -145,6 +206,24 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
||||||
/* Initialize the VM statistics */
|
/* Initialize the VM statistics */
|
||||||
ProcessList_getVMStats(&this->vm_stats);
|
ProcessList_getVMStats(&this->vm_stats);
|
||||||
|
|
||||||
|
/* Initialize the ZFS kstats, if zfs.kext loaded */
|
||||||
|
len = sizeof(this->zfsArcSize);
|
||||||
|
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &this->zfsArcSize, &len,
|
||||||
|
NULL, 0) == 0 && this->zfsArcSize != 0) {
|
||||||
|
this->zfsArcEnabled = 1;
|
||||||
|
|
||||||
|
len = 5;
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len);
|
||||||
|
sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len);
|
||||||
|
} else {
|
||||||
|
this->zfsArcEnabled = 0;
|
||||||
|
}
|
||||||
|
|
||||||
this->super.kernelThreads = 0;
|
this->super.kernelThreads = 0;
|
||||||
this->super.userlandThreads = 0;
|
this->super.userlandThreads = 0;
|
||||||
this->super.totalTasks = 0;
|
this->super.totalTasks = 0;
|
||||||
|
@ -173,6 +252,7 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
dpl->prev_load = dpl->curr_load;
|
dpl->prev_load = dpl->curr_load;
|
||||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||||
ProcessList_getVMStats(&dpl->vm_stats);
|
ProcessList_getVMStats(&dpl->vm_stats);
|
||||||
|
DarwinProcessList_scanZfsArcstats(dpl);
|
||||||
|
|
||||||
/* Get the time difference */
|
/* Get the time difference */
|
||||||
dpl->global_diff = 0;
|
dpl->global_diff = 0;
|
||||||
|
|
|
@ -9,6 +9,17 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct kern;
|
||||||
|
|
||||||
|
void GetKernelVersion(struct kern *k);
|
||||||
|
|
||||||
|
/* compare the given os version with the one installed returns:
|
||||||
|
0 if equals the installed version
|
||||||
|
positive value if less than the installed version
|
||||||
|
negative value if more than the installed version
|
||||||
|
*/
|
||||||
|
int CompareKernelVersion(short int major, short int minor, short int component);
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
@ -23,6 +34,16 @@ typedef struct DarwinProcessList_ {
|
||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
|
|
||||||
|
int zfsArcEnabled;
|
||||||
|
unsigned long long int zfsArcMax;
|
||||||
|
unsigned long long int zfsArcSize;
|
||||||
|
unsigned long long int zfsArcMFU;
|
||||||
|
unsigned long long int zfsArcMRU;
|
||||||
|
unsigned long long int zfsArcAnon;
|
||||||
|
unsigned long long int zfsArcHeader;
|
||||||
|
unsigned long long int zfsArcOther;
|
||||||
|
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ in the source distribution for its full text.
|
||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
#include "zfs/ZfsArcMeter.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -117,6 +118,7 @@ MeterClass* Platform_meterTypes[] = {
|
||||||
&RightCPUsMeter_class,
|
&RightCPUsMeter_class,
|
||||||
&LeftCPUs2Meter_class,
|
&LeftCPUs2Meter_class,
|
||||||
&RightCPUs2Meter_class,
|
&RightCPUs2Meter_class,
|
||||||
|
&ZfsArcMeter_class,
|
||||||
&BlankMeter_class,
|
&BlankMeter_class,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
@ -241,6 +243,23 @@ void Platform_setSwapValues(Meter* mtr) {
|
||||||
mtr->values[0] = swapused.xsu_used / 1024;
|
mtr->values[0] = swapused.xsu_used / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this) {
|
||||||
|
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
|
||||||
|
|
||||||
|
this->total = dpl->zfsArcMax;
|
||||||
|
this->values[0] = dpl->zfsArcMFU;
|
||||||
|
this->values[1] = dpl->zfsArcMRU;
|
||||||
|
this->values[2] = dpl->zfsArcAnon;
|
||||||
|
this->values[3] = dpl->zfsArcHeader;
|
||||||
|
this->values[4] = dpl->zfsArcOther;
|
||||||
|
|
||||||
|
// "Hide" the last value so it can
|
||||||
|
// only be accessed by index and is not
|
||||||
|
// displayed by the Bar or Graph style
|
||||||
|
Meter_setItems(this, 5);
|
||||||
|
this->values[5] = dpl->zfsArcSize;
|
||||||
|
}
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
char* env = NULL;
|
char* env = NULL;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ void Platform_setMemoryValues(Meter* mtr);
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* mtr);
|
void Platform_setSwapValues(Meter* mtr);
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* mtr);
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue