def __getitem__(self, triplet): if isinstance(triplet, libkstat.kstat): ksp = C.pointer(triplet) elif isinstance(triplet, libkstat.kstat_p): ksp = triplet else: module, instance, name = triplet ksp = libkstat.kstat_lookup(self._ctl, module, instance, name) if not ksp: raise KeyError(triplet) #if self._check_filter(ksp.contents): # raise KeyError(triplet) return self._read_value(ksp)
def __getitem__(self, triplet): module, instance, name = triplet ksp = libkstat.kstat_lookup(self._ctl, module, instance, name) if not ksp: raise KeyError(triplet) libkstat.kstat_read(self._ctl, ksp, None) ks = ksp.contents if ks.ks_type == libkstat.KSTAT_TYPE_RAW: pass elif ks.ks_type == libkstat.KSTAT_TYPE_NAMED: value = dict() print ks.ks_data datap = C.cast(ks.ks_data, C.POINTER(libkstat.kstat_named)) for i in range(ks.ks_ndata): if datap[i].data_type == libkstat.KSTAT_DATA_CHAR: value[datap[i].name] = datap[i].value.c elif datap[i].data_type == libkstat.KSTAT_DATA_INT32: value[datap[i].name] = datap[i].value.i32 elif datap[i].data_type == libkstat.KSTAT_DATA_UINT32: value[datap[i].name] = datap[i].value.ui32 elif datap[i].data_type == libkstat.KSTAT_DATA_INT64: value[datap[i].name] = datap[i].value.i64 elif datap[i].data_type == libkstat.KSTAT_DATA_UINT64: value[datap[i].name] = datap[i].value.ui64 #print datap.contents #print dir(datap[i].value) #value[datap[i].name] = 0 elif ks.ks_type == libkstat.KSTAT_TYPE_INTR: pass elif ks.ks_type == libkstat.KSTAT_TYPE_IO: pass elif ks.ks_type == libkstat.KSTAT_TYPE_TIMER: pass else: pass return value
def lookup(self): libkstat.kstat_lookup(self._ctl, self._module, self._inst, self._name)
def lookup(self, module, instance, name): kstat_p = libkstat.kstat_lookup(self._kstat_ctl, module, instance, name) if kstat_p is None: return KeyError((module, instance, name)) return kstat_p