#compdef mpstat cifsiostat isag sadf sar pidstat
#TODO:
# sysstat-nfsiostat - there seems to be two nfsiostat(1)s. one from oracle and one by redhat.

_mpstat() {
  _arguments -S : \
    '(-n -u -I -N -P)-A[equivalent to -n -u -I ALL -N ALL -P ALL]' \
    '(-A)-I[report interrupt statistics]:interrupt:(SUM CPU SCPU ALL)' \
    '(-A)-N[specify NUMA nodes]:NUMA node' \
    '(-A)-n[report summary CPU statistics based on NUMA node placement]' \
    '--dec=-[specify the number of decimal places to use]:decimal places [2]:(0 1 2)' \
    '-o[display statistics in JSON]:format:(JSON)' \
    '(-A)-P[specify processor number]:processor: _values -s "," processor ALL {0..$(_call_program processors getconf _NPROCESSORS_ONLN)}' \
    '-T[display topology elements in the CPU report]' \
    '-u[report CPU utilization]' \
    '(- 1 2)-V[display version information]' \
    '1: : _guard "^-*" interval' \
    '2: : _guard "^-*" count'
}

_cifsiostat() {
  _arguments : \
    '--dec=-[specify the number of decimal places to use]:decimal places [2]:(0 1 2)' \
    '-h[human readable]' \
    '(-m)-k[display statistics in kB/s]' \
    '(-k)-m[display statistics in MB/s]' \
    '-t[print timestamp for each report]' \
    '(- 1 2)-V[print version number]' \
    '--human[print sizes in human readable format]' \
    '--pretty[make the CIFS report easier to read by a human]' \
    '1: : _guard "^-*" interval' \
    '2: : _guard "^-*" count'
}

_isag() {
  _arguments : \
    '-p[specify path to daily data files]:path:_files -/' \
    '-c[specify configuration file]:configuration file:_files' \
    '-ght[specify height of the chart]:height' \
    '-gwd[specify width of the chart]:width'
}

_sadf() {
  local i ret=1
  # any options after `--' are for sar(1)
  if (( CURRENT <= $words[(i)--] )); then
    _arguments : \
      '-C[display comments in file]' \
      '-c[convert an old datafile to the new format]' \
      '-e[set ending time of report]:ending time (HH\:MM\:SS)' \
      '-H[display only the header of the report]' \
      '(-g -j -p -r -x)-h[print on a single line when used with -d]' \
      '-O[specify output options]: : _values -s , option
        autoscale bwcol customcol height\:value oneday packed showidle showinfo showtoc skipempty hz\:value pcparchive\:name\:_files debug' \
      '-P[restrict processor dependent statistics]:processor number(zero indexed) or ALL:(ALL)' \
      '--dev=-[specify block devices for which statistics are to be displayed]:block device:_files -g "*(-%)"' \
      '--fs=-[specify filesystems for which statistics are to be displayed]:file system:_dir_list -s ,' \
      '--iface=-[specify network interfaces for which statistics are to be displayed]:network interface:_sequence _net_interfaces' \
      '--int=-[specify interrupts for which statistics are to be displayed]: : _values -s "," interrupt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15' \
      '-s[set starting time of report]:starting time (HH\:MM\:SS)"' \
      '(-t -U)-T[display timestamp in local time]' \
      '(-T -U)-t[display timestamp in file\''s original localtime]' \
      '(-t -T)-U[display in seconds since epoch (UTC)]' \
      '(- 1 2 3)-V[print version number]' \
      '1: : _guard "^-*" interval' \
      '2: : _guard "^-*" count' \
      '3:data file:_files' \
      + '(format)' \
      '-d[output file in SQL format]' \
      '-g[print data in SVG format]' \
      '-j[output file in JSON]' \
      '-l[export the contents of the data file to a PCP (Performance Co-Pilot) archive]' \
      '-p[print in format parsable by tools like awk]' \
      '-r[print raw contents of data file]' \
      '-x[output file in XML]' \
      && ret=0
  else
    (( i = words[(i)--] - 1, CURRENT -= i ))
    shift i words
    _sar && ret=0
  fi
  return ret
}

