os.cpus()
-
返回:<Object[]>
\Returns: <Object[]>
返回包含有关每个逻辑 CPU 内核的信息的对象数组。如果没有可用的 CPU 信息,例如 /proc 文件系统不可用,则该数组将为空。
\Returns an array of objects containing information about each logical CPU core.
The array will be empty if no CPU information is available, such as if the
/proc file system is unavailable.
每个对象上包含的属性包括:
\The properties included on each object include:
-
model<string> -
speed<number> (以兆赫为单位)\
speed<number> (in MHz) -
times<Object>-
user<number> CPU 在用户模式下花费的毫秒数。\
user<number> The number of milliseconds the CPU has spent in user mode. -
nice<number> CPU 在良好模式下花费的毫秒数。\
nice<number> The number of milliseconds the CPU has spent in nice mode. -
sys<number> CPU 在系统模式下花费的毫秒数。\
sys<number> The number of milliseconds the CPU has spent in sys mode. -
idle<number> CPU 在空闲模式下花费的毫秒数。\
idle<number> The number of milliseconds the CPU has spent in idle mode. -
irq<number> CPU 在中断请求模式下花费的毫秒数。\
irq<number> The number of milliseconds the CPU has spent in irq mode.
-
[
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 252020,
nice: 0,
sys: 30340,
idle: 1070356870,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 306960,
nice: 0,
sys: 26980,
idle: 1071569080,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 248450,
nice: 0,
sys: 21750,
idle: 1070919370,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 256880,
nice: 0,
sys: 19430,
idle: 1070905480,
irq: 20,
},
},
] nice 值仅适用于 POSIX。在 Windows 上,所有处理器的 nice 值始终为 0。
\nice values are POSIX-only. On Windows, the nice values of all processors
are always 0.
os.cpus().length 不应用于计算应用可用的并行度。为此使用 os.availableParallelism()。
\os.cpus().length should not be used to calculate the amount of parallelism
available to an application. Use
os.availableParallelism() for this purpose.