mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #32125 from mx601595686/master
Update 'pidusage' type definition
This commit is contained in:
Vendored
+51
-38
@@ -5,46 +5,59 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface Stat {
|
||||
/**
|
||||
* percentage (from 0 to 100*vcore)
|
||||
*/
|
||||
cpu: number;
|
||||
|
||||
/**
|
||||
* bytes
|
||||
*/
|
||||
memory: number;
|
||||
|
||||
/**
|
||||
* PPID
|
||||
*/
|
||||
ppid: number;
|
||||
|
||||
/**
|
||||
* PID
|
||||
*/
|
||||
pid: number;
|
||||
|
||||
/**
|
||||
* ms user + system time
|
||||
*/
|
||||
ctime: number;
|
||||
|
||||
/**
|
||||
* ms since the start of the process
|
||||
*/
|
||||
elapsed: number;
|
||||
|
||||
/**
|
||||
* ms since epoch
|
||||
*/
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
declare function pidusage(pid: number | string, callback: (err: Error | null, stats: Stat) => void): void;
|
||||
declare function pidusage(pid: number | string, options: { [key: string]: any }, callback: (err: Error | null, stats: Stat) => void): void;
|
||||
declare function pidusage(pids: Array<number | string>, callback: (err: Error | null, stats: { [key: string]: Stat }) => void): void;
|
||||
declare function pidusage(pid: number | string): Promise<Stat>;
|
||||
declare function pidusage(pids: Array<number | string>): Promise<{ [key: string]: Stat }>;
|
||||
declare function pidusage(pids: Array<number | string>, options: { [key: string]: any }, callback: (err: Error | null, stats: { [key: string]: Stat }) => void): void;
|
||||
declare function pidusage(pid: number | string, options?: { [key: string]: any }): Promise<Stat>;
|
||||
declare function pidusage(pids: Array<number | string>, options?: { [key: string]: any }): Promise<{ [key: string]: Stat }>;
|
||||
|
||||
export default pidusage;
|
||||
declare namespace pidusage {
|
||||
type Status = Stat;
|
||||
|
||||
export interface Stat {
|
||||
/**
|
||||
* percentage (from 0 to 100*vcore)
|
||||
*/
|
||||
cpu: number;
|
||||
/**
|
||||
* If needed this function can be used to clear the event loop.
|
||||
* Indeed, we're registering an interval to free up the in-memory metrics.
|
||||
* By calling this, it will clear this interval and all delete all in-memory data
|
||||
*/
|
||||
function clear(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* bytes
|
||||
*/
|
||||
memory: number;
|
||||
|
||||
/**
|
||||
* PPID
|
||||
*/
|
||||
ppid: number;
|
||||
|
||||
/**
|
||||
* PID
|
||||
*/
|
||||
pid: number;
|
||||
|
||||
/**
|
||||
* ms user + system time
|
||||
*/
|
||||
ctime: number;
|
||||
|
||||
/**
|
||||
* ms since the start of the process
|
||||
*/
|
||||
elapsed: number;
|
||||
|
||||
/**
|
||||
* ms since epoch
|
||||
*/
|
||||
timestamp: number;
|
||||
}
|
||||
export = pidusage;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import pidusage, { Stat } from 'pidusage';
|
||||
import pidusage = require('pidusage');
|
||||
|
||||
let cpu: number;
|
||||
let memory: number;
|
||||
@@ -8,7 +8,7 @@ let ctime: number;
|
||||
let elapsed: number;
|
||||
let timestamp: number;
|
||||
|
||||
pidusage(1, (err: Error | null, stats: Stat) => {
|
||||
pidusage(1, (err: Error | null, stats: pidusage.Status) => {
|
||||
cpu = stats.cpu;
|
||||
memory = stats.memory;
|
||||
ppid = stats.ppid;
|
||||
@@ -18,7 +18,7 @@ pidusage(1, (err: Error | null, stats: Stat) => {
|
||||
timestamp = stats.timestamp;
|
||||
});
|
||||
|
||||
pidusage('two', (err: Error | null, stats: Stat) => {
|
||||
pidusage('two', {}, (err: Error | null, stats: pidusage.Status) => {
|
||||
cpu = stats.cpu;
|
||||
memory = stats.memory;
|
||||
ppid = stats.ppid;
|
||||
@@ -28,11 +28,18 @@ pidusage('two', (err: Error | null, stats: Stat) => {
|
||||
timestamp = stats.timestamp;
|
||||
});
|
||||
|
||||
pidusage([1, 'two'], (err: Error | null, stats: { [key: string]: Stat }) => {
|
||||
const one: Stat = stats[1];
|
||||
const two: Stat = stats.two;
|
||||
pidusage([1, 'two'], (err: Error | null, stats: { [key: string]: pidusage.Status }) => {
|
||||
const one: pidusage.Status = stats[1];
|
||||
const two: pidusage.Status = stats.two;
|
||||
});
|
||||
|
||||
const stats_1: Promise<Stat> = pidusage(1);
|
||||
const stats_two: Promise<Stat> = pidusage('two');
|
||||
const stats_obj: Promise<{ [key: string]: Stat }> = pidusage([1, 'two']);
|
||||
pidusage([1, 'two'], {}, (err: Error | null, stats: { [key: string]: pidusage.Status }) => {
|
||||
const one: pidusage.Status = stats[1];
|
||||
const two: pidusage.Status = stats.two;
|
||||
});
|
||||
|
||||
const stats_1: Promise<pidusage.Status> = pidusage(1);
|
||||
const stats_two: Promise<pidusage.Status> = pidusage('two', {});
|
||||
|
||||
const stats_obj: Promise<{ [key: string]: pidusage.Status }> = pidusage([1, 'two']);
|
||||
const stats_obj_config: Promise<{ [key: string]: pidusage.Status }> = pidusage([1, 'two'], {});
|
||||
|
||||
Reference in New Issue
Block a user