Interface LibKstat
- All Superinterfaces:
- Library
Kstat library. The kstat facility is a general-purpose mechanism for
 providing kernel statistics to users.
- Author:
- widdis[at]gmail[dot]com
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic classThe kernel maintains a linked list of statistics structures, or kstats.static classA kstat control structure.static classInterrupt statistics.static classIO Statistics.static classA list of arbitrary name=value statistics.static classEvent timer statistics.Nested classes/interfaces inherited from interface com.sun.jna.LibraryLibrary.Handler
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intstatic final LibKstatstatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final bytestatic final bytestatic final bytestatic final bytestatic final byteFields inherited from interface com.sun.jna.LibraryOPTION_ALLOW_OBJECTS, OPTION_CALLING_CONVENTION, OPTION_CLASSLOADER, OPTION_FUNCTION_MAPPER, OPTION_INVOCATION_MAPPER, OPTION_OPEN_FLAGS, OPTION_STRING_ENCODING, OPTION_STRUCTURE_ALIGNMENT, OPTION_SYMBOL_PROVIDER, OPTION_TYPE_MAPPER
- 
Method SummaryModifier and TypeMethodDescriptionintThe kstat_chain_update() function brings the user's kstat header chain in sync with that of the kernel.intThe kstat_close() function frees all resources that were associated with kc.kstat_data_lookup(LibKstat.Kstat ksp, String name) The kstat_data_lookup() function searches the kstat's data section for the record with the specified name .kstat_lookup(LibKstat.KstatCtl kc, String ks_module, int ks_instance, String ks_name) The kstat_lookup() function traverses the kstat chain, kc.kc_chain, searching for a kstat with the same ks_module, ks_instance, and ks_name fields; this triplet uniquely identifies a kstat.The kstat_open() function initializes a kstat control structure, which provides access to the kernel statistics library.intkstat_read(LibKstat.KstatCtl kc, LibKstat.Kstat ksp, Pointer p) kstat_read() gets data from the kernel for the kstat pointed to by ksp.intkstat_write(LibKstat.KstatCtl kc, LibKstat.Kstat ksp, Pointer buf) kstat_write() writes data from buf, or from ksp.ks_data if buf is NULL, to the corresponding kstat in the kernel.
- 
Field Details- 
INSTANCE
- 
KSTAT_TYPE_RAWstatic final byte KSTAT_TYPE_RAW- See Also:
 
- 
KSTAT_TYPE_NAMEDstatic final byte KSTAT_TYPE_NAMED- See Also:
 
- 
KSTAT_TYPE_INTRstatic final byte KSTAT_TYPE_INTR- See Also:
 
- 
KSTAT_TYPE_IOstatic final byte KSTAT_TYPE_IO- See Also:
 
- 
KSTAT_TYPE_TIMERstatic final byte KSTAT_TYPE_TIMER- See Also:
 
- 
KSTAT_DATA_CHARstatic final byte KSTAT_DATA_CHAR- See Also:
 
- 
KSTAT_DATA_INT32static final byte KSTAT_DATA_INT32- See Also:
 
- 
KSTAT_DATA_UINT32static final byte KSTAT_DATA_UINT32- See Also:
 
- 
KSTAT_DATA_INT64static final byte KSTAT_DATA_INT64- See Also:
 
- 
KSTAT_DATA_UINT64static final byte KSTAT_DATA_UINT64- See Also:
 
- 
KSTAT_DATA_STRINGstatic final byte KSTAT_DATA_STRING- See Also:
 
- 
KSTAT_INTR_HARDstatic final int KSTAT_INTR_HARD- See Also:
 
- 
KSTAT_INTR_SOFTstatic final int KSTAT_INTR_SOFT- See Also:
 
- 
KSTAT_INTR_WATCHDOGstatic final int KSTAT_INTR_WATCHDOG- See Also:
 
- 
KSTAT_INTR_SPURIOUSstatic final int KSTAT_INTR_SPURIOUS- See Also:
 
- 
KSTAT_INTR_MULTSVCstatic final int KSTAT_INTR_MULTSVC- See Also:
 
