Specified devices are the first selection priority. These are generally devices specified by name by the user e.g. da0, da1, cd0.
match patterns
These are pattern matching expressions generated by devstat_buildmatch from user input.
performance
If performance mode is enabled, devices will be sorted based on the bytes field in the .Vt device_selection structure passed in to devstat_selectdevs. The bytes value currently must be maintained by the user. In the future, this may be done for him in a devstat library routine. If no devices have been selected by name or by pattern, the performance tracking code will select every device in the system, and sort them by performance. If devices have been selected by name or pattern, the performance tracking code will honor those selections and will only sort among the selected devices.
order in the devstat list
If the selection mode is set to DS_SELECT_ADD, and if there are still less than maxshowdevs devices selected, devstat_selectdevs will automatically select up to maxshowdevs devices.
The devstat_selectdevs function performs selections in four different modes:
DS_SELECT_ADD
In "add" mode, devstat_selectdevs will select any unselected devices specified by name or matching pattern. It will also select more devices, in devstat list order, until the number of selected devices is equal to maxshowdevs or until all devices are selected.
DS_SELECT_ONLY
In "only" mode, devstat_selectdevs will clear all current selections, and will only select devices specified by name or by matching pattern.
DS_SELECT_REMOVE
In "remove" mode, devstat_selectdevs will remove devices specified by name or by matching pattern. It will not select any additional devices.
DS_SELECT_ADDONLY
In ""add only"" mode, devstat_selectdevs will select any unselected devices specified by name or matching pattern. In this respect it is identical to "add" mode. It will not, however, select any devices other than those specified.
In all selection modes, devstat_selectdevs will not select any more than maxshowdevs devices. One exception to this is when you are in "top" mode and no devices have been selected. In this case, devstat_selectdevs will select every device in the system. Client programs must pay attention to selection order when deciding whether to pay attention to a particular device. This may be the wrong behavior, and probably requires additional thought.
The devstat_selectdevs function handles allocation and resizing of the dev_select structure passed in by the client. The devstat_selectdevs function uses the numdevs and current_generation fields to track the current devstat generation and number of devices. If num_selections is not the same as numdevs or if select_generation is not the same as current_generation, devstat_selectdevs will resize the selection list as necessary, and re-initialize the selection array.
The devstat_buildmatch function takes a comma separated match string and compiles it into a .Vt devstat_match structure that is understood by devstat_selectdevs. Match strings have the following format:
The devstat_buildmatch function takes care of allocating and reallocating the match list as necessary. Currently known match types include:
device type:
da
Direct Access devices
sa
Sequential Access devices
printer
Printers
proc
Processor devices
worm
Write Once Read Multiple devices
cd
CD devices
scanner
Scanner devices
optical
Optical Memory devices
changer
Medium Changer devices
comm
Communication devices
array
Storage Array devices
enclosure
Enclosure Services devices
floppy
Floppy devices
interface:
IDE
Integrated Drive Electronics devices
SCSI
Small Computer System Interface devices
other
Any other device interface
passthrough:
pass
Passthrough devices
The devstat_compute_statistics function provides complete statistics calculation. There are four arguments for which values must be supplied: current, previous, etime, and the terminating argument for the varargs list, DSM_NONE. For most applications, the user will want to supply valid .Vt devstat structures for both current and previous. In some instances, for instance when calculating statistics since system boot, the user may pass in a NULL pointer for the previous argument. In that case, devstat_compute_statistics will use the total stats in the current structure to calculate statistics over etime. For each statistics to be calculated, the user should supply the proper enumerated type (listed below), and a variable of the indicated type. All statistics are either integer values, for which a .Vt u_int64_t is used, or floating point, for which a .Vt "long double" is used. The statistics that may be calculated are:
DSM_NONE
type: N/A
This must be the last argument passed to devstat_compute_statistics. It is an argument list terminator.
DSM_TOTAL_BYTES
type: .Vt "u_int64_t *"
The total number of bytes transferred between the acquisition of previous and current.
The total number of transactions of the specified type between the acquisition of previous and current.
DSM_TOTAL_BLOCKS
type: .Vt "u_int64_t *"
The total number of blocks transferred between the acquisition of previous and current. This number is in terms of the blocksize reported by the device. If no blocksize has been reported (i.e., the block size is 0), a default blocksize of 512 bytes will be used in the calculation.
The total number of blocks of the specified type between the acquisition of previous and current. This number is in terms of the blocksize reported by the device. If no blocksize has been reported (i.e., the block size is 0), a default blocksize of 512 bytes will be used in the calculation.
DSM_KB_PER_TRANSFER
type: .Vt "long double *"
The average number of kilobytes per transfer between the acquisition of previous and current.
The average number of megabytes per second in the specified type of transaction between the acquisition of previous and current.
DSM_BLOCKS_PER_SECOND
type: .Vt "long double *"
The average number of blocks transferred per second between the acquisition of previous and current. This number is in terms of the blocksize reported by the device. If no blocksize has been reported (i.e., the block size is 0), a default blocksize of 512 bytes will be used in the calculation.
The average number of blocks per second in the specificed type of transaction between the acquisition of previous and current. This number is in terms of the blocksize reported by the device. If no blocksize has been reported (i.e., the block size is 0), a default blocksize of 512 bytes will be used in the calculation.
DSM_MS_PER_TRANSACTION
type: .Vt "long double *"
The average duration of transactions between the acquisition of previous and current.
The average duration of transactions of the specified type between the acquisition of previous and current.
DSM_BUSY_PCT
type: .Vt "long double *"
The percentage of time the device had one or more transactions outstanding between the acquisition of previous and current.
DSM_QUEUE_LENGTH
type: .Vt "u_int64_t *"
The number of not yet completed transactions at the time when current was acquired.
DSM_SKIP
type: N/A
If you do not need a result from devstat_compute_statistics, just put DSM_SKIP as first (type) parameter and NULL as second parameter. This can be useful in scenarios where the statistics to be calculated are determined at run time.
The devstat_compute_etime function provides an easy way to find the difference in seconds between two .Vt bintime structures. This is most commonly used in conjunction with the time recorded by the devstat_getdevs function (in .Vt "struct statinfo" ) each time it fetches the current devstat list.