traceperf 0.1.0 → 0.1.2
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 +110 -1
- package/dist/browser.d.ts +67 -5
- package/dist/browser.js +207 -36
- package/dist/browser.js.map +1 -1
- package/dist/esm/browser.d.ts +129 -0
- package/dist/esm/browser.js +426 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/core/config.d.ts +77 -0
- package/dist/esm/core/config.js +112 -0
- package/dist/esm/core/config.js.map +1 -0
- package/dist/esm/core/constants.d.ts +78 -0
- package/dist/esm/core/constants.js +106 -0
- package/dist/esm/core/constants.js.map +1 -0
- package/dist/esm/core/index.d.ts +3 -0
- package/dist/esm/core/index.js +4 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/logger.d.ts +84 -0
- package/dist/esm/core/logger.js +170 -0
- package/dist/esm/core/logger.js.map +1 -0
- package/dist/esm/formatters/ascii.d.ts +52 -0
- package/dist/esm/formatters/ascii.js +100 -0
- package/dist/esm/formatters/ascii.js.map +1 -0
- package/dist/esm/formatters/cli.d.ts +50 -0
- package/dist/esm/formatters/cli.js +96 -0
- package/dist/esm/formatters/cli.js.map +1 -0
- package/dist/esm/formatters/index.d.ts +3 -0
- package/dist/esm/formatters/index.js +4 -0
- package/dist/esm/formatters/index.js.map +1 -0
- package/dist/esm/formatters/json.d.ts +45 -0
- package/dist/esm/formatters/json.js +85 -0
- package/dist/esm/formatters/json.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/trackers/execution.d.ts +88 -0
- package/dist/esm/trackers/execution.js +214 -0
- package/dist/esm/trackers/execution.js.map +1 -0
- package/dist/esm/trackers/index.d.ts +2 -0
- package/dist/esm/trackers/index.js +3 -0
- package/dist/esm/trackers/index.js.map +1 -0
- package/dist/esm/trackers/performance.d.ts +82 -0
- package/dist/esm/trackers/performance.js +106 -0
- package/dist/esm/trackers/performance.js.map +1 -0
- package/dist/esm/types/config.d.ts +110 -0
- package/dist/esm/types/config.js +2 -0
- package/dist/esm/types/config.js.map +1 -0
- package/dist/esm/types/index.d.ts +34 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/logger.d.ts +127 -0
- package/dist/esm/types/logger.js +2 -0
- package/dist/esm/types/logger.js.map +1 -0
- package/dist/esm/utils/colors.d.ts +87 -0
- package/dist/esm/utils/colors.js +134 -0
- package/dist/esm/utils/colors.js.map +1 -0
- package/dist/esm/utils/index.d.ts +3 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/stack.d.ts +63 -0
- package/dist/esm/utils/stack.js +110 -0
- package/dist/esm/utils/stack.js.map +1 -0
- package/dist/esm/utils/timing.d.ts +65 -0
- package/dist/esm/utils/timing.js +99 -0
- package/dist/esm/utils/timing.js.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/trackers/execution.d.ts +23 -7
- package/dist/trackers/execution.js +100 -29
- package/dist/trackers/execution.js.map +1 -1
- package/dist/types/config.js +2 -1
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.js +18 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/logger.js +2 -1
- package/package.json +16 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-resolution timing utilities for performance tracking
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get the current high-resolution time
|
|
6
|
+
*
|
|
7
|
+
* @returns The current high-resolution time
|
|
8
|
+
*/
|
|
9
|
+
export function getHighResTime() {
|
|
10
|
+
return process.hrtime();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Calculate the duration between a start time and now
|
|
14
|
+
*
|
|
15
|
+
* @param startTime - The start time from getHighResTime()
|
|
16
|
+
* @returns The duration in milliseconds
|
|
17
|
+
*/
|
|
18
|
+
export function getDuration(startTime) {
|
|
19
|
+
const [seconds, nanoseconds] = process.hrtime(startTime);
|
|
20
|
+
return seconds * 1000 + nanoseconds / 1000000;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Format a duration in milliseconds to a human-readable string
|
|
24
|
+
*
|
|
25
|
+
* @param duration - The duration in milliseconds
|
|
26
|
+
* @returns A formatted string (e.g., "1.23ms", "1.23s")
|
|
27
|
+
*/
|
|
28
|
+
export function formatDuration(duration) {
|
|
29
|
+
if (duration < 1) {
|
|
30
|
+
return `${(duration * 1000).toFixed(2)}μs`;
|
|
31
|
+
}
|
|
32
|
+
else if (duration < 1000) {
|
|
33
|
+
return `${duration.toFixed(2)}ms`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return `${(duration / 1000).toFixed(2)}s`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A simple timer class for measuring durations
|
|
41
|
+
*/
|
|
42
|
+
export class Timer {
|
|
43
|
+
/**
|
|
44
|
+
* Create a new Timer instance
|
|
45
|
+
*
|
|
46
|
+
* @param label - A label for the timer
|
|
47
|
+
*/
|
|
48
|
+
constructor(label) {
|
|
49
|
+
this._endTime = null;
|
|
50
|
+
this._startTime = getHighResTime();
|
|
51
|
+
this._label = label;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Stop the timer
|
|
55
|
+
*
|
|
56
|
+
* @returns The duration in milliseconds
|
|
57
|
+
*/
|
|
58
|
+
stop() {
|
|
59
|
+
if (this._endTime === null) {
|
|
60
|
+
this._endTime = getHighResTime();
|
|
61
|
+
}
|
|
62
|
+
return this.getDuration();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the duration of the timer
|
|
66
|
+
*
|
|
67
|
+
* @returns The duration in milliseconds
|
|
68
|
+
*/
|
|
69
|
+
getDuration() {
|
|
70
|
+
if (this._endTime === null) {
|
|
71
|
+
return getDuration(this._startTime);
|
|
72
|
+
}
|
|
73
|
+
return getDuration(this._startTime);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the label of the timer
|
|
77
|
+
*
|
|
78
|
+
* @returns The timer label
|
|
79
|
+
*/
|
|
80
|
+
getLabel() {
|
|
81
|
+
return this._label;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Reset the timer
|
|
85
|
+
*/
|
|
86
|
+
reset() {
|
|
87
|
+
this._startTime = getHighResTime();
|
|
88
|
+
this._endTime = null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get a formatted string with the duration
|
|
92
|
+
*
|
|
93
|
+
* @returns A formatted string (e.g., "label: 1.23ms")
|
|
94
|
+
*/
|
|
95
|
+
toString() {
|
|
96
|
+
return `${this._label}: ${formatDuration(this.getDuration())}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../../src/utils/timing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,SAA2B;IACrD,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACzD,OAAO,OAAO,GAAG,IAAI,GAAG,WAAW,GAAG,OAAO,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;SAAM,IAAI,QAA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portStar(require("./core"), exports);
|
|
|
30
30
|
__exportStar(require("./formatters"), exports);
|
|
31
31
|
__exportStar(require("./trackers"), exports);
|
|
32
32
|
__exportStar(require("./utils"), exports);
|
|
33
|
+
// Add CommonJS compatibility
|
|
34
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
35
|
+
module.exports = Object.assign(defaultLogger, {
|
|
36
|
+
default: defaultLogger,
|
|
37
|
+
createLogger,
|
|
38
|
+
// Re-export everything from the modules
|
|
39
|
+
...require('./types'),
|
|
40
|
+
...require('./core'),
|
|
41
|
+
...require('./formatters'),
|
|
42
|
+
...require('./trackers'),
|
|
43
|
+
...require('./utils')
|
|
44
|
+
});
|
|
45
|
+
}
|
|
33
46
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAUA,oCAEC;AAZD,0CAAuC;AAGvC,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,eAAM,EAAE,CAAC;AAEnC,sDAAsD;AACtD,kBAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,SAAgB,YAAY,CAAC,SAAiC,EAAE;IAC9D,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,8CAA8C;AAC9C,0CAAwB;AACxB,yCAAuB;AACvB,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAUA,oCAEC;AAZD,0CAAuC;AAGvC,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,eAAM,EAAE,CAAC;AAEnC,sDAAsD;AACtD,kBAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,SAAgB,YAAY,CAAC,SAAiC,EAAE;IAC9D,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,8CAA8C;AAC9C,0CAAwB;AACxB,yCAAuB;AACvB,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB;AAExB,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;QAC5C,OAAO,EAAE,aAAa;QACtB,YAAY;QACZ,wCAAwC;QACxC,GAAG,OAAO,CAAC,SAAS,CAAC;QACrB,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpB,GAAG,OAAO,CAAC,cAAc,CAAC;QAC1B,GAAG,OAAO,CAAC,YAAY,CAAC;QACxB,GAAG,OAAO,CAAC,SAAS,CAAC;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -22,6 +22,8 @@ export declare class ExecutionTracker implements IExecutionTracker {
|
|
|
22
22
|
private _currentExecution;
|
|
23
23
|
private _asciiGenerator;
|
|
24
24
|
private _defaultThreshold;
|
|
25
|
+
private _instrumentedFunctions;
|
|
26
|
+
private _isInstrumented;
|
|
25
27
|
/**
|
|
26
28
|
* Create a new ExecutionTracker instance
|
|
27
29
|
*
|
|
@@ -39,6 +41,13 @@ export declare class ExecutionTracker implements IExecutionTracker {
|
|
|
39
41
|
* @returns The return value of the tracked function
|
|
40
42
|
*/
|
|
41
43
|
track<T>(fn: () => T, options?: ITrackOptions): T;
|
|
44
|
+
/**
|
|
45
|
+
* Instrument a function to track nested function calls
|
|
46
|
+
*
|
|
47
|
+
* @param fn - The function to instrument
|
|
48
|
+
* @returns The instrumented function
|
|
49
|
+
*/
|
|
50
|
+
private instrumentFunction;
|
|
42
51
|
/**
|
|
43
52
|
* Get the current call stack
|
|
44
53
|
*
|
|
@@ -51,6 +60,20 @@ export declare class ExecutionTracker implements IExecutionTracker {
|
|
|
51
60
|
* @returns ASCII flow chart of the execution
|
|
52
61
|
*/
|
|
53
62
|
generateFlowChart(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Prepare execution data for the ASCII generator
|
|
65
|
+
*
|
|
66
|
+
* @param executions - The execution records to prepare
|
|
67
|
+
* @returns A list of execution data
|
|
68
|
+
*/
|
|
69
|
+
private prepareExecutionData;
|
|
70
|
+
/**
|
|
71
|
+
* Add children to the result list
|
|
72
|
+
*
|
|
73
|
+
* @param children - The children to add
|
|
74
|
+
* @param result - The result list
|
|
75
|
+
*/
|
|
76
|
+
private addChildrenToResult;
|
|
54
77
|
/**
|
|
55
78
|
* Clear all execution records
|
|
56
79
|
*/
|
|
@@ -61,12 +84,5 @@ export declare class ExecutionTracker implements IExecutionTracker {
|
|
|
61
84
|
* @returns All execution records
|
|
62
85
|
*/
|
|
63
86
|
getExecutions(): ExecutionRecord[];
|
|
64
|
-
/**
|
|
65
|
-
* Flatten the execution tree into a list
|
|
66
|
-
*
|
|
67
|
-
* @param executions - The execution records to flatten
|
|
68
|
-
* @returns A flat list of execution data
|
|
69
|
-
*/
|
|
70
|
-
private flattenExecutions;
|
|
71
87
|
}
|
|
72
88
|
export {};
|
|
@@ -17,6 +17,8 @@ class ExecutionTracker {
|
|
|
17
17
|
var _a;
|
|
18
18
|
this._executions = [];
|
|
19
19
|
this._currentExecution = null;
|
|
20
|
+
this._instrumentedFunctions = new Map();
|
|
21
|
+
this._isInstrumented = false;
|
|
20
22
|
this._callStack = new stack_1.CallStackManager();
|
|
21
23
|
this._asciiGenerator = new ascii_1.AsciiArtGenerator({ boxWidth: options.boxWidth });
|
|
22
24
|
this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
|
|
@@ -29,10 +31,11 @@ class ExecutionTracker {
|
|
|
29
31
|
* @returns The return value of the tracked function
|
|
30
32
|
*/
|
|
31
33
|
track(fn, options) {
|
|
32
|
-
var _a, _b;
|
|
34
|
+
var _a, _b, _c;
|
|
33
35
|
const fnName = (options === null || options === void 0 ? void 0 : options.label) || (0, stack_1.getFunctionName)(fn);
|
|
34
36
|
const threshold = (_a = options === null || options === void 0 ? void 0 : options.threshold) !== null && _a !== void 0 ? _a : this._defaultThreshold;
|
|
35
37
|
const includeMemory = (_b = options === null || options === void 0 ? void 0 : options.includeMemory) !== null && _b !== void 0 ? _b : true;
|
|
38
|
+
const enableNestedTracking = (_c = options === null || options === void 0 ? void 0 : options.enableNestedTracking) !== null && _c !== void 0 ? _c : true;
|
|
36
39
|
// Get memory usage before execution
|
|
37
40
|
const startMemory = includeMemory ? process.memoryUsage().heapUsed : undefined;
|
|
38
41
|
// Start timing
|
|
@@ -61,9 +64,20 @@ class ExecutionTracker {
|
|
|
61
64
|
const previousExecution = this._currentExecution;
|
|
62
65
|
// Set this as the current execution
|
|
63
66
|
this._currentExecution = execution;
|
|
67
|
+
// Flag to track if we're already instrumenting to avoid recursion
|
|
68
|
+
const wasInstrumented = this._isInstrumented;
|
|
64
69
|
try {
|
|
65
|
-
//
|
|
66
|
-
|
|
70
|
+
// If this is the top-level call and nested tracking is enabled, instrument the function
|
|
71
|
+
if (enableNestedTracking && !wasInstrumented) {
|
|
72
|
+
this._isInstrumented = true;
|
|
73
|
+
// Instrument the function to track nested calls
|
|
74
|
+
const instrumentedFn = this.instrumentFunction(fn);
|
|
75
|
+
return instrumentedFn();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Execute the function normally
|
|
79
|
+
return fn();
|
|
80
|
+
}
|
|
67
81
|
}
|
|
68
82
|
finally {
|
|
69
83
|
// End timing
|
|
@@ -81,8 +95,45 @@ class ExecutionTracker {
|
|
|
81
95
|
this._currentExecution = previousExecution;
|
|
82
96
|
// Remove from call stack
|
|
83
97
|
this._callStack.pop();
|
|
98
|
+
// Reset instrumentation flag if this was the top-level call
|
|
99
|
+
if (!wasInstrumented) {
|
|
100
|
+
this._isInstrumented = false;
|
|
101
|
+
}
|
|
84
102
|
}
|
|
85
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Instrument a function to track nested function calls
|
|
106
|
+
*
|
|
107
|
+
* @param fn - The function to instrument
|
|
108
|
+
* @returns The instrumented function
|
|
109
|
+
*/
|
|
110
|
+
instrumentFunction(fn) {
|
|
111
|
+
// If we've already instrumented this function, return the instrumented version
|
|
112
|
+
if (this._instrumentedFunctions.has(fn)) {
|
|
113
|
+
return this._instrumentedFunctions.get(fn);
|
|
114
|
+
}
|
|
115
|
+
// Create a new instrumented function
|
|
116
|
+
const instrumentedFn = () => {
|
|
117
|
+
try {
|
|
118
|
+
// We can't actually modify the function at runtime to track nested calls
|
|
119
|
+
// in a generic way. The best we can do is execute the function and rely
|
|
120
|
+
// on the call stack for visualization.
|
|
121
|
+
//
|
|
122
|
+
// For proper nested function tracking, users should wrap each function
|
|
123
|
+
// they want to track with tracePerf.track() or use a more advanced
|
|
124
|
+
// instrumentation approach like aspect-oriented programming or
|
|
125
|
+
// code transformation.
|
|
126
|
+
return fn();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// Re-throw any errors
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// Cache the instrumented function
|
|
134
|
+
this._instrumentedFunctions.set(fn, instrumentedFn);
|
|
135
|
+
return instrumentedFn;
|
|
136
|
+
}
|
|
86
137
|
/**
|
|
87
138
|
* Get the current call stack
|
|
88
139
|
*
|
|
@@ -98,9 +149,52 @@ class ExecutionTracker {
|
|
|
98
149
|
*/
|
|
99
150
|
generateFlowChart() {
|
|
100
151
|
// Convert execution records to execution data for the ASCII generator
|
|
101
|
-
const
|
|
152
|
+
const executionData = this.prepareExecutionData(this._executions);
|
|
102
153
|
// Generate the flow chart
|
|
103
|
-
return this._asciiGenerator.generateFlowChart(
|
|
154
|
+
return this._asciiGenerator.generateFlowChart(executionData);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Prepare execution data for the ASCII generator
|
|
158
|
+
*
|
|
159
|
+
* @param executions - The execution records to prepare
|
|
160
|
+
* @returns A list of execution data
|
|
161
|
+
*/
|
|
162
|
+
prepareExecutionData(executions) {
|
|
163
|
+
const result = [];
|
|
164
|
+
// Process each root execution
|
|
165
|
+
executions.forEach(execution => {
|
|
166
|
+
// Add the root execution
|
|
167
|
+
result.push({
|
|
168
|
+
name: execution.name,
|
|
169
|
+
duration: execution.duration,
|
|
170
|
+
isSlow: execution.isSlow,
|
|
171
|
+
memoryUsage: execution.memoryUsage,
|
|
172
|
+
level: execution.level,
|
|
173
|
+
});
|
|
174
|
+
// Add children recursively
|
|
175
|
+
this.addChildrenToResult(execution.children, result);
|
|
176
|
+
});
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Add children to the result list
|
|
181
|
+
*
|
|
182
|
+
* @param children - The children to add
|
|
183
|
+
* @param result - The result list
|
|
184
|
+
*/
|
|
185
|
+
addChildrenToResult(children, result) {
|
|
186
|
+
children.forEach(child => {
|
|
187
|
+
// Add the child
|
|
188
|
+
result.push({
|
|
189
|
+
name: child.name,
|
|
190
|
+
duration: child.duration,
|
|
191
|
+
isSlow: child.isSlow,
|
|
192
|
+
memoryUsage: child.memoryUsage,
|
|
193
|
+
level: child.level,
|
|
194
|
+
});
|
|
195
|
+
// Add grandchildren recursively
|
|
196
|
+
this.addChildrenToResult(child.children, result);
|
|
197
|
+
});
|
|
104
198
|
}
|
|
105
199
|
/**
|
|
106
200
|
* Clear all execution records
|
|
@@ -109,6 +203,7 @@ class ExecutionTracker {
|
|
|
109
203
|
this._executions = [];
|
|
110
204
|
this._currentExecution = null;
|
|
111
205
|
this._callStack.clear();
|
|
206
|
+
this._instrumentedFunctions.clear();
|
|
112
207
|
}
|
|
113
208
|
/**
|
|
114
209
|
* Get all execution records
|
|
@@ -118,30 +213,6 @@ class ExecutionTracker {
|
|
|
118
213
|
getExecutions() {
|
|
119
214
|
return [...this._executions];
|
|
120
215
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Flatten the execution tree into a list
|
|
123
|
-
*
|
|
124
|
-
* @param executions - The execution records to flatten
|
|
125
|
-
* @returns A flat list of execution data
|
|
126
|
-
*/
|
|
127
|
-
flattenExecutions(executions) {
|
|
128
|
-
const result = [];
|
|
129
|
-
// Helper function to recursively flatten the tree
|
|
130
|
-
const flatten = (record) => {
|
|
131
|
-
result.push({
|
|
132
|
-
name: record.name,
|
|
133
|
-
duration: record.duration,
|
|
134
|
-
isSlow: record.isSlow,
|
|
135
|
-
memoryUsage: record.memoryUsage,
|
|
136
|
-
level: record.level,
|
|
137
|
-
});
|
|
138
|
-
// Process children
|
|
139
|
-
record.children.forEach(child => flatten(child));
|
|
140
|
-
};
|
|
141
|
-
// Flatten each root execution
|
|
142
|
-
executions.forEach(execution => flatten(execution));
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
216
|
}
|
|
146
217
|
exports.ExecutionTracker = ExecutionTracker;
|
|
147
218
|
//# sourceMappingURL=execution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/trackers/execution.ts"],"names":[],"mappings":";;;AACA,0CAAmE;AACnE,4CAA8D;AAC9D,+CAAuE;AAiBvE;;GAEG;AACH,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/trackers/execution.ts"],"names":[],"mappings":";;;AACA,0CAAmE;AACnE,4CAA8D;AAC9D,+CAAuE;AAiBvE;;GAEG;AACH,MAAa,gBAAgB;IAS3B;;;;OAIG;IACH,YAAY,UAA4D,EAAE;;QAZlE,gBAAW,GAAsB,EAAE,CAAC;QACpC,sBAAiB,GAA2B,IAAI,CAAC;QAGjD,2BAAsB,GAA4B,IAAI,GAAG,EAAE,CAAC;QAC5D,oBAAe,GAAY,KAAK,CAAC;QAQvC,IAAI,CAAC,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,IAAI,yBAAiB,CAAC,EAAE,QAAQ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,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;CACF;AA5OD,4CA4OC"}
|
package/dist/types/config.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
1
|
export * from './config';
|
|
2
2
|
export * from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* Options for tracking function execution
|
|
5
|
+
*/
|
|
6
|
+
export interface ITrackOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom label for the function
|
|
9
|
+
*/
|
|
10
|
+
label?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Performance threshold in milliseconds
|
|
13
|
+
*/
|
|
14
|
+
threshold?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to include memory usage in the tracking
|
|
17
|
+
*/
|
|
18
|
+
includeMemory?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to track nested function calls
|
|
21
|
+
*
|
|
22
|
+
* Note: This option doesn't automatically track all nested function calls.
|
|
23
|
+
* It only enables the infrastructure for tracking nested calls, but you still
|
|
24
|
+
* need to manually track each nested function using one of the approaches
|
|
25
|
+
* described in the documentation.
|
|
26
|
+
*
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
enableNestedTracking?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to suppress logging
|
|
32
|
+
*/
|
|
33
|
+
silent?: boolean;
|
|
34
|
+
}
|
package/dist/types/index.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config"), exports);
|
|
18
|
+
__exportStar(require("./logger"), exports);
|
|
3
19
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB"}
|
package/dist/types/logger.js
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "traceperf",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Advanced console logging & performance tracking for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"browser": "dist/browser.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./browser": {
|
|
16
|
+
"require": "./dist/browser.js",
|
|
17
|
+
"import": "./dist/esm/browser.js",
|
|
18
|
+
"types": "./dist/browser.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
8
21
|
"files": [
|
|
9
22
|
"dist"
|
|
10
23
|
],
|
|
11
24
|
"scripts": {
|
|
12
25
|
"build": "tsc",
|
|
26
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
13
27
|
"build:browser": "tsc -p tsconfig.browser.json",
|
|
14
|
-
"build:all": "npm run build && npm run build:browser",
|
|
28
|
+
"build:all": "npm run build && npm run build:esm && npm run build:browser",
|
|
15
29
|
"test": "jest",
|
|
16
30
|
"lint": "eslint src --ext .ts",
|
|
17
31
|
"format": "prettier --write \"src/**/*.ts\"",
|