||Query CPU usage statistics for a given time interval using hs.host.cpuUsageTicks and return the results as percentages.
- `period` - an optional value specifying the time between samples collected for calculating CPU usage statistics.
- If `callback` is not provided, this is an optional integer, default 100000, specifying the number of microseconds to block between samples collected. Note that Hammerspoon will block for this period of time during execution of this function.
- If `callback` is provided, this is an optional number, default 1.0, specifying the number of seconds between samples collected. Hammerspoon will *not* block during this time period.
- `callback` - an optional callback function which will receive the cpu usage statistics in a table, described below, as its sole argument.
- If a callback function is not provided, this function will return a table containing the following:
- Individual tables, indexed by the core number, for each CPU core with the following keys in each subtable:
- user -- percentage of CPU time occupied by user level processes.
- system -- percentage of CPU time occupied by system (kernel) level processes.
- nice -- percentage of CPU time occupied by user level processes with a positive nice value. (See notes below)
- active -- For convenience, when you just want the total CPU usage, this is the sum of user, system, and nice.
- idle -- percentage of CPU time spent idle
- The key `overall` containing the same keys as described above but based upon the average of all cores combined.
- The key `n` containing the number of cores detected.
- If a callback function is provided, this function will return a placeholder table with the following metamethods:
- `hs.host.cpuUsage:finished()` - returns a boolean indicating if the second CPU sample has been collected yet (true) or not (false).
- `hs.host.cpuUsage:stop()` - abort the sample collection. The callback function will not be invoked.
- The results of the cpu statistics will be submitted as a table, described above, to the callback function.
- If no callback function is provided, Hammerspoon will block (i.e. no other Hammerspoon activity can occur) during execution of this function for `period` microseconds (1 second = 1,000,000 microseconds). The default period is 1/10 of a second. If `period` is too small, it is possible that some of the CPU statistics may result in `nan` (not-a-number).