@memlab/core 1.0.0

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.
Files changed (130) hide show
  1. package/README.md +11 -0
  2. package/dist/__tests__/parser/HeapParser.test.d.ts +11 -0
  3. package/dist/__tests__/parser/HeapParser.test.d.ts.map +1 -0
  4. package/dist/__tests__/parser/HeapParser.test.js +54 -0
  5. package/dist/__tests__/parser/NodeHeap.test.d.ts +11 -0
  6. package/dist/__tests__/parser/NodeHeap.test.d.ts.map +1 -0
  7. package/dist/__tests__/parser/NodeHeap.test.js +96 -0
  8. package/dist/__tests__/parser/StringNode.test.d.ts +11 -0
  9. package/dist/__tests__/parser/StringNode.test.d.ts.map +1 -0
  10. package/dist/__tests__/parser/StringNode.test.js +61 -0
  11. package/dist/__tests__/parser/traverse/HeapNodeTraverse.test.d.ts +16 -0
  12. package/dist/__tests__/parser/traverse/HeapNodeTraverse.test.d.ts.map +1 -0
  13. package/dist/__tests__/parser/traverse/HeapNodeTraverse.test.js +140 -0
  14. package/dist/__tests__/utils/utils.test.d.ts +11 -0
  15. package/dist/__tests__/utils/utils.test.d.ts.map +1 -0
  16. package/dist/__tests__/utils/utils.test.js +81 -0
  17. package/dist/index.d.ts +29 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +62 -0
  20. package/dist/lib/BaseOption.d.ts +31 -0
  21. package/dist/lib/BaseOption.d.ts.map +1 -0
  22. package/dist/lib/BaseOption.js +109 -0
  23. package/dist/lib/BrowserInfo.d.ts +33 -0
  24. package/dist/lib/BrowserInfo.d.ts.map +1 -0
  25. package/dist/lib/BrowserInfo.js +117 -0
  26. package/dist/lib/Config.d.ts +203 -0
  27. package/dist/lib/Config.d.ts.map +1 -0
  28. package/dist/lib/Config.js +427 -0
  29. package/dist/lib/Console.d.ts +67 -0
  30. package/dist/lib/Console.d.ts.map +1 -0
  31. package/dist/lib/Console.js +344 -0
  32. package/dist/lib/Constant.d.ts +38 -0
  33. package/dist/lib/Constant.d.ts.map +1 -0
  34. package/dist/lib/Constant.js +58 -0
  35. package/dist/lib/FileManager.d.ts +69 -0
  36. package/dist/lib/FileManager.d.ts.map +1 -0
  37. package/dist/lib/FileManager.js +309 -0
  38. package/dist/lib/HeapAnalyzer.d.ts +51 -0
  39. package/dist/lib/HeapAnalyzer.d.ts.map +1 -0
  40. package/dist/lib/HeapAnalyzer.js +719 -0
  41. package/dist/lib/HeapParser.d.ts +19 -0
  42. package/dist/lib/HeapParser.d.ts.map +1 -0
  43. package/dist/lib/HeapParser.js +128 -0
  44. package/dist/lib/InternalValueSetter.d.ts +14 -0
  45. package/dist/lib/InternalValueSetter.d.ts.map +1 -0
  46. package/dist/lib/InternalValueSetter.js +43 -0
  47. package/dist/lib/NodeHeap.d.ts +16 -0
  48. package/dist/lib/NodeHeap.d.ts.map +1 -0
  49. package/dist/lib/NodeHeap.js +62 -0
  50. package/dist/lib/ProcessManager.d.ts +25 -0
  51. package/dist/lib/ProcessManager.d.ts.map +1 -0
  52. package/dist/lib/ProcessManager.js +67 -0
  53. package/dist/lib/Serializer.d.ts +49 -0
  54. package/dist/lib/Serializer.d.ts.map +1 -0
  55. package/dist/lib/Serializer.js +702 -0
  56. package/dist/lib/StringLoader.d.ts +26 -0
  57. package/dist/lib/StringLoader.d.ts.map +1 -0
  58. package/dist/lib/StringLoader.js +290 -0
  59. package/dist/lib/Types.d.ts +432 -0
  60. package/dist/lib/Types.d.ts.map +1 -0
  61. package/dist/lib/Types.js +11 -0
  62. package/dist/lib/Utils.d.ts +223 -0
  63. package/dist/lib/Utils.d.ts.map +1 -0
  64. package/dist/lib/Utils.js +1736 -0
  65. package/dist/lib/heap-data/HeapEdge.d.ts +27 -0
  66. package/dist/lib/heap-data/HeapEdge.d.ts.map +1 -0
  67. package/dist/lib/heap-data/HeapEdge.js +75 -0
  68. package/dist/lib/heap-data/HeapLocation.d.ts +22 -0
  69. package/dist/lib/heap-data/HeapLocation.d.ts.map +1 -0
  70. package/dist/lib/heap-data/HeapLocation.js +40 -0
  71. package/dist/lib/heap-data/HeapNode.d.ts +55 -0
  72. package/dist/lib/heap-data/HeapNode.d.ts.map +1 -0
  73. package/dist/lib/heap-data/HeapNode.js +344 -0
  74. package/dist/lib/heap-data/HeapSnapshot.d.ts +85 -0
  75. package/dist/lib/heap-data/HeapSnapshot.d.ts.map +1 -0
  76. package/dist/lib/heap-data/HeapSnapshot.js +462 -0
  77. package/dist/lib/heap-data/HeapStringNode.d.ts +18 -0
  78. package/dist/lib/heap-data/HeapStringNode.d.ts.map +1 -0
  79. package/dist/lib/heap-data/HeapStringNode.js +43 -0
  80. package/dist/lib/heap-data/HeapUtils.d.ts +17 -0
  81. package/dist/lib/heap-data/HeapUtils.d.ts.map +1 -0
  82. package/dist/lib/heap-data/HeapUtils.js +25 -0
  83. package/dist/logger/LeakClusterLogger.d.ts +40 -0
  84. package/dist/logger/LeakClusterLogger.d.ts.map +1 -0
  85. package/dist/logger/LeakClusterLogger.js +228 -0
  86. package/dist/logger/LeakTraceDetailsLogger.d.ts +19 -0
  87. package/dist/logger/LeakTraceDetailsLogger.d.ts.map +1 -0
  88. package/dist/logger/LeakTraceDetailsLogger.js +50 -0
  89. package/dist/modes/BaseMode.d.ts +30 -0
  90. package/dist/modes/BaseMode.d.ts.map +1 -0
  91. package/dist/modes/BaseMode.js +95 -0
  92. package/dist/modes/InteractionTestMode.d.ts +23 -0
  93. package/dist/modes/InteractionTestMode.d.ts.map +1 -0
  94. package/dist/modes/InteractionTestMode.js +46 -0
  95. package/dist/modes/MeasureMode.d.ts +23 -0
  96. package/dist/modes/MeasureMode.d.ts.map +1 -0
  97. package/dist/modes/MeasureMode.js +58 -0
  98. package/dist/modes/RunningModes.d.ts +15 -0
  99. package/dist/modes/RunningModes.d.ts.map +1 -0
  100. package/dist/modes/RunningModes.js +40 -0
  101. package/dist/paths/TraceFinder.d.ts +31 -0
  102. package/dist/paths/TraceFinder.d.ts.map +1 -0
  103. package/dist/paths/TraceFinder.js +537 -0
  104. package/dist/trace-cluster/ClusterUtils.d.ts +14 -0
  105. package/dist/trace-cluster/ClusterUtils.d.ts.map +1 -0
  106. package/dist/trace-cluster/ClusterUtils.js +17 -0
  107. package/dist/trace-cluster/ClusterUtilsHelper.d.ts +38 -0
  108. package/dist/trace-cluster/ClusterUtilsHelper.d.ts.map +1 -0
  109. package/dist/trace-cluster/ClusterUtilsHelper.js +373 -0
  110. package/dist/trace-cluster/ClusteringHeuristics.d.ts +22 -0
  111. package/dist/trace-cluster/ClusteringHeuristics.d.ts.map +1 -0
  112. package/dist/trace-cluster/ClusteringHeuristics.js +23 -0
  113. package/dist/trace-cluster/EvalutationMetric.d.ts +22 -0
  114. package/dist/trace-cluster/EvalutationMetric.d.ts.map +1 -0
  115. package/dist/trace-cluster/EvalutationMetric.js +158 -0
  116. package/dist/trace-cluster/TraceBucket.d.ts +36 -0
  117. package/dist/trace-cluster/TraceBucket.d.ts.map +1 -0
  118. package/dist/trace-cluster/TraceBucket.js +238 -0
  119. package/dist/trace-cluster/TraceElement.d.ts +71 -0
  120. package/dist/trace-cluster/TraceElement.d.ts.map +1 -0
  121. package/dist/trace-cluster/TraceElement.js +182 -0
  122. package/dist/trace-cluster/strategies/TraceAsClusterStrategy.d.ts +15 -0
  123. package/dist/trace-cluster/strategies/TraceAsClusterStrategy.d.ts.map +1 -0
  124. package/dist/trace-cluster/strategies/TraceAsClusterStrategy.js +37 -0
  125. package/dist/trace-cluster/strategies/TraceSimilarityStrategy.d.ts +15 -0
  126. package/dist/trace-cluster/strategies/TraceSimilarityStrategy.d.ts.map +1 -0
  127. package/dist/trace-cluster/strategies/TraceSimilarityStrategy.js +60 -0
  128. package/package.json +60 -0
  129. package/static/run-meta.json +10 -0
  130. package/static/visit-order.json +27 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @lightSyntaxTransform
