btake 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # insight
package/bin/index.js ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ const yargs = require('yargs')(process.argv.slice(2));
3
+ const lsofi = require('lsofi');
4
+ const systeminformation = require('systeminformation');
5
+ const { Inspector, ToolName } = require('../lib');
6
+
7
+ const commonOptions = {
8
+ p: {
9
+ alias: 'pid',
10
+ demandOption: false,
11
+ describe: 'target pid of your Node.js process.',
12
+ type: 'number',
13
+ },
14
+ a: {
15
+ alias: 'addr',
16
+ demandOption: false,
17
+ describe:
18
+ 'The inspect address of your Node.js process, e.g. 127.0.0.1:9229',
19
+ type: 'string',
20
+ },
21
+ };
22
+
23
+ const options = [];
24
+
25
+ options.push({
26
+ command: 'cpuprofile',
27
+ desc: `${ToolName} cpuprofile -p=<pid> [<args>]\ntake the cpu profile for a process.`,
28
+ optsFunc: (yargs) => {
29
+ yargs.options({
30
+ d: {
31
+ alias: 'duration',
32
+ demandOption: false,
33
+ describe: 'How long the profiling will last, unit: ms.',
34
+ default: 10000,
35
+ type: 'number',
36
+ },
37
+ ...commonOptions,
38
+ })
39
+ },
40
+ commandFunc: function (argv) {
41
+ new Inspector(argv).takeCpuProfile();
42
+ },
43
+ })
44
+
45
+ options.push({
46
+ command: 'heapsnapshot',
47
+ desc: `${ToolName} heapsnapshot -p=<pid> [<args>]\ntake the heapsnapshot of a process.`,
48
+ optsFunc: (yargs) => {
49
+ yargs.options({
50
+ ...commonOptions,
51
+ })
52
+ },
53
+ commandFunc: function (argv) {
54
+ new Inspector(argv).takeHeapSnapshot(argv);
55
+ },
56
+ })
57
+
58
+ options.push({
59
+ command: 'who',
60
+ desc: `${ToolName} who -p=<port> [<args>]\nwho is listening the port`,
61
+ optsFunc: (yargs) => {
62
+ yargs.options({
63
+ p: {
64
+ alias: 'port',
65
+ type: 'number',
66
+ },
67
+ })
68
+ },
69
+ commandFunc: async function (argv) {
70
+ try {
71
+ const pid = await lsofi(argv.port);
72
+ if (pid) {
73
+ console.log(`process(${pid}) is listening the port(${argv.port})`);
74
+ } else {
75
+ console.log(`no process is listening the port(${argv.port})`);
76
+ }
77
+ } catch(e) {
78
+ console.error(`${ToolName} error: err: ${e.message}`);
79
+ }
80
+ },
81
+ });
82
+
83
+ options.push({
84
+ command: 'port',
85
+ desc: `${ToolName} port p=<pid> [<args>]\ntake the tcp ports for process`,
86
+ optsFunc: (yargs) => {
87
+ yargs.options({
88
+ p: {
89
+ alias: 'pid',
90
+ type: 'number',
91
+ },
92
+ })
93
+ },
94
+ commandFunc: async function (argv) {
95
+ systeminformation.networkConnections(function(connections) {
96
+ const ports = connections
97
+ .filter(conn => {
98
+ return conn.pid === argv.pid && conn.protocol.startsWith('tcp') && conn.state === 'LISTEN';
99
+ }).map(conn => ({
100
+ host: conn.localAddress,
101
+ port: conn.localPort,
102
+ }));
103
+ console.log(`process(${argv.pid}) tcp listen ports: `, ports);
104
+ });
105
+ },
106
+ });
107
+
108
+
109
+ options.forEach((option) => {
110
+ const { commandFunc, desc, command, optsFunc } = option
111
+ yargs.command(command, desc, optsFunc, commandFunc)
112
+ })
113
+
114
+ yargs
115
+ .usage(`usage: ${ToolName} <command> [<args>]`)
116
+ .scriptName(ToolName)
117
+ .help()
118
+ .locale('en')
119
+ .demandCommand()
120
+ .strict()
121
+ .parse()
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const ToolName: any;
2
+ export declare class Inspector {
3
+ options: any;
4
+ constructor(options: any);
5
+ private openInspector;
6
+ private genFilename;
7
+ takeHeapSnapshot(): Promise<void>;
8
+ takeCpuProfile(): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,KAAO,CAAC;AA+B7B,qBAAa,SAAS;IAClB,OAAO,EAAE,GAAG,CAAC;gBAED,OAAO,EAAE,GAAG;IAiB3B,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,WAAW;IAQb,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAgBrC"}
package/lib/index.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Inspector = exports.ToolName = void 0;
16
+ const chrome_remote_interface_1 = __importDefault(require("chrome-remote-interface"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const path_1 = __importDefault(require("path"));
19
+ const { name } = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../package.json'), 'utf8'));
20
+ exports.ToolName = name;
21
+ const closeInspectorScript = `(function() {
22
+ try {
23
+ if (typeof process._debugEnd === 'function') {
24
+ process._debugEnd();
25
+ } else {
26
+ require('inspector').close();
27
+ }
28
+ } catch (e) {
29
+ }
30
+ })();`;
31
+ function sleep(ms) {
32
+ return new Promise(resolve => setTimeout(resolve, ms));
33
+ }
34
+ function retry(task, delay = 100, retries = 3) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ let lastError;
37
+ for (let i = 0; i < retries; i++) {
38
+ try {
39
+ return yield task();
40
+ }
41
+ catch (error) {
42
+ lastError = error;
43
+ yield sleep(delay);
44
+ }
45
+ }
46
+ throw lastError;
47
+ });
48
+ }
49
+ class Inspector {
50
+ constructor(options) {
51
+ this.options = options;
52
+ if (this.options.addr) {
53
+ const list = this.options.addr.split(':');
54
+ if (list.length >= 2) {
55
+ this.options.host = list[0];
56
+ this.options.port = Number(list[1]);
57
+ }
58
+ else {
59
+ this.options.host = 'localhost';
60
+ this.options.port = Number(list[0]);
61
+ }
62
+ }
63
+ else {
64
+ this.options.host = 'localhost';
65
+ this.options.port = 9229;
66
+ }
67
+ }
68
+ openInspector() {
69
+ try {
70
+ if (this.options.pid) {
71
+ // @ts-ignore
72
+ if (typeof process._debugProcess === 'function') {
73
+ // @ts-ignore
74
+ process._debugProcess(this.options.pid);
75
+ }
76
+ else {
77
+ process.kill(this.options.pid, 'SIGUSR1');
78
+ }
79
+ }
80
+ }
81
+ catch (e) {
82
+ console.error('open inspector failed: err', e.message);
83
+ }
84
+ }
85
+ genFilename(ext) {
86
+ if (this.options.pid) {
87
+ return `${name}_${this.options.pid}_${Date.now()}.${ext}`;
88
+ }
89
+ else {
90
+ return `${name}_${this.options.host}_${this.options.port}_${Date.now()}.${ext}`;
91
+ }
92
+ }
93
+ takeHeapSnapshot() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ this.openInspector();
96
+ retry(() => __awaiter(this, void 0, void 0, function* () {
97
+ const client = yield (0, chrome_remote_interface_1.default)({ port: this.options.port, host: this.options.host });
98
+ let chunk = '';
99
+ const handler = (data) => {
100
+ chunk += data.chunk;
101
+ };
102
+ client.on('HeapProfiler.addHeapSnapshotChunk', handler);
103
+ yield client.HeapProfiler.takeHeapSnapshot({});
104
+ // @ts-ignore
105
+ client.off('HeapProfiler.addHeapSnapshotChunk', handler);
106
+ yield client.Runtime.evaluate({
107
+ includeCommandLineAPI: true,
108
+ expression: closeInspectorScript,
109
+ }).catch(() => { });
110
+ fs_1.default.writeFileSync(this.genFilename('heapsnapshot'), chunk);
111
+ }));
112
+ });
113
+ }
114
+ takeCpuProfile() {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ this.openInspector();
117
+ retry(() => __awaiter(this, void 0, void 0, function* () {
118
+ const client = yield (0, chrome_remote_interface_1.default)({ port: this.options.port, host: this.options.host });
119
+ yield client.Profiler.enable();
120
+ yield client.Profiler.start();
121
+ yield sleep(this.options.duration || 1000);
122
+ const result = yield client.Profiler.stop();
123
+ yield client.Profiler.disable();
124
+ yield client.Runtime.evaluate({
125
+ includeCommandLineAPI: true,
126
+ expression: closeInspectorScript,
127
+ }).catch(() => { });
128
+ fs_1.default.writeFileSync(this.genFilename('cpuprofile'), JSON.stringify(result.profile));
129
+ }));
130
+ });
131
+ }
132
+ }
133
+ exports.Inspector = Inspector;
134
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sFAAyC;AACzC,4CAAoB;AACpB,gDAAwB;AAExB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjF,QAAA,QAAQ,GAAG,IAAI,CAAC;AAE7B,MAAM,oBAAoB,GAAG;;;;;;;;;MASvB,CAAC;AAEP,SAAS,KAAK,CAAC,EAAU;IACxB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACxD,CAAC;AAEA,SAAe,KAAK,CAAI,IAAsB,EAAE,KAAK,GAAG,GAAG,EAAE,OAAO,GAAG,CAAC;;QACxE,IAAI,SAAc,CAAC;QACnB,KAAK,IAAI,CAAC,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package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "btake",
3
+ "version": "0.0.1",
4
+ "description": "a tool for taking node.js profile",
5
+ "main": "/lib/index.js",
6
+ "bin": {
7
+ "btake": "./bin/index.js"
8
+ },
9
+ "scripts": {
10
+ "publish": "npm run build && npm publish",
11
+ "beta": "npm run build && npm publish --tag beta",
12
+ "dev": "tsc -w",
13
+ "build": "rm -rf lib && tsc"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/theanarkh/btake.git"
18
+ },
19
+ "author": "theanarkh",
20
+ "license": "ISC",
21
+ "bugs": {
22
+ "url": "https://github.com/theanarkh/btake/issues"
23
+ },
24
+ "homepage": "https://github.com/theanarkh/btake#readme",
25
+ "dependencies": {
26
+ "chrome-remote-interface": "^0.33.3",
27
+ "lsofi": "^1.0.0",
28
+ "systeminformation": "^5.30.1",
29
+ "yargs": "^14.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/chrome-remote-interface": "^0.33.0",
33
+ "@types/node": "^25.0.3"
34
+ }
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,118 @@
1
+ import CDP from 'chrome-remote-interface'
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ const { name } = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
6
+
7
+ export const ToolName = name;
8
+
9
+ const closeInspectorScript = `(function() {
10
+ try {
11
+ if (typeof process._debugEnd === 'function') {
12
+ process._debugEnd();
13
+ } else {
14
+ require('inspector').close();
15
+ }
16
+ } catch (e) {
17
+ }
18
+ })();`;
19
+
20
+ function sleep(ms: number) {
21
+ return new Promise(resolve => setTimeout(resolve, ms));
22
+ }
23
+
24
+ async function retry<T>(task: () => Promise<T>, delay = 100, retries = 3): Promise<T> {
25
+ let lastError: any;
26
+ for (let i = 0; i < retries; i++) {
27
+ try {
28
+ return await task();
29
+ } catch (error) {
30
+ lastError = error;
31
+ await sleep(delay);
32
+ }
33
+ }
34
+
35
+ throw lastError;
36
+ }
37
+
38
+ export class Inspector {
39
+ options: any;
40
+
41
+ constructor(options: any) {
42
+ this.options = options;
43
+ if (this.options.addr) {
44
+ const list = this.options.addr.split(':');
45
+ if (list.length >= 2) {
46
+ this.options.host = list[0];
47
+ this.options.port = Number(list[1]);
48
+ } else {
49
+ this.options.host = 'localhost';
50
+ this.options.port = Number(list[0]);
51
+ }
52
+ } else {
53
+ this.options.host = 'localhost';
54
+ this.options.port = 9229;
55
+ }
56
+ }
57
+
58
+ private openInspector() {
59
+ try {
60
+ if (this.options.pid) {
61
+ // @ts-ignore
62
+ if (typeof process._debugProcess === 'function') {
63
+ // @ts-ignore
64
+ process._debugProcess(this.options.pid);
65
+ } else {
66
+ process.kill(this.options.pid as number, 'SIGUSR1');
67
+ }
68
+ }
69
+ } catch (e) {
70
+ console.error('open inspector failed: err', (e as Error).message);
71
+ }
72
+ }
73
+
74
+ private genFilename(ext: string) {
75
+ if (this.options.pid) {
76
+ return `${name}_${this.options.pid}_${Date.now()}.${ext}`;
77
+ } else {
78
+ return `${name}_${this.options.host}_${this.options.port}_${Date.now()}.${ext}`;
79
+ }
80
+ }
81
+
82
+ async takeHeapSnapshot(): Promise<void> {
83
+ this.openInspector();
84
+ retry(async () => {
85
+ const client = await CDP({ port: this.options.port, host: this.options.host });
86
+ let chunk = '';
87
+ const handler = (data: { chunk: string }) => {
88
+ chunk += data.chunk;
89
+ };
90
+ client.on('HeapProfiler.addHeapSnapshotChunk', handler);
91
+ await client.HeapProfiler.takeHeapSnapshot({});
92
+ // @ts-ignore
93
+ client.off('HeapProfiler.addHeapSnapshotChunk', handler);
94
+ await client.Runtime.evaluate({
95
+ includeCommandLineAPI: true,
96
+ expression: closeInspectorScript,
97
+ }).catch(() => { });
98
+ fs.writeFileSync(this.genFilename('heapsnapshot'), chunk);
99
+ });
100
+ }
101
+
102
+ async takeCpuProfile(): Promise<void> {
103
+ this.openInspector();
104
+ retry(async () => {
105
+ const client = await CDP({ port: this.options.port, host: this.options.host });
106
+ await client.Profiler.enable();
107
+ await client.Profiler.start();
108
+ await sleep(this.options.duration || 1000);
109
+ const result = await client.Profiler.stop();
110
+ await client.Profiler.disable();
111
+ await client.Runtime.evaluate({
112
+ includeCommandLineAPI: true,
113
+ expression: closeInspectorScript,
114
+ }).catch(() => { });
115
+ fs.writeFileSync(this.genFilename('cpuprofile'), JSON.stringify(result.profile));
116
+ });
117
+ }
118
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ "module": "nodenext",
5
+ "target": "es6",
6
+ "types": ["node"],
7
+ "sourceMap": true,
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "exactOptionalPropertyTypes": true,
12
+ "strict": true,
13
+ "isolatedModules": true,
14
+ "moduleDetection": "force",
15
+ "skipLibCheck": true,
16
+ "outDir": "./lib",
17
+ }
18
+ }