@@ -1815,6 +1815,91 @@ process.report.writeReport();
1815
1815
1816
1816
Additional documentation is available in the [ report documentation] [ ] .
1817
1817
1818
+ ## process.resourceUsage()
1819
+ <!-- YAML
1820
+ added: REPLACEME
1821
+ -->
1822
+
1823
+ * Returns: {Object}
1824
+ * ` userCPUTime ` {integer}
1825
+ * ` systemCPUTime ` {integer}
1826
+ * ` maxRSS ` {integer}
1827
+ * ` sharedMemorySize ` {integer}
1828
+ * ` unsharedDataSize ` {integer}
1829
+ * ` unsharedStackSize ` {integer}
1830
+ * ` minorPageFault ` {integer}
1831
+ * ` majorPageFault ` {integer}
1832
+ * ` swapedOut ` {integer}
1833
+ * ` fsRead ` {integer}
1834
+ * ` fsWrite ` {integer}
1835
+ * ` ipcSent ` {integer}
1836
+ * ` ipcReceived ` {integer}
1837
+ * ` signalsCount ` {integer}
1838
+ * ` voluntaryContextSwitches ` {integer}
1839
+ * ` involuntaryContextSwitches ` {integer}
1840
+
1841
+ The ` process.resourceUsage() ` method returns the resource usage
1842
+ for the current process.
1843
+ All of these values come from the ` uv_getrusage ` call which returns
1844
+ [ this struct] [ uv_rusage_t ] , here the mapping between node and libuv:
1845
+ - ` userCPUTime ` maps to ` ru_utime ` computed in microseconds.
1846
+ It is the values as [ ` process.cpuUsage().user ` ] [ process.cpuUsage ]
1847
+ - ` systemCPUTime ` maps to ` ru_stime ` computed in microseconds.
1848
+ It is the value as [ ` process.cpuUsage().system ` ] [ process.cpuUsage ]
1849
+ - ` maxRSS ` maps to ` ru_maxrss ` which is the maximum resident set size
1850
+ used (in kilobytes).
1851
+ - ` sharedMemorySize ` maps to ` ru_ixrss ` but is not supported by any platform.
1852
+ - ` unsharedDataSize ` maps to ` ru_idrss ` but is not supported by any platform.
1853
+ - ` unsharedStackSize ` maps to ` ru_isrss ` but is not supported by any platform.
1854
+ - ` minorPageFault ` maps to ` ru_minflt ` which is the number of minor page fault
1855
+ for the process, see [ this article for more details] [ wikipedia_minor_fault ]
1856
+ - ` majorPageFault ` maps to ` ru_majflt ` which is the number of major page fault
1857
+ for the process, see [ this article for more details] [ wikipedia_major_fault ] .
1858
+ This field is not supported on Windows platforms.
1859
+ - ` swappedOut ` maps to ` ru_nswap ` which is not supported by any platform.
1860
+ - ` fsRead ` maps to ` ru_inblock ` which is the number of times the file system
1861
+ had to perform input.
1862
+ - ` fsWrite ` maps to ` ru_oublock ` which is the number of times the file system
1863
+ had to perform output.
1864
+ - ` ipcSent ` maps to ` ru_msgsnd ` but is not supported by any platform.
1865
+ - ` ipcReceived ` maps to ` ru_msgrcv ` but is not supported by any platform.
1866
+ - ` signalsCount ` maps to ` ru_nsignals ` but is not supported by any platform.
1867
+ - ` voluntaryContextSwitches ` maps to ` ru_nvcsw ` which is the number of times
1868
+ a CPU context switch resulted due to a process voluntarily giving up the
1869
+ processor before its time slice was completed
1870
+ (usually to await availability of a resource).
1871
+ This field is not supported on Windows platforms.
1872
+ - ` involuntaryContextSwitches ` maps to ` ru_nivcsw ` which is the number of times
1873
+ a CPU context switch resulted due to a higher priority process becoming runnable
1874
+ or because the current process exceeded its time slice.
1875
+ This field is not supported on Windows platforms.
1876
+
1877
+
1878
+ ``` js
1879
+ console .log (process .resourceUsage ());
1880
+ /*
1881
+ Will output:
1882
+ {
1883
+ userCPUTime: 82872,
1884
+ systemCPUTime: 4143,
1885
+ maxRSS: 33164,
1886
+ sharedMemorySize: 0,
1887
+ unsharedDataSize: 0,
1888
+ unsharedStackSize: 0,
1889
+ minorPageFault: 2469,
1890
+ majorPageFault: 0,
1891
+ swapedOut: 0,
1892
+ fsRead: 0,
1893
+ fsWrite: 8,
1894
+ ipcSent: 0,
1895
+ ipcReceived: 0,
1896
+ signalsCount: 0,
1897
+ voluntaryContextSwitches: 79,
1898
+ involuntaryContextSwitches: 1
1899
+ }
1900
+ */
1901
+ ```
1902
+
1818
1903
## process.send(message[ , sendHandle[ , options]] [ , callback ] )
1819
1904
<!-- YAML
1820
1905
added: v0.5.9
@@ -2329,6 +2414,10 @@ cases:
2329
2414
[ Writable ] : stream.html#stream_writable_streams
2330
2415
[ debugger ] : debugger.html
2331
2416
[ note on process I/O ] : process.html#process_a_note_on_process_i_o
2417
+ [ process.cpuUsage ] : #process_process_cpuusage_previousvalue
2332
2418
[ process_emit_warning ] : #process_process_emitwarning_warning_type_code_ctor
2333
2419
[ process_warning ] : #process_event_warning
2334
2420
[ report documentation ] : report.html
2421
+ [ uv_rusage_t ] : http://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t
2422
+ [ wikipedia_minor_fault ] : https://en.wikipedia.org/wiki/Page_fault#Minor
2423
+ [ wikipedia_major_fault ] : https://en.wikipedia.org/wiki/Page_fault#Major
0 commit comments