9
+ * @format
10
+ */
11
+ import type { IHeapSnapshot } from './Types';
12
+ declare function getNodeIdsFromFile(file: string, _options?: {}): Promise<Set<number>>;
13
+ declare function parse(file: string, options?: {}): Promise<IHeapSnapshot>;
14
+ declare const _default: {
15
+ getNodeIdsFromFile: typeof getNodeIdsFromFile;
16
+ parse: typeof parse;
17
+ };
18
+ export default _default;
19
+ //# sourceMappingURL=HeapParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HeapParser.d.ts","sourceRoot":"","sources":["../../src/lib/HeapParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,SAAS,CAAC;AAyCjB,iBAAe,kBAAkB,CAC/B,IAAI,EAAE,MAAM,EAEZ,QAAQ,KAAK,GACZ,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAatB;AA+CD,iBAAe,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAKvE;;;;;AAED,wBAGE"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @lightSyntaxTransform
9
+ * @format
10
+ */
11
+ 'use strict';
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const Config_1 = __importDefault(require("./Config"));
26
+ const Console_1 = __importDefault(require("./Console"));
27
+ const StringLoader_1 = __importDefault(require("./StringLoader"));
28
+ const HeapSnapshot_1 = __importDefault(require("./heap-data/HeapSnapshot"));
29
+ // ----------- utility and parsing functions -----------
30
+ function getSnapshotMetaData(content) {
31
+ function getSignatureIndex(signature) {
32
+ const idx = content.indexOf(signature);
33
+ if (idx < 0) {
34
+ throw 'heap parsing: meta data parsing error';
35
+ }
36
+ return idx;
37
+ }
38
+ const startSignature = '"snapshot":';
39
+ const startIdx = getSignatureIndex(startSignature) + startSignature.length;
40
+ const endSignature = '"nodes":';
41
+ const endIdx = getSignatureIndex(endSignature);
42
+ const metaContent = content.slice(startIdx, endIdx).trim().slice(0, -1);
43
+ return JSON.parse(metaContent);
44
+ }
45
+ const nums = Object.create(null);
46
+ for (let i = 0; i < 10; i++) {
47
+ nums[`${i}`] = i;
48
+ }
49
+ function loadSnapshotMetaDataFromFile(file) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const content = yield StringLoader_1.default.readFile(file, {
52
+ startSignature: '"snapshot":',
53
+ endSignature: '"nodes":',
54
+ inclusive: true,
55
+ });
56
+ return getSnapshotMetaData(content);
57
+ });
58
+ }
59
+ function getNodeIdsFromFile(file,
60
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
+ _options = {}) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const snapshotInfo = yield loadSnapshotMetaDataFromFile(file);
64
+ const nodes = yield StringLoader_1.default.readFileAndExtractTypedArray(file, 'nodes');
65
+ const ids = new Set();
66
+ const nodeFields = snapshotInfo.meta.node_fields;
67
+ const nodeFieldCount = nodeFields.length;
68
+ const idOffset = nodeFields.indexOf('id');
69
+ let valueIndex = 0;
70
+ while (valueIndex < nodes.length) {
71
+ ids.add(nodes[valueIndex + idOffset]);
72
+ valueIndex += nodeFieldCount;
73
+ }
74
+ return ids;
75
+ });
76
+ }
77
+ function parseFile(file) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const [nodes, edges, locations, content] = yield Promise.all([
80
+ StringLoader_1.default.readFileAndExtractTypedArray(file, 'nodes'),
81
+ StringLoader_1.default.readFileAndExtractTypedArray(file, 'edges'),
82
+ StringLoader_1.default.readFileAndExtractTypedArray(file, 'locations'),
83
+ StringLoader_1.default.readFileAndExcludeTypedArray(file, [
84
+ 'nodes',
85
+ 'edges',
86
+ 'locations',
87
+ ]),
88
+ ]);
89
+ const snapshot = JSON.parse(content);
90
+ snapshot.nodes = nodes;
91
+ snapshot.edges = edges;
92
+ snapshot.locations = locations;
93
+ return snapshot;
94
+ });
95
+ }
96
+ // auto detect and set JS snapshot's engine type
97
+ function identifyAndSetEngine(snapshot) {
98
+ if (Config_1.default.specifiedEngine) {
99
+ if (Config_1.default.verbose) {
100
+ Console_1.default.lowLevel(`JS snapshot engine is manually set to be ${Config_1.default.jsEngine}`);
101
+ }
102
+ return; // skip if engine type is manually set
103
+ }
104
+ Console_1.default.overwrite('identifying snapshot engine...');
105
+ let engine = 'v8';
106
+ snapshot.nodes.forEach((node) => {
107
+ if (node.type === 'object' && node.name.startsWith('Object(')) {
108
+ engine = 'hermes';
109
+ return false;
110
+ }
111
+ });
112
+ if (Config_1.default.verbose) {
113
+ Console_1.default.lowLevel(`detect and set JS snapshot engine: ${engine}`);
114
+ }
115
+ Config_1.default.jsEngine = engine;
116
+ }
117
+ function parse(file, options = {}) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const snapshot = yield parseFile(file);
120
+ const ret = new HeapSnapshot_1.default(snapshot, options);
121
+ identifyAndSetEngine(ret);
122
+ return ret;
123
+ });
124
+ }
125
+ exports.default = {
126
+ getNodeIdsFromFile,
127
+ parse,
128
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ export declare abstract class InternalValueSetter<T> {
11
+ fillIn(_module: T): T;
12
+ }
13
+ export declare function setInternalValue<T>(value: T, callerFilePath: string, internalFolderName: string): T;
14
+ //# sourceMappingURL=InternalValueSetter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InternalValueSetter.d.ts","sourceRoot":"","sources":["../../src/lib/InternalValueSetter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,8BAAsB,mBAAmB,CAAC,CAAC;IAEzC,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC;CAGtB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,CAAC,EACR,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,GACzB,CAAC,CAmBH"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
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.setInternalValue = exports.InternalValueSetter = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ class InternalValueSetter {
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
+ fillIn(_module) {
21
+ throw new Error('InternalValueSetter.fillIn is not implemented');
22
+ }
23
+ }
24
+ exports.InternalValueSetter = InternalValueSetter;
25
+ function setInternalValue(value, callerFilePath, internalFolderName) {
26
+ const callerDir = path_1.default.dirname(callerFilePath);
27
+ const callerFile = path_1.default.basename(callerFilePath);
28
+ const internalDir = path_1.default.join(callerDir, internalFolderName);
29
+ const internalModulePath = path_1.default.join(internalDir, callerFile);
30
+ if (!fs_1.default.existsSync(internalModulePath)) {
31
+ return value;
32
+ }
33
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
34
+ const module = require(internalModulePath);
35
+ const Constructor = typeof module.default === 'function' ? module.default : module;
36
+ const setter = new Constructor();
37
+ if (typeof setter.fillIn !== 'function') {
38
+ return value;
39
+ }
40
+ const valueSetter = setter;
41
+ return valueSetter.fillIn(value);
42
+ }
43
+ exports.setInternalValue = setInternalValue;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import type { AnyValue, IHeapSnapshot } from './Types';
11
+ declare type AnyObject = Record<AnyValue, AnyValue>;
12
+ export declare function tagObject(o: AnyObject, tag: string): AnyObject;
13
+ export declare function dumpNodeHeapSnapshot(): string;
14
+ export declare function getCurrentNodeHeap(): Promise<IHeapSnapshot>;
15
+ export {};
16
+ //# sourceMappingURL=NodeHeap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeHeap.d.ts","sourceRoot":"","sources":["../../src/lib/NodeHeap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAQrD,aAAK,SAAS,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAU5C,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAM9D;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAO7C;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,aAAa,CAAC,CASjE"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.getCurrentNodeHeap = exports.dumpNodeHeapSnapshot = exports.tagObject = void 0;
25
+ const fs_extra_1 = __importDefault(require("fs-extra"));
26
+ const path_1 = __importDefault(require("path"));
27
+ const v8_1 = __importDefault(require("v8"));
28
+ const FileManager_1 = __importDefault(require("./FileManager"));
29
+ const Utils_1 = __importDefault(require("./Utils"));
30
+ class MemLabTaggedStore {
31
+ constructor() {
32
+ this.taggedObjects = Object.create(null);
33
+ }
34
+ }
35
+ const store = new MemLabTaggedStore();
36
+ function tagObject(o, tag) {
37
+ if (!store.taggedObjects[tag]) {
38
+ store.taggedObjects[tag] = new WeakSet();
39
+ }
40
+ store.taggedObjects[tag].add(o);
41
+ return o;
42
+ }
43
+ exports.tagObject = tagObject;
44
+ function dumpNodeHeapSnapshot() {
45
+ const file = path_1.default.join(FileManager_1.default.generateTmpHeapDir(), `nodejs.heapsnapshot`);
46
+ v8_1.default.writeHeapSnapshot(file);
47
+ return file;
48
+ }
49
+ exports.dumpNodeHeapSnapshot = dumpNodeHeapSnapshot;
50
+ function getCurrentNodeHeap() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const file = dumpNodeHeapSnapshot();
53
+ const snapshot = yield Utils_1.default.getSnapshotFromFile(file, {
54
+ buildNodeIdIndex: true,
55
+ });
56
+ fs_extra_1.default.unlink(file, () => {
57
+ // do nothing
58
+ });
59
+ return snapshot;
60
+ });
61
+ }
62
+ exports.getCurrentNodeHeap = getCurrentNodeHeap;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import type { Command, Optional } from './Types';
11
+ declare type Options = {
12
+ msg?: string;
13
+ processLimit?: number;
14
+ };
15
+ declare class ProcessManager {
16
+ private procLimit;
17
+ private nProc;
18
+ start(nextCommand: () => Optional<Command>, options?: Options): void;
19
+ private init;
20
+ private hasFreeProcess;
21
+ private freeProcess;
22
+ private runInProcess;
23
+ }
24
+ export default ProcessManager;
25
+ //# sourceMappingURL=ProcessManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProcessManager.d.ts","sourceRoot":"","sources":["../../src/lib/ProcessManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAM/C,aAAK,OAAO,GAAG;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAIF,cAAM,cAAc;IAClB,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,KAAK,CAAK;IAGX,KAAK,CACV,WAAW,EAAE,MAAM,QAAQ,CAAC,OAAO,CAAC,EACpC,OAAO,GAAE,OAAY,GACpB,IAAI;IAeP,OAAO,CAAC,IAAI;IAMZ,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,YAAY;CAmBrB;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
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
+ const Console_1 = __importDefault(require("./Console"));
16
+ const child_process_1 = __importDefault(require("child_process"));
17
+ const os_1 = __importDefault(require("os"));
18
+ const DEFAULT_PROCESS_LIMIT = 1;
19
+ class ProcessManager {
20
+ constructor() {
21
+ this.procLimit = DEFAULT_PROCESS_LIMIT;
22
+ this.nProc = 0;
23
+ }
24
+ // 1. periodically check for available free process
25
+ // 2. start commands in process until all tasks are completed
26
+ start(nextCommand, options = {}) {
27
+ this.init(options);
28
+ const timer = setInterval(() => {
29
+ if (!this.hasFreeProcess()) {
30
+ return;
31
+ }
32
+ const cmd = nextCommand();
33
+ // if next command is empty, stop the loop
34
+ if (!cmd) {
35
+ return clearInterval(timer);
36
+ }
37
+ this.runInProcess(...cmd);
38
+ }, 100);
39
+ }
40
+ init(options = {}) {
41
+ this.procLimit = options.processLimit
42
+ ? options.processLimit
43
+ : (os_1.default.cpus().length / 9) | 0;
44
+ }
45
+ hasFreeProcess() {
46
+ return this.nProc < this.procLimit;
47
+ }
48
+ freeProcess() {
49
+ this.nProc--;
50
+ }
51
+ runInProcess(cmd, args, options = {}) {
52
+ if (options.msg) {
53
+ Console_1.default.lowLevel(options.msg);
54
+ }
55
+ const str = [cmd, ...args].join(' ');
56
+ this.nProc++;
57
+ const proc = child_process_1.default.spawn(cmd, args);
58
+ proc.on('exit', code => {
59
+ Console_1.default.lowLevel(`done: ${str}`);
60
+ if (code !== 0) {
61
+ Console_1.default.error(`fail: ${str}`);
62
+ }
63
+ this.freeProcess();
64
+ });
65
+ }
66
+ }
67
+ exports.default = ProcessManager;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import { E2EStepInfo, HeapNodeIdSet, IHeapEdge, IHeapNode, IHeapSnapshot, ISerializedInfo, LeakTracePathItem, Nullable } from './Types';
11
+ declare type JSONifyArgs = {
12
+ leakedIdSet?: Set<number>;
13
+ nodeIdsInSnapshots?: Array<Set<number>>;
14
+ };
15
+ declare function JSONifyPath(path: LeakTracePathItem, _snapshot: IHeapSnapshot, args: JSONifyArgs): Nullable<ISerializedInfo>;
16
+ declare type SummarizeOptions = {
17
+ compact?: boolean;
18
+ color?: boolean;
19
+ progress?: number;
20
+ abstract?: boolean;
21
+ depth?: number;
22
+ excludeKeySet?: HeapNodeIdSet;
23
+ };
24
+ declare function summarizeNodeShape(node: IHeapNode, options?: SummarizeOptions): string;
25
+ declare type UnboundedObjectInfo = {
26
+ id: number;
27
+ name: string;
28
+ node: IHeapNode;
29
+ type: string;
30
+ history: number[];
31
+ };
32
+ declare function summarizeUnboundedObjects(unboundedObjects: UnboundedObjectInfo[], options?: SummarizeOptions): string;
33
+ declare function summarizeUnboundedObjectsToCSV(unboundedObjects: UnboundedObjectInfo[]): string;
34
+ declare function summarizeTabsOrder(tabsOrder: E2EStepInfo[], options?: SummarizeOptions): string;
35
+ declare function summarizeNodeName(node: IHeapNode, options: SummarizeOptions): string;
36
+ declare function summarizeEdgeName(edge: IHeapEdge, options?: SummarizeOptions): string;
37
+ declare function summarizePath(pathArg: LeakTracePathItem, nodeIdInPaths: Set<number>, snapshot: IHeapSnapshot, options?: SummarizeOptions): string;
38
+ declare const _default: {
39
+ JSONifyPath: typeof JSONifyPath;
40
+ summarizeEdgeName: typeof summarizeEdgeName;
41
+ summarizeNodeName: typeof summarizeNodeName;
42
+ summarizeNodeShape: typeof summarizeNodeShape;
43
+ summarizePath: typeof summarizePath;
44
+ summarizeTabsOrder: typeof summarizeTabsOrder;
45
+ summarizeUnboundedObjects: typeof summarizeUnboundedObjects;
46
+ summarizeUnboundedObjectsToCSV: typeof summarizeUnboundedObjectsToCSV;
47
+ };
48
+ export default _default;
49
+ //# sourceMappingURL=Serializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serializer.d.ts","sourceRoot":"","sources":["../../src/lib/Serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,QAAQ,EAET,MAAM,SAAS,CAAC;AAajB,aAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,kBAAkB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACzC,CAAC;AAwYF,iBAAS,WAAW,CAClB,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,WAAW,GAChB,QAAQ,CAAC,eAAe,CAAC,CAkC3B;AA+ID,aAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AA6BF,iBAAS,kBAAkB,CACzB,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CASR;AAED,aAAK,mBAAmB,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,iBAAS,yBAAyB,CAChC,gBAAgB,EAAE,mBAAmB,EAAE,EACvC,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAcR;AAED,iBAAS,8BAA8B,CACrC,gBAAgB,EAAE,mBAAmB,EAAE,GACtC,MAAM,CAMR;AAiBD,iBAAS,kBAAkB,CACzB,SAAS,EAAE,WAAW,EAAE,EACxB,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAuBR;AAED,iBAAS,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAI7E;AAoBD,iBAAS,iBAAiB,CACxB,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAeR;AAkBD,iBAAS,aAAa,CACpB,OAAO,EAAE,iBAAiB,EAC1B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,EAC1B,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CA2ER;;;;;;;;;;;AAED,wBASE"}