Skip to content

Commit 35318bb

Browse files
committed
✨ feat: client.getProcessStats() #2760
1 parent 75c59f0 commit 35318bb

File tree

4 files changed

+113
-29
lines changed

4 files changed

+113
-29
lines changed

package-lock.json

+91-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@
8989
"husky": "^7.0.0",
9090
"line-reader": "^0.4.0",
9191
"marked": "^4.0.10",
92-
"ts-json-schema-generator": "^v1.1.0-next.5",
9392
"node-emoji": "^1.10.0",
9493
"onchange": "^7.0.2",
9594
"precise-commits": "^1.0.2",
9695
"prettier": "^2.0.1",
9796
"release-it": "^14.0.3",
9897
"shelljs": "^0.8.3",
9998
"tiny-glob": "^0.2.9",
99+
"ts-json-schema-generator": "^v1.1.0-next.5",
100100
"ts-node": "^10.0.0",
101101
"tsc-watch": "^4.0.0",
102102
"typeconv": "^1.7.0",
@@ -144,6 +144,8 @@
144144
"parse-url": "^5.0.2",
145145
"patch-package": "^6.2.2",
146146
"pico-s3": "^1.0.1",
147+
"pidtree": "^0.6.0",
148+
"pidusage": "^3.0.0",
147149
"postman-2-swagger": "^0.5.0",
148150
"puppeteer": "15.0.0",
149151
"puppeteer-extra": "^3.2.3",

src/api/Client.ts

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { AdvancedButton, Button, LocationButtonBody, Section } from './model/but
4040
import { JsonObject } from 'type-fest';
4141
import { log } from '../logging/logging';
4242
import { ReactionEvent } from './model/reactions';
43+
import { pidTreeUsage } from '../utils/pid_utils';
4344

4445

4546
/** @ignore */
@@ -1316,6 +1317,13 @@ public async testCallback(callbackToTest: SimpleListener, testData: any) : Prom
13161317
return await this._page.evaluate(() => WAPI.healthCheck());
13171318
}
13181319

1320+
/**
1321+
* Get the stats of the current process and the corresponding browser process.
1322+
*/
1323+
public async getProcessStats() : Promise<any> {
1324+
return await pidTreeUsage([process.pid, this._page.browser().process().pid])
1325+
}
1326+
13191327

13201328
/**
13211329
* A list of participants in the chat who have their live location on. If the chat does not exist, or the chat does not have any contacts actively sharing their live locations, it will return false. If it's a chat with a single contact, there will be only 1 value in the array if the contact has their livelocation on.

src/utils/pid_utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pidtree from 'pidtree'
2+
import pidusage from 'pidusage'
3+
4+
export const pidTreeUsage = async pid => {
5+
if(!Array.isArray(pid)) {
6+
pid = [pid]
7+
}
8+
const pids : number[] = (await Promise.all(pid.map(pidtree))).flat() as number[];
9+
const stats = await pidusage(pids)
10+
return stats;
11+
}

0 commit comments

Comments
 (0)