process.resourceUsage()


  • 返回: <Object> 当前进程的资源使用情况。 所有这些值都来自返回 uv_rusage_t structuv_getrusage 调用。
    • userCPUTime <integer> 映射到以微秒计算的 ru_utime。 它与 process.cpuUsage().user 的值相同。
    • systemCPUTime <integer> 映射到以微秒计算的 ru_stime。 它与 process.cpuUsage().system 的值相同。
    • maxRSS <integer> 映射到 ru_maxrss,其以千字节为单位使用的最大驻留集大小。
    • sharedMemorySize <integer> 映射到 ru_ixrss 但不受任何平台支持。
    • unsharedDataSize <integer> 映射到 ru_idrss 但不受任何平台支持。
    • unsharedStackSize <integer> 映射到 ru_isrss 但不受任何平台支持。
    • minorPageFault <integer> 映射到 ru_minflt,这是进程的次要页面错误的数量,请参阅这篇文章了解更多详情
    • majorPageFault <integer> 映射到 ru_majflt,这是进程的主要页面错误的数量,请参阅这篇文章了解更多详情。 Windows 不支持此字段。
    • swappedOut <integer> 映射到 ru_nswap 但不受任何平台支持。
    • fsRead <integer> 映射到 ru_inblock,这是文件系统必须执行输入的次数。
    • fsWrite <integer> 映射到 ru_oublock,这是文件系统必须执行输出的次数。
    • ipcSent <integer> 映射到 ru_msgsnd 但不受任何平台支持。
    • ipcReceived <integer> 映射到 ru_msgrcv 但不受任何平台支持。
    • signalsCount <integer> 映射到 ru_nsignals 但不受任何平台支持。
    • voluntaryContextSwitches <integer> 映射到 ru_nvcsw,这是由于进程在其时间片完成之前自愿放弃处理器而导致 CPU 上下文切换的次数(通常是为了等待资源的可用性)。 Windows 不支持此字段。
    • involuntaryContextSwitches <integer> 映射到 ru_nivcsw,这是由于更高优先级的进程变得可运行或当前进程超过其时间片而导致 CPU 上下文切换的次数。 Windows 不支持此字段。
import { resourceUsage } from 'node:process';

console.log(resourceUsage());
/*
  Will output:
  {
    userCPUTime: 82872,
    systemCPUTime: 4143,
    maxRSS: 33164,
    sharedMemorySize: 0,
    unsharedDataSize: 0,
    unsharedStackSize: 0,
    minorPageFault: 2469,
    majorPageFault: 0,
    swappedOut: 0,
    fsRead: 0,
    fsWrite: 8,
    ipcSent: 0,
    ipcReceived: 0,
    signalsCount: 0,
    voluntaryContextSwitches: 79,
    involuntaryContextSwitches: 1
  }
*/const { resourceUsage } = require('node:process');

console.log(resourceUsage());
/*
  Will output:
  {
    userCPUTime: 82872,
    systemCPUTime: 4143,
    maxRSS: 33164,
    sharedMemorySize: 0,
    unsharedDataSize: 0,
    unsharedStackSize: 0,
    minorPageFault: 2469,
    majorPageFault: 0,
    swappedOut: 0,
    fsRead: 0,
    fsWrite: 8,
    ipcSent: 0,
    ipcReceived: 0,
    signalsCount: 0,
    voluntaryContextSwitches: 79,
    involuntaryContextSwitches: 1
  }
*/
  • Returns: <Object> the resource usage for the current process. All of these values come from the uv_getrusage call which returns a uv_rusage_t struct.
    • userCPUTime <integer> maps to ru_utime computed in microseconds. It is the same value as process.cpuUsage().user.
    • systemCPUTime <integer> maps to ru_stime computed in microseconds. It is the same value as process.cpuUsage().system.
    • maxRSS <integer> maps to ru_maxrss which is the maximum resident set size used in kilobytes.
    • sharedMemorySize <integer> maps to ru_ixrss but is not supported by any platform.
    • unsharedDataSize <integer> maps to ru_idrss but is not supported by any platform.
    • unsharedStackSize <integer> maps to ru_isrss but is not supported by any platform.
    • minorPageFault <integer> maps to ru_minflt which is the number of minor page faults for the process, see this article for more details.
    • majorPageFault <integer> maps to ru_majflt which is the number of major page faults for the process, see this article for more details. This field is not supported on Windows.
    • swappedOut <integer> maps to ru_nswap but is not supported by any platform.
    • fsRead <integer> maps to ru_inblock which is the number of times the file system had to perform input.
    • fsWrite <integer> maps to ru_oublock which is the number of times the file system had to perform output.
    • ipcSent <integer> maps to ru_msgsnd but is not supported by any platform.
    • ipcReceived <integer> maps to ru_msgrcv but is not supported by any platform.
    • signalsCount <integer> maps to ru_nsignals but is not supported by any platform.
    • voluntaryContextSwitches <integer> maps to ru_nvcsw which is the number of times a CPU context switch resulted due to a process voluntarily giving up the processor before its time slice was completed (usually to await availability of a resource). This field is not supported on Windows.
    • involuntaryContextSwitches <integer> maps to ru_nivcsw which is the number of times a CPU context switch resulted due to a higher priority process becoming runnable or because the current process exceeded its time slice. This field is not supported on Windows.
import { resourceUsage } from 'node:process';

console.log(resourceUsage());
/*
  Will output:
  {
    userCPUTime: 82872,
    systemCPUTime: 4143,
    maxRSS: 33164,
    sharedMemorySize: 0,
    unsharedDataSize: 0,
    unsharedStackSize: 0,
    minorPageFault: 2469,
    majorPageFault: 0,
    swappedOut: 0,
    fsRead: 0,
    fsWrite: 8,
    ipcSent: 0,
    ipcReceived: 0,
    signalsCount: 0,
    voluntaryContextSwitches: 79,
    involuntaryContextSwitches: 1
  }
*/const { resourceUsage } = require('node:process');

console.log(resourceUsage());
/*
  Will output:
  {
    userCPUTime: 82872,
    systemCPUTime: 4143,
    maxRSS: 33164,
    sharedMemorySize: 0,
    unsharedDataSize: 0,
    unsharedStackSize: 0,
    minorPageFault: 2469,
    majorPageFault: 0,
    swappedOut: 0,
    fsRead: 0,
    fsWrite: 8,
    ipcSent: 0,
    ipcReceived: 0,
    signalsCount: 0,
    voluntaryContextSwitches: 79,
    involuntaryContextSwitches: 1
  }
*/