1#compdef vmstat
2
3local -a specs
4case $OSTYPE in
5  *linux*)
6    specs=(
7      '(-w --wide)'{-w,--wide}'[wide output]'
8      '(-t --timestamp)'{-t,--timestamp}'[show timestamp]'
9      '(-n --one-header)'{-n,--one-header}'[do not redisplay header]'
10      '(-S --unit)'{-S+,--unit=}'[specify unit for displayed sizes]:unit prefix [K]:((k\:1000 K\:1024 m\:1000000 M\:1048576))'
11      '1: :_guard "[0-9]#" "interval (seconds)"' '2:count'
12      + '(action)' \
13      '(- :)'{-h,--help}'[display help information]'
14      '(- :)'{-V,--version}'[display version information]'
15      {-a,--active}'[show active/inactive memory]'
16      '(- :)'{-f,--forks}'[show number of forks since boot]'
17      '(-S --unit -t --timestamp -w --wide)'{-m,--slabs}'[show slabinfo]'
18      '(-w --wide -n --one-header -t --timestamp :)'{-s,--stats}'[show event counter statistics]'
19      {-d,--disk}'[show disk statistics]'
20      {-p+,--partition=}'[show partition specific statistics]:partition:_files -W /dev -g "*(-%)"'
21      '(- :)'{-D,--disk-sum}'[summarize disk statistics]'
22    )
23  ;;
24  *bsd*|dragonfly*)
25    specs=(
26      '-c+[specify number of times to refresh the display]:count'
27      '-i[report the number of interrupts taken by devices since boot]'
28      '-M+[specify core file to extract values associated with the name list from]:core:_files'
29      '-N+[specify file to extract the name list from]:system:_files'
30      '-w+[specify delay between each display]:delay (seconds)'
31      '*: :_bsd_disks'
32    )
33  ;|
34  *bsd*)
35    specs+=(
36      '-f[report on the number fork syscalls since boot and pages of virtual memory for each]'
37    )
38  ;|
39  freebsd*|dragonfly*)
40    specs+=(
41      '-m[report on the usage of kernel dynamic memory allocated using malloc(9) by type]'
42      '-n+[change the maximum number of disks to display]:number of disks to display [2]'
43      '*-p+[specify which types of devices to display]: :->devices'
44      '-s[display the contents of the SUM structure]'
45      '-z[report on memory used by the kernel zone allocator, uma(9), by zone]'
46    )
47  ;|
48  freebsd*)
49    specs+=(
50      '-a[include statistics about all interrupts]'
51      '-h[human readable memory columns output]'
52      '-H[scriptable memory columns output]'
53      '-o[list virtual memory objects]'
54      '-P[report per-cpu system/user/idle cpu statistics]'
55    )
56  ;|
57  (net|open)bsd*)
58    specs+=(
59      '-m[report usage of kernel dynamic memory listed first by size of allocation then type of usage]'
60      '-s[display the contents of the UVMEXP structure]'
61      '-v[print more verbose information]'
62    )
63  ;|
64  openbsd*)
65    specs+=(
66      '-t[report on the number of page in and page reclaims since boot]'
67      '-z[include statistics about all interrupts]'
68    )
69  ;;
70  netbsd*)
71    specs+=(
72      '-C[report on kernel memory caches]'
73      '-e[report the values of system event counters]'
74      '-H[report all hash table statistics]'
75      '-h+[dump specified hash table]:hash table:->hashes'
76      '-L[list all hash tables]'
77      '-l[list UVM histories maintained by the kernel]'
78      '-t[display contents of the vmtotal structure]'
79      '-U[dump all UVM histories]'
80      '-u+[dump specified UVM history]:uvm'
81      '-W[print more information about kernel memory pools]'
82    )
83  ;;
84  dragonfly*)
85    specs+=(
86      '-b[use brief format for formatted numbers]'
87      '-o[report usage of kernel object cache]'
88      '-u[output unformatted numeric values]'
89      '-v[include IRQ numbers and IRQ target CPU numbers before device names (with -i)]'
90    )
91  ;;
92  solaris2.<11->)
93    specs+=( '(-i -s)-T+[specify time format]:time format:((u\:seconds\ since\ epoch d\:standard\ date\ format))' )
94  ;&
95  solaris*)
96    specs+=(
97      '-q[suppress messages related to state changes]'
98      + '(actions)' \
99      '(-T)-i[report the number of interrupts taken by devices since boot]'
100      '-p[report paging activity]'
101      '(-T)-s[display the total number of system events since boot]'
102      '-S[report on swapping rather than paging activity]'
103      '::disk:_files -W /dev -g "*(-%b)"'
104      ': :_guard "[0-9]#" "interval (seconds)"' '::count'
105    )
106  ;;
107esac
108
109if (( $#specs )); then
110  local curcontext=$curcontext state state_descr line ret=1
111  typeset -A opt_args
112
113  _arguments -C -s -w -A '-*' : "$specs[@]" && ret=0
114
115  if [[ $state == devices ]]; then
116    _fbsd_device_types && ret=0
117  elif [[ $state == hashes ]]; then
118   local -a tables
119   tables=( ${${${(f)"$(_call_program hashes $words[1] -L)"}[2,-1]#?}/ ##/:} )
120    _describe -t hashes 'hash table' tables && ret=0
121  fi
122  return ret
123fi
124
125_default
126