traceperf 0.1.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.
- package/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/browser.d.ts +67 -0
- package/dist/browser.js +260 -0
- package/dist/browser.js.map +1 -0
- package/dist/core/config.d.ts +77 -0
- package/dist/core/config.js +116 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/constants.d.ts +78 -0
- package/dist/core/constants.js +109 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +84 -0
- package/dist/core/logger.js +174 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/formatters/ascii.d.ts +52 -0
- package/dist/formatters/ascii.js +104 -0
- package/dist/formatters/ascii.js.map +1 -0
- package/dist/formatters/cli.d.ts +50 -0
- package/dist/formatters/cli.js +100 -0
- package/dist/formatters/cli.js.map +1 -0
- package/dist/formatters/index.d.ts +3 -0
- package/dist/formatters/index.js +20 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/json.d.ts +45 -0
- package/dist/formatters/json.js +89 -0
- package/dist/formatters/json.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/trackers/execution.d.ts +72 -0
- package/dist/trackers/execution.js +147 -0
- package/dist/trackers/execution.js.map +1 -0
- package/dist/trackers/index.d.ts +2 -0
- package/dist/trackers/index.js +19 -0
- package/dist/trackers/index.js.map +1 -0
- package/dist/trackers/performance.d.ts +82 -0
- package/dist/trackers/performance.js +110 -0
- package/dist/trackers/performance.js.map +1 -0
- package/dist/types/config.d.ts +110 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/logger.d.ts +127 -0
- package/dist/types/logger.js +2 -0
- package/dist/types/logger.js.map +1 -0
- package/dist/utils/colors.d.ts +87 -0
- package/dist/utils/colors.js +148 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stack.d.ts +63 -0
- package/dist/utils/stack.js +116 -0
- package/dist/utils/stack.js.map +1 -0
- package/dist/utils/timing.d.ts +65 -0
- package/dist/utils/timing.js +106 -0
- package/dist/utils/timing.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with terminal colors
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Apply color to a string
|
|
6
|
+
*
|
|
7
|
+
* @param text - The text to colorize
|
|
8
|
+
* @param color - The color to apply
|
|
9
|
+
* @returns The colorized string
|
|
10
|
+
*/
|
|
11
|
+
export declare function colorize(text: string, color: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Apply bold formatting to a string
|
|
14
|
+
*
|
|
15
|
+
* @param text - The text to make bold
|
|
16
|
+
* @returns The bold string
|
|
17
|
+
*/
|
|
18
|
+
export declare function bold(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Apply dim formatting to a string
|
|
21
|
+
*
|
|
22
|
+
* @param text - The text to make dim
|
|
23
|
+
* @returns The dim string
|
|
24
|
+
*/
|
|
25
|
+
export declare function dim(text: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Apply underline formatting to a string
|
|
28
|
+
*
|
|
29
|
+
* @param text - The text to underline
|
|
30
|
+
* @returns The underlined string
|
|
31
|
+
*/
|
|
32
|
+
export declare function underline(text: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Apply red color to a string
|
|
35
|
+
*
|
|
36
|
+
* @param text - The text to colorize
|
|
37
|
+
* @returns The red string
|
|
38
|
+
*/
|
|
39
|
+
export declare function red(text: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Apply green color to a string
|
|
42
|
+
*
|
|
43
|
+
* @param text - The text to colorize
|
|
44
|
+
* @returns The green string
|
|
45
|
+
*/
|
|
46
|
+
export declare function green(text: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Apply yellow color to a string
|
|
49
|
+
*
|
|
50
|
+
* @param text - The text to colorize
|
|
51
|
+
* @returns The yellow string
|
|
52
|
+
*/
|
|
53
|
+
export declare function yellow(text: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Apply blue color to a string
|
|
56
|
+
*
|
|
57
|
+
* @param text - The text to colorize
|
|
58
|
+
* @returns The blue string
|
|
59
|
+
*/
|
|
60
|
+
export declare function blue(text: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Apply magenta color to a string
|
|
63
|
+
*
|
|
64
|
+
* @param text - The text to colorize
|
|
65
|
+
* @returns The magenta string
|
|
66
|
+
*/
|
|
67
|
+
export declare function magenta(text: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Apply cyan color to a string
|
|
70
|
+
*
|
|
71
|
+
* @param text - The text to colorize
|
|
72
|
+
* @returns The cyan string
|
|
73
|
+
*/
|
|
74
|
+
export declare function cyan(text: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Apply gray color to a string
|
|
77
|
+
*
|
|
78
|
+
* @param text - The text to colorize
|
|
79
|
+
* @returns The gray string
|
|
80
|
+
*/
|
|
81
|
+
export declare function gray(text: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Check if terminal supports colors
|
|
84
|
+
*
|
|
85
|
+
* @returns Whether the terminal supports colors
|
|
86
|
+
*/
|
|
87
|
+
export declare function supportsColor(): boolean;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.colorize = colorize;
|
|
4
|
+
exports.bold = bold;
|
|
5
|
+
exports.dim = dim;
|
|
6
|
+
exports.underline = underline;
|
|
7
|
+
exports.red = red;
|
|
8
|
+
exports.green = green;
|
|
9
|
+
exports.yellow = yellow;
|
|
10
|
+
exports.blue = blue;
|
|
11
|
+
exports.magenta = magenta;
|
|
12
|
+
exports.cyan = cyan;
|
|
13
|
+
exports.gray = gray;
|
|
14
|
+
exports.supportsColor = supportsColor;
|
|
15
|
+
const constants_1 = require("../core/constants");
|
|
16
|
+
/**
|
|
17
|
+
* Utilities for working with terminal colors
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Apply color to a string
|
|
21
|
+
*
|
|
22
|
+
* @param text - The text to colorize
|
|
23
|
+
* @param color - The color to apply
|
|
24
|
+
* @returns The colorized string
|
|
25
|
+
*/
|
|
26
|
+
function colorize(text, color) {
|
|
27
|
+
return `${color}${text}${constants_1.COLORS.reset}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Apply bold formatting to a string
|
|
31
|
+
*
|
|
32
|
+
* @param text - The text to make bold
|
|
33
|
+
* @returns The bold string
|
|
34
|
+
*/
|
|
35
|
+
function bold(text) {
|
|
36
|
+
return `${constants_1.COLORS.bright}${text}${constants_1.COLORS.reset}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Apply dim formatting to a string
|
|
40
|
+
*
|
|
41
|
+
* @param text - The text to make dim
|
|
42
|
+
* @returns The dim string
|
|
43
|
+
*/
|
|
44
|
+
function dim(text) {
|
|
45
|
+
return `${constants_1.COLORS.dim}${text}${constants_1.COLORS.reset}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Apply underline formatting to a string
|
|
49
|
+
*
|
|
50
|
+
* @param text - The text to underline
|
|
51
|
+
* @returns The underlined string
|
|
52
|
+
*/
|
|
53
|
+
function underline(text) {
|
|
54
|
+
return `${constants_1.COLORS.underscore}${text}${constants_1.COLORS.reset}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Apply red color to a string
|
|
58
|
+
*
|
|
59
|
+
* @param text - The text to colorize
|
|
60
|
+
* @returns The red string
|
|
61
|
+
*/
|
|
62
|
+
function red(text) {
|
|
63
|
+
return colorize(text, constants_1.COLORS.fg.red);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Apply green color to a string
|
|
67
|
+
*
|
|
68
|
+
* @param text - The text to colorize
|
|
69
|
+
* @returns The green string
|
|
70
|
+
*/
|
|
71
|
+
function green(text) {
|
|
72
|
+
return colorize(text, constants_1.COLORS.fg.green);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Apply yellow color to a string
|
|
76
|
+
*
|
|
77
|
+
* @param text - The text to colorize
|
|
78
|
+
* @returns The yellow string
|
|
79
|
+
*/
|
|
80
|
+
function yellow(text) {
|
|
81
|
+
return colorize(text, constants_1.COLORS.fg.yellow);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Apply blue color to a string
|
|
85
|
+
*
|
|
86
|
+
* @param text - The text to colorize
|
|
87
|
+
* @returns The blue string
|
|
88
|
+
*/
|
|
89
|
+
function blue(text) {
|
|
90
|
+
return colorize(text, constants_1.COLORS.fg.blue);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Apply magenta color to a string
|
|
94
|
+
*
|
|
95
|
+
* @param text - The text to colorize
|
|
96
|
+
* @returns The magenta string
|
|
97
|
+
*/
|
|
98
|
+
function magenta(text) {
|
|
99
|
+
return colorize(text, constants_1.COLORS.fg.magenta);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Apply cyan color to a string
|
|
103
|
+
*
|
|
104
|
+
* @param text - The text to colorize
|
|
105
|
+
* @returns The cyan string
|
|
106
|
+
*/
|
|
107
|
+
function cyan(text) {
|
|
108
|
+
return colorize(text, constants_1.COLORS.fg.cyan);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Apply gray color to a string
|
|
112
|
+
*
|
|
113
|
+
* @param text - The text to colorize
|
|
114
|
+
* @returns The gray string
|
|
115
|
+
*/
|
|
116
|
+
function gray(text) {
|
|
117
|
+
return colorize(text, constants_1.COLORS.fg.gray);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if terminal supports colors
|
|
121
|
+
*
|
|
122
|
+
* @returns Whether the terminal supports colors
|
|
123
|
+
*/
|
|
124
|
+
function supportsColor() {
|
|
125
|
+
if (process.env.FORCE_COLOR === '0') {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (process.env.FORCE_COLOR) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (process.platform === 'win32') {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
if ('CI' in process.env) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (process.env.COLORTERM) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (process.env.TERM === 'dumb') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (process.stdout.isTTY) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/utils/colors.ts"],"names":[],"mappings":";;AAaA,4BAEC;AAQD,oBAEC;AAQD,kBAEC;AAQD,8BAEC;AAQD,kBAEC;AAQD,sBAEC;AAQD,wBAEC;AAQD,oBAEC;AAQD,0BAEC;AAQD,oBAEC;AAQD,oBAEC;AAOD,sCA8BC;AAxJD,iDAA2C;AAE3C;;GAEG;AAEH;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,KAAa;IAClD,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,kBAAM,CAAC,KAAK,EAAE,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,IAAI,CAAC,IAAY;IAC/B,OAAO,GAAG,kBAAM,CAAC,MAAM,GAAG,IAAI,GAAG,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AQ,CAAC,IAAI,EAAE,kBAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa;IAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,GAAG,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./timing"), exports);
|
|
18
|
+
__exportStar(require("./stack"), exports);
|
|
19
|
+
__exportStar(require("./colors"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for managing call stacks and function tracking
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extract the name of a function
|
|
6
|
+
*
|
|
7
|
+
* @param fn - The function to extract the name from
|
|
8
|
+
* @returns The function name or a placeholder if not available
|
|
9
|
+
*/
|
|
10
|
+
export declare function getFunctionName(fn: Function): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the current call stack
|
|
13
|
+
*
|
|
14
|
+
* @returns An array of function names in the call stack
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCallStack(): string[];
|
|
17
|
+
/**
|
|
18
|
+
* CallStackManager - Manages a call stack for execution tracking
|
|
19
|
+
*/
|
|
20
|
+
export declare class CallStackManager {
|
|
21
|
+
private _stack;
|
|
22
|
+
/**
|
|
23
|
+
* Push a function name onto the call stack
|
|
24
|
+
*
|
|
25
|
+
* @param name - The function name
|
|
26
|
+
* @returns The current stack depth
|
|
27
|
+
*/
|
|
28
|
+
push(name: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Pop a function name from the call stack
|
|
31
|
+
*
|
|
32
|
+
* @returns The popped function name or undefined if the stack is empty
|
|
33
|
+
*/
|
|
34
|
+
pop(): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get the current call stack
|
|
37
|
+
*
|
|
38
|
+
* @returns A copy of the current call stack
|
|
39
|
+
*/
|
|
40
|
+
getStack(): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Get the current stack depth
|
|
43
|
+
*
|
|
44
|
+
* @returns The current stack depth
|
|
45
|
+
*/
|
|
46
|
+
getDepth(): number;
|
|
47
|
+
/**
|
|
48
|
+
* Clear the call stack
|
|
49
|
+
*/
|
|
50
|
+
clear(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get the current function name (top of the stack)
|
|
53
|
+
*
|
|
54
|
+
* @returns The current function name or undefined if the stack is empty
|
|
55
|
+
*/
|
|
56
|
+
getCurrentFunction(): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get the parent function name
|
|
59
|
+
*
|
|
60
|
+
* @returns The parent function name or undefined if there is no parent
|
|
61
|
+
*/
|
|
62
|
+
getParentFunction(): string | undefined;
|
|
63
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for managing call stacks and function tracking
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CallStackManager = void 0;
|
|
7
|
+
exports.getFunctionName = getFunctionName;
|
|
8
|
+
exports.getCallStack = getCallStack;
|
|
9
|
+
/**
|
|
10
|
+
* Extract the name of a function
|
|
11
|
+
*
|
|
12
|
+
* @param fn - The function to extract the name from
|
|
13
|
+
* @returns The function name or a placeholder if not available
|
|
14
|
+
*/
|
|
15
|
+
function getFunctionName(fn) {
|
|
16
|
+
if (fn.name) {
|
|
17
|
+
return fn.name;
|
|
18
|
+
}
|
|
19
|
+
// Try to extract name from function toString()
|
|
20
|
+
const fnStr = fn.toString();
|
|
21
|
+
const nameMatch = fnStr.match(/function\s+([^(]+)/);
|
|
22
|
+
if (nameMatch) {
|
|
23
|
+
return nameMatch[1].trim();
|
|
24
|
+
}
|
|
25
|
+
// For arrow functions or anonymous functions
|
|
26
|
+
const arrowMatch = fnStr.match(/^\s*(?:async\s+)?(?:\([^)]*\)|\w+)\s*=>/);
|
|
27
|
+
if (arrowMatch) {
|
|
28
|
+
return '<arrow function>';
|
|
29
|
+
}
|
|
30
|
+
return '<anonymous>';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the current call stack
|
|
34
|
+
*
|
|
35
|
+
* @returns An array of function names in the call stack
|
|
36
|
+
*/
|
|
37
|
+
function getCallStack() {
|
|
38
|
+
const stack = new Error().stack;
|
|
39
|
+
if (!stack) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
// Parse the stack trace
|
|
43
|
+
return stack
|
|
44
|
+
.split('\n')
|
|
45
|
+
.slice(2) // Skip the Error and this function
|
|
46
|
+
.map(line => {
|
|
47
|
+
const match = line.match(/at\s+([^\s]+)/);
|
|
48
|
+
return match ? match[1] : line.trim();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* CallStackManager - Manages a call stack for execution tracking
|
|
53
|
+
*/
|
|
54
|
+
class CallStackManager {
|
|
55
|
+
constructor() {
|
|
56
|
+
this._stack = [];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Push a function name onto the call stack
|
|
60
|
+
*
|
|
61
|
+
* @param name - The function name
|
|
62
|
+
* @returns The current stack depth
|
|
63
|
+
*/
|
|
64
|
+
push(name) {
|
|
65
|
+
this._stack.push(name);
|
|
66
|
+
return this._stack.length;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Pop a function name from the call stack
|
|
70
|
+
*
|
|
71
|
+
* @returns The popped function name or undefined if the stack is empty
|
|
72
|
+
*/
|
|
73
|
+
pop() {
|
|
74
|
+
return this._stack.pop();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the current call stack
|
|
78
|
+
*
|
|
79
|
+
* @returns A copy of the current call stack
|
|
80
|
+
*/
|
|
81
|
+
getStack() {
|
|
82
|
+
return [...this._stack];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the current stack depth
|
|
86
|
+
*
|
|
87
|
+
* @returns The current stack depth
|
|
88
|
+
*/
|
|
89
|
+
getDepth() {
|
|
90
|
+
return this._stack.length;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clear the call stack
|
|
94
|
+
*/
|
|
95
|
+
clear() {
|
|
96
|
+
this._stack = [];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the current function name (top of the stack)
|
|
100
|
+
*
|
|
101
|
+
* @returns The current function name or undefined if the stack is empty
|
|
102
|
+
*/
|
|
103
|
+
getCurrentFunction() {
|
|
104
|
+
return this._stack[this._stack.length - 1];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the parent function name
|
|
108
|
+
*
|
|
109
|
+
* @returns The parent function name or undefined if there is no parent
|
|
110
|
+
*/
|
|
111
|
+
getParentFunction() {
|
|
112
|
+
return this._stack[this._stack.length - 2];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CallStackManager = CallStackManager;
|
|
116
|
+
//# sourceMappingURL=stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../src/utils/stack.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAQH,0CAmBC;AAOD,oCAcC;AA9CD;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,EAAY;IAC1C,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB,CAAC;IAED,+CAA+C;IAC/C,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACpD,IAAI,SAAS,EAAE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AQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACI,kBAAkB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAjED,4CAiEC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 declare function getHighResTime(): [number, number];
|
|
10
|
+
/**
|
|
11
|
+
* Calculate the duration between a start time and now
|
|
12
|
+
*
|
|
13
|
+
* @param startTime - The start time from getHighResTime()
|
|
14
|
+
* @returns The duration in milliseconds
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDuration(startTime: [number, number]): number;
|
|
17
|
+
/**
|
|
18
|
+
* Format a duration in milliseconds to a human-readable string
|
|
19
|
+
*
|
|
20
|
+
* @param duration - The duration in milliseconds
|
|
21
|
+
* @returns A formatted string (e.g., "1.23ms", "1.23s")
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatDuration(duration: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* A simple timer class for measuring durations
|
|
26
|
+
*/
|
|
27
|
+
export declare class Timer {
|
|
28
|
+
private _startTime;
|
|
29
|
+
private _endTime;
|
|
30
|
+
private _label;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new Timer instance
|
|
33
|
+
*
|
|
34
|
+
* @param label - A label for the timer
|
|
35
|
+
*/
|
|
36
|
+
constructor(label: string);
|
|
37
|
+
/**
|
|
38
|
+
* Stop the timer
|
|
39
|
+
*
|
|
40
|
+
* @returns The duration in milliseconds
|
|
41
|
+
*/
|
|
42
|
+
stop(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get the duration of the timer
|
|
45
|
+
*
|
|
46
|
+
* @returns The duration in milliseconds
|
|
47
|
+
*/
|
|
48
|
+
getDuration(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Get the label of the timer
|
|
51
|
+
*
|
|
52
|
+
* @returns The timer label
|
|
53
|
+
*/
|
|
54
|
+
getLabel(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Reset the timer
|
|
57
|
+
*/
|
|
58
|
+
reset(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get a formatted string with the duration
|
|
61
|
+
*
|
|
62
|
+
* @returns A formatted string (e.g., "label: 1.23ms")
|
|
63
|
+
*/
|
|
64
|
+
toString(): string;
|
|
65
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-resolution timing utilities for performance tracking
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Timer = void 0;
|
|
7
|
+
exports.getHighResTime = getHighResTime;
|
|
8
|
+
exports.getDuration = getDuration;
|
|
9
|
+
exports.formatDuration = formatDuration;
|
|
10
|
+
/**
|
|
11
|
+
* Get the current high-resolution time
|
|
12
|
+
*
|
|
13
|
+
* @returns The current high-resolution time
|
|
14
|
+
*/
|
|
15
|
+
function getHighResTime() {
|
|
16
|
+
return process.hrtime();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the duration between a start time and now
|
|
20
|
+
*
|
|
21
|
+
* @param startTime - The start time from getHighResTime()
|
|
22
|
+
* @returns The duration in milliseconds
|
|
23
|
+
*/
|
|
24
|
+
function getDuration(startTime) {
|
|
25
|
+
const [seconds, nanoseconds] = process.hrtime(startTime);
|
|
26
|
+
return seconds * 1000 + nanoseconds / 1000000;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Format a duration in milliseconds to a human-readable string
|
|
30
|
+
*
|
|
31
|
+
* @param duration - The duration in milliseconds
|
|
32
|
+
* @returns A formatted string (e.g., "1.23ms", "1.23s")
|
|
33
|
+
*/
|
|
34
|
+
function formatDuration(duration) {
|
|
35
|
+
if (duration < 1) {
|
|
36
|
+
return `${(duration * 1000).toFixed(2)}μs`;
|
|
37
|
+
}
|
|
38
|
+
else if (duration < 1000) {
|
|
39
|
+
return `${duration.toFixed(2)}ms`;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return `${(duration / 1000).toFixed(2)}s`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A simple timer class for measuring durations
|
|
47
|
+
*/
|
|
48
|
+
class Timer {
|
|
49
|
+
/**
|
|
50
|
+
* Create a new Timer instance
|
|
51
|
+
*
|
|
52
|
+
* @param label - A label for the timer
|
|
53
|
+
*/
|
|
54
|
+
constructor(label) {
|
|
55
|
+
this._endTime = null;
|
|
56
|
+
this._startTime = getHighResTime();
|
|
57
|
+
this._label = label;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stop the timer
|
|
61
|
+
*
|
|
62
|
+
* @returns The duration in milliseconds
|
|
63
|
+
*/
|
|
64
|
+
stop() {
|
|
65
|
+
if (this._endTime === null) {
|
|
66
|
+
this._endTime = getHighResTime();
|
|
67
|
+
}
|
|
68
|
+
return this.getDuration();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the duration of the timer
|
|
72
|
+
*
|
|
73
|
+
* @returns The duration in milliseconds
|
|
74
|
+
*/
|
|
75
|
+
getDuration() {
|
|
76
|
+
if (this._endTime === null) {
|
|
77
|
+
return getDuration(this._startTime);
|
|
78
|
+
}
|
|
79
|
+
return getDuration(this._startTime);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the label of the timer
|
|
83
|
+
*
|
|
84
|
+
* @returns The timer label
|
|
85
|
+
*/
|
|
86
|
+
getLabel() {
|
|
87
|
+
return this._label;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reset the timer
|
|
91
|
+
*/
|
|
92
|
+
reset() {
|
|
93
|
+
this._startTime = getHighResTime();
|
|
94
|
+
this._endTime = null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a formatted string with the duration
|
|
98
|
+
*
|
|
99
|
+
* @returns A formatted string (e.g., "label: 1.23ms")
|
|
100
|
+
*/
|
|
101
|
+
toString() {
|
|
102
|
+
return `${this._label}: ${formatDuration(this.getDuration())}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.Timer = Timer;
|
|
106
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/utils/timing.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAOH,wCAEC;AAQD,kCAGC;AAQD,wCAQC;AAlCD;;;;GAIG;AACH,SAAgB,cAAc;IAC5B,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,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,SAAgB,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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0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "traceperf",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Advanced console logging & performance tracking for Node.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"browser": "dist/browser.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"build:browser": "tsc -p tsconfig.browser.json",
|
|
14
|
+
"build:all": "npm run build && npm run build:browser",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"lint": "eslint src --ext .ts",
|
|
17
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
18
|
+
"prepare": "husky install",
|
|
19
|
+
"prepublishOnly": "npm run build:all",
|
|
20
|
+
"dev": "tsc --watch"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"logging",
|
|
24
|
+
"performance",
|
|
25
|
+
"debugging",
|
|
26
|
+
"console",
|
|
27
|
+
"trace",
|
|
28
|
+
"profiling",
|
|
29
|
+
"bottleneck",
|
|
30
|
+
"execution-flow"
|
|
31
|
+
],
|
|
32
|
+
"author": "Shubh Wadekar",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=14.0.0"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/thelastbackspace/traceperf.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/thelastbackspace/traceperf/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/thelastbackspace/traceperf#readme",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/jest": "^29.5.14",
|
|
47
|
+
"@types/node": "^22.13.10",
|
|
48
|
+
"@types/uuid": "^10.0.0",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
50
|
+
"@typescript-eslint/parser": "^8.26.1",
|
|
51
|
+
"eslint": "^8.56.0",
|
|
52
|
+
"eslint-config-prettier": "^10.1.1",
|
|
53
|
+
"husky": "^9.1.7",
|
|
54
|
+
"jest": "^29.7.0",
|
|
55
|
+
"prettier": "^3.5.3",
|
|
56
|
+
"ts-jest": "^29.2.6",
|
|
57
|
+
"typescript": "^5.8.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"uuid": "^11.1.0"
|
|
61
|
+
}
|
|
62
|
+
}
|