_sar() {
  _arguments -s : \
    '-A[equivalent to -bBdFHqrRSuvwWy -I SUM -I XALL -m ALL -n ALL -r ALL -u ALL -P ALL]' \
    '-B[report paging statistics]' \
    '-b[report I/O and transfer rate statistics]' \
    '-C[display comments from sadc]' \
    '-D[use saYYYYMMDD instead of saDD as the standard system activity daily data file name]' \
    '-d[report activity for each block device]' \
    '--dec=-[specify the number of decimal places to use]:decimal places [2]:(0 1 2)' \
    '--dev=-[specify block devices for which statistics are to be displayed]:block device:_files -g "*(-%)"' \
    '-e[set ending time of report]:ending time (HH\:MM\:SS)' \
    '-F[display statistics for mounted filesystems]' \
    '-f[extract records from file]:record:_files' \
    '--fs=-[specify filesystems for which statistics are to be displayed]:file system:_dir_list -s ,' \
    '-H[report hugepages utilization]' \
    '(--human -p)-h[make output easier to read: implies --human and -p]' \
    '(- 1 2)--help[display usage information]' \
    '--human[print sizes in human readable format]' \
    '-I[report statistics for interrupts]:interrupt:(SUM ALL)' \
    '-i[select records as close as possible to interval]:interval' \
    '--iface=-[specify network interfaces for which statistics are to be displayed]:network interface:_sequence _net_interfaces' \
    '--int=-[specify interrupts for which statistics are to be displayed]: : _values -s "," interrupt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15' \
    '-j[display persistent device names]:type:(ID LABEL PATH UUID)' \
    '-m[report power management statistics]:keyword:_sequence compadd - CPU FAN FREQ IN TEMP USB ALL' \
    '-n[report network statistics]:keyword:_sequence compadd - DEV EDEV NFS NFSD SOCK IP EIP ICMP EICMP TCP ETCP UDP SOCK6 IP6 EIP6 ICMP6 EICMP6 UDP6 FC SOFT ALL' \
    '-o[save readings to file in binary form]:file:_files' \
    '-P[report per-processor statistics]:processor: _values -s "," processors ALL' \
    '-p[pretty-print device names]' \
    '-q[report queue length and load averages]::keyword:(CPU IO LOAD MEM PSI ALL)' \
    '-R[report memory statistics]' \
    '-r[report memory utilization statistics]:: :(ALL)' \
    '-S[report swap space utilization]' \
    '-s[set starting time of report]:start time (HH\:MM\:SS)' \
    '--sadc[print name of data collector]' \
    '-t[display timestamps in original local time of file creator]' \
    '-u[report CPU utilization]:: :(ALL)' \
    '(- 1 2)-V[display version information]' \
    '-v[report status of kernel tables]' \
    '-W[report swapping statistics]' \
    '-w[report task creation and system switching activity]' \
    '-y[report TTY device activity]' \
    '-z[omit output for any devices lacking activity during sample period]' \
    '1: : _guard "^-*" interval' \
    '2: : _guard "^-*" count'
}

_pidstat() {
  _arguments -s : \
    '-C[filter tasks by string]:task filter' \
    '-d[report I/O statistics]' \
    '-e[execute specified program and monitor it with pidstat]:*::command: _normal -p $service' \
    '-H[display timestamp in seconds since the epoch]' \
    '-h[display horizontally]' \
    '-I[divide CPU usage by number of processors]' \
    '-l[display process name along with arguments]' \
    '*-p[select pid]:pid: _sequence _pids' \
    '-R[report realtime priority and scheduling policy information]' \
    '-r[report page faults and memory]' \
    '-s[report stack utilization]' \
    '-T[specifies what to monitor]:type:(TASK CHILD ALL)' \
    '-t[display statistics for threads]' \
    '-U[display real username of tasks]::username:_users' \
    '-u[report cpu utilization]' \
    '(- 1 2)-V[display version information]' \
    '-v[display values from kernel table]' \
    '-w[report task switching activity]' \
    '-G[include only processes with specified name]:process name' \
    '--dec=-[specify the number of decimal places to use]:decimal places [2]:(0 1 2)' \
    '--human[print sizes in human readable format]' \
    '1: : _guard "^-*" interval' \
    '2: : _guard "^-*" count'
}

_sysstat() {
  local ret
  _call_function ret _$service && return ret
}

_sysstat "$@"