- 
KSTAT_NUM_INTRSstatic final int KSTAT_NUM_INTRS- See Also:
 
- 
KSTAT_STRLENstatic final int KSTAT_STRLEN- See Also:
 
- 
EAGAINstatic final int EAGAIN- See Also:
 
 
- 
- 
Method Details- 
kstat_openLibKstat.KstatCtl kstat_open()The kstat_open() function initializes a kstat control structure, which provides access to the kernel statistics library.- Returns:
- A pointer to this structure, which must be supplied as the kc argument in subsequent libkstat function calls.
 
- 
kstat_closeThe kstat_close() function frees all resources that were associated with kc.- Parameters:
- kc- a kstat control structure
- Returns:
- 0 on success and -1 on failure.
 
- 
kstat_chain_updateThe kstat_chain_update() function brings the user's kstat header chain in sync with that of the kernel. The kstat chain is a linked list of kstat headers (kstat_t's) pointed to by kc.kc_chain, which is initialized by kstat_open(3KSTAT). This chain constitutes a list of all kstats currently in the system. During normal operation, the kernel creates new kstats and delete old ones as various device instances are added and removed, thereby causing the user's copy of the kstat chain to become out of date. The kstat_chain_update() function detects this condition by comparing the kernel's current kstat chain ID(KCID), which is incremented every time the kstat chain changes, to the user's KCID, kc.kc_chain_id. If the KCIDs match, kstat_chain_update() does nothing. Otherwise, it deletes any invalid kstat headers from the user's kstat chain, adds any new ones, and sets kc.kc_chain_id to the new KCID. All other kstat headers in the user's kstat chain are unmodified.- Parameters:
- kc- a kstat control structure
- Returns:
- the new KCID if the kstat chain has changed, 0 if it hasn't, or -1 on failure.
 
- 
kstat_readkstat_read() gets data from the kernel for the kstat pointed to by ksp. ksp.ks_data is automatically allocated (or reallocated) to be large enough to hold all of the data. ksp.ks_ndata is set to the number of data fields, ksp.ks_data_size is set to the total size of the data, and ksp.ks_snaptime is set to the high-resolution time at which the data snapshot was taken.- Parameters:
- kc- The kstat control structure
- ksp- The kstat from which to retrieve data
- p- If buf is non-NULL , the data is copied from ksp.ks_data into buf.
- Returns:
- On success, return the current kstat chain ID (KCID). On failure, return -1.
 
- 
kstat_writekstat_write() writes data from buf, or from ksp.ks_data if buf is NULL, to the corresponding kstat in the kernel. Only the superuser can use kstat_write() .- Parameters:
- kc- The kstat control structure
- ksp- The kstat on which to set data
- buf- If buf is non-NULL, the data is copied from buf into ksp.ks_data.
- Returns:
- On success, return the current kstat chain ID (KCID). On failure, return -1.
 
- 
kstat_lookupLibKstat.Kstat kstat_lookup(LibKstat.KstatCtl kc, String ks_module, int ks_instance, String ks_name) The kstat_lookup() function traverses the kstat chain, kc.kc_chain, searching for a kstat with the same ks_module, ks_instance, and ks_name fields; this triplet uniquely identifies a kstat. If ks_module is NULL, ks_instance is -1, or ks_name is NULL, then those fields will be ignored in the search. For example, kstat_lookup(kc, NULL, -1, "foo") will simply find the first kstat with name "foo".- Parameters:
- kc- The kstat control structure
- ks_module- The kstat module to search
- ks_instance- The kstat instance number
- ks_name- The kstat name to search
- Returns:
- a pointer to the requested kstat if it is found, or NULL if it is not.
 
- 
kstat_data_lookupThe kstat_data_lookup() function searches the kstat's data section for the record with the specified name . This operation is valid only for kstat types which have named data records. Currently, only the KSTAT_TYPE_NAMED and KSTAT_TYPE_TIMER kstats have named data records.- Parameters:
- ksp- The kstat to search
- name- The key for the name-value pair, or name of the timer as applicable
- Returns:
- a pointer to the requested data record if it is found. If the requested record is not found, or if the kstat type is invalid, returns NULL.
 
 
-