Interface LibKstat

  • All Superinterfaces:
    Library

    public interface LibKstat
    extends Library
    Kstat library. The kstat facility is a general-purpose mechanism for providing kernel statistics to users.
    Author:
    widdis[at]gmail[dot]com
    • Method Detail

      • kstat_open

        LibKstat.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_close

        int kstat_close​(LibKstat.KstatCtl kc)
        The 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_update

        int kstat_chain_update​(LibKstat.KstatCtl kc)
        The 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_read

        int kstat_read​(LibKstat.KstatCtl kc,
                       LibKstat.Kstat ksp,
                       Pointer p)
        kstat_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_write

        int kstat_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. 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_lookup

        LibKstat.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_lookup

        Pointer 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 . 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.