Node.js의 process.cpuUsage() 메서드

WBOY
풀어 주다: 2023-09-20 08:01:10
앞으로
1205명이 탐색했습니다.

Node.js 中的 process.cpuUsage() 方法

process.argv() 메서드는 현재 실행 중인 프로세스의 사용자와 CPU 사용량을 가져오는 데 사용됩니다. 데이터는 사용자 및 시스템 속성이 포함된 개체로 반환됩니다. 얻은 값은 마이크로초 단위로 10^-6초입니다. 여러 코어가 실행 중인 프로세스에 대해 작업을 수행하는 경우 반환되는 값은 실제 실행 시간보다 클 수 있습니다.

Syntax

process.cpuUsage([previousValue])
로그인 후 복사

Parameters

메서드는 아래에 정의된 단일 매개변수(

  • previousValue )만 허용합니다. 이는 선택적 매개변수입니다. 이는 process.cpuUsage() 메서드에 대한 이전 호출의 반환 값입니다.

Example

cpuUsage.js라는 파일을 만들고 아래 코드 조각을 복사하세요. 파일을 생성한 후 아래 예제와 같이 다음 명령을 사용하여 이 코드를 실행합니다. -

node cpuUsage.js
로그인 후 복사

cpuUsage.js

Live Demo

// Node.js program to demonstrate the use of process.argv

// Importing the process module
const process = require('process');

// Getting the cpu usage details by calling the below method
const usage = process.cpuUsage();

// Printing the cpu usage values
console.log(usage);
로그인 후 복사

Output

admin@root:~/node/test$ node cpuUsage.js
{ user: 352914, system: 19826 }
로그인 후 복사

Example

예제를 하나 더 살펴보겠습니다.

실시간 데모

// Node.js program to demonstrate the use of process.argv

// Importing the process module
const process = require('process');

// Getting the cpu usage details by calling the below method
var usage = process.cpuUsage();
// Printing the cpu usage values
console.log("cpu usage before: ", usage);

// Printing the current time stamp
const now = Date.now();

// Looping to delay the process for 100 milliseconds
while (Date.now() - now < 100);

// After using the cpu for nearly 100ms
// calling the process.cpuUsage() method again...
usage = process.cpuUsage(usage);

// Printing the new cpu usage values
console.log("Cpu usage by this process: ", usage);
로그인 후 복사

Output

admin@root:~/node/test$ node cpuUsage.js
cpu usage before: { user: 357675, system: 32150 }
Cpu usage by this process: { user: 93760, system: 95 }
로그인 후 복사

위 내용은 Node.js의 process.cpuUsage() 메서드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!