From bdd42596223ecb78682ffa7192a5a15e151a0d61 Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Sat, 11 Aug 2018 13:30:01 +0800 Subject: [PATCH] update package pidusage`s definition to version 2.0.14 --- types/pidusage/index.d.ts | 56 ++++++++++++++++++++++++--- types/pidusage/pidusage-tests.ts | 27 ++++++++++--- types/pidusage/v1.1/index.d.ts | 12 ++++++ types/pidusage/v1.1/pidusage-tests.ts | 8 ++++ types/pidusage/v1.1/tsconfig.json | 26 +++++++++++++ types/pidusage/v1.1/tslint.json | 3 ++ 6 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 types/pidusage/v1.1/index.d.ts create mode 100644 types/pidusage/v1.1/pidusage-tests.ts create mode 100644 types/pidusage/v1.1/tsconfig.json create mode 100644 types/pidusage/v1.1/tslint.json diff --git a/types/pidusage/index.d.ts b/types/pidusage/index.d.ts index fbe98309b7..a883387a67 100644 --- a/types/pidusage/index.d.ts +++ b/types/pidusage/index.d.ts @@ -1,12 +1,56 @@ -// Type definitions for pidusage 1.1 +// Type definitions for pidusage 2.0 // Project: https://github.com/soyuka/pidusage // Definitions by: Cyril Schumacher +// wujingtao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export interface Stat { - cpu: number; - memory: number; +/** + * @param pids A pid or a list of pids. + * @param callback Called when the statistics are ready. + */ +declare function pidusage(pids: number | number[] | string | string[], callback: (err: Error | null, stats: pidusage.Stat) => void): void; +/** + * @param pids A pid or a list of pids. + */ +declare function pidusage(pids: number | number[] | string | string[]): Promise; + +declare namespace pidusage { + 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; + } } -export function stat(pid: number, callback: (error: Error, stat: Stat) => void): void; -export function unmonitor(pid: number): void; +export = pidusage; diff --git a/types/pidusage/pidusage-tests.ts b/types/pidusage/pidusage-tests.ts index b1d16cbc16..b6835cff18 100644 --- a/types/pidusage/pidusage-tests.ts +++ b/types/pidusage/pidusage-tests.ts @@ -1,8 +1,25 @@ -import pusage = require("pidusage"); +import * as pidusage from 'pidusage'; -pusage.stat(0, (err: Error, stat: pusage.Stat) => { - const cpu = stat.cpu; - const memory = stat.memory; +let cpu: number; +let memory: number; +let ppid: number; +let pid: number; +let ctime: number; +let elapsed: number; +let timestamp: number; + +pidusage(1, (err: Error | null, stats: pidusage.Stat) => { + cpu = stats.cpu; + memory = stats.memory; + ppid = stats.ppid; + pid = stats.pid; + ctime = stats.ctime; + elapsed = stats.elapsed; + timestamp = stats.timestamp; }); -pusage.unmonitor(0); +let stats: Promise; + +stats = pidusage([1, 2]); +stats = pidusage('string'); +stats = pidusage(['string', 'string']); diff --git a/types/pidusage/v1.1/index.d.ts b/types/pidusage/v1.1/index.d.ts new file mode 100644 index 0000000000..fbe98309b7 --- /dev/null +++ b/types/pidusage/v1.1/index.d.ts @@ -0,0 +1,12 @@ +// Type definitions for pidusage 1.1 +// Project: https://github.com/soyuka/pidusage +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Stat { + cpu: number; + memory: number; +} + +export function stat(pid: number, callback: (error: Error, stat: Stat) => void): void; +export function unmonitor(pid: number): void; diff --git a/types/pidusage/v1.1/pidusage-tests.ts b/types/pidusage/v1.1/pidusage-tests.ts new file mode 100644 index 0000000000..b1d16cbc16 --- /dev/null +++ b/types/pidusage/v1.1/pidusage-tests.ts @@ -0,0 +1,8 @@ +import pusage = require("pidusage"); + +pusage.stat(0, (err: Error, stat: pusage.Stat) => { + const cpu = stat.cpu; + const memory = stat.memory; +}); + +pusage.unmonitor(0); diff --git a/types/pidusage/v1.1/tsconfig.json b/types/pidusage/v1.1/tsconfig.json new file mode 100644 index 0000000000..15eed73ebd --- /dev/null +++ b/types/pidusage/v1.1/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "pidusage": [ "pidusage/v1.1" ] + }, + }, + "files": [ + "index.d.ts", + "pidusage-tests.ts" + ] +} \ No newline at end of file diff --git a/types/pidusage/v1.1/tslint.json b/types/pidusage/v1.1/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/pidusage/v1.1/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file