Skip to content

Commit

Permalink
✨ feat: client.getProcessStats() #2760
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Jun 24, 2022
1 parent 75c59f0 commit 35318bb
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 29 deletions.
119 changes: 91 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@
"husky": "^7.0.0",
"line-reader": "^0.4.0",
"marked": "^4.0.10",
"ts-json-schema-generator": "^v1.1.0-next.5",
"node-emoji": "^1.10.0",
"onchange": "^7.0.2",
"precise-commits": "^1.0.2",
"prettier": "^2.0.1",
"release-it": "^14.0.3",
"shelljs": "^0.8.3",
"tiny-glob": "^0.2.9",
"ts-json-schema-generator": "^v1.1.0-next.5",
"ts-node": "^10.0.0",
"tsc-watch": "^4.0.0",
"typeconv": "^1.7.0",
Expand Down Expand Up @@ -144,6 +144,8 @@
"parse-url": "^5.0.2",
"patch-package": "^6.2.2",
"pico-s3": "^1.0.1",
"pidtree": "^0.6.0",
"pidusage": "^3.0.0",
"postman-2-swagger": "^0.5.0",
"puppeteer": "15.0.0",
"puppeteer-extra": "^3.2.3",
Expand Down
8 changes: 8 additions & 0 deletions src/api/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { AdvancedButton, Button, LocationButtonBody, Section } from './model/but
import { JsonObject } from 'type-fest';
import { log } from '../logging/logging';
import { ReactionEvent } from './model/reactions';
import { pidTreeUsage } from '../utils/pid_utils';


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

/**
* Get the stats of the current process and the corresponding browser process.
*/
public async getProcessStats() : Promise<any> {
return await pidTreeUsage([process.pid, this._page.browser().process().pid])
}


/**
* 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.
Expand Down
11 changes: 11 additions & 0 deletions src/utils/pid_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pidtree from 'pidtree'
import pidusage from 'pidusage'

export const pidTreeUsage = async pid => {
if(!Array.isArray(pid)) {
pid = [pid]
}
const pids : number[] = (await Promise.all(pid.map(pidtree))).flat() as number[];
const stats = await pidusage(pids)
return stats;
}

0 comments on commit 35318bb

Please sign in to comment.