traceperf 0.1.0 → 0.1.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 +31 -0
- package/dist/browser.d.ts +9 -3
- package/dist/browser.js +28 -8
- package/dist/browser.js.map +1 -1
- package/dist/esm/browser.d.ts +73 -0
- package/dist/esm/browser.js +275 -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 +72 -0
- package/dist/esm/trackers/execution.js +143 -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 +2 -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/types/config.js +2 -1
- 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,134 @@
|
|
|
1
|
+
import { COLORS } from '../core/constants';
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for working with terminal colors
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Apply color to a string
|
|
7
|
+
*
|
|
8
|
+
* @param text - The text to colorize
|
|
9
|
+
* @param color - The color to apply
|
|
10
|
+
* @returns The colorized string
|
|
11
|
+
*/
|
|
12
|
+
export function colorize(text, color) {
|
|
13
|
+
return `${color}${text}${COLORS.reset}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Apply bold formatting to a string
|
|
17
|
+
*
|
|
18
|
+
* @param text - The text to make bold
|
|
19
|
+
* @returns The bold string
|
|
20
|
+
*/
|
|
21
|
+
export function bold(text) {
|
|
22
|
+
return `${COLORS.bright}${text}${COLORS.reset}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Apply dim formatting to a string
|
|
26
|
+
*
|
|
27
|
+
* @param text - The text to make dim
|
|
28
|
+
* @returns The dim string
|
|
29
|
+
*/
|
|
30
|
+
export function dim(text) {
|
|
31
|
+
return `${COLORS.dim}${text}${COLORS.reset}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Apply underline formatting to a string
|
|
35
|
+
*
|
|
36
|
+
* @param text - The text to underline
|
|
37
|
+
* @returns The underlined string
|
|
38
|
+
*/
|
|
39
|
+
export function underline(text) {
|
|
40
|
+
return `${COLORS.underscore}${text}${COLORS.reset}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Apply red color to a string
|
|
44
|
+
*
|
|
45
|
+
* @param text - The text to colorize
|
|
46
|
+
* @returns The red string
|
|
47
|
+
*/
|
|
48
|
+
export function red(text) {
|
|
49
|
+
return colorize(text, COLORS.fg.red);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Apply green color to a string
|
|
53
|
+
*
|
|
54
|
+
* @param text - The text to colorize
|
|
55
|
+
* @returns The green string
|
|
56
|
+
*/
|
|
57
|
+
export function green(text) {
|
|
58
|
+
return colorize(text, COLORS.fg.green);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Apply yellow color to a string
|
|
62
|
+
*
|
|
63
|
+
* @param text - The text to colorize
|
|
64
|
+
* @returns The yellow string
|
|
65
|
+
*/
|
|
66
|
+
export function yellow(text) {
|
|
67
|
+
return colorize(text, COLORS.fg.yellow);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Apply blue color to a string
|
|
71
|
+
*
|
|
72
|
+
* @param text - The text to colorize
|
|
73
|
+
* @returns The blue string
|
|
74
|
+
*/
|
|
75
|
+
export function blue(text) {
|
|
76
|
+
return colorize(text, COLORS.fg.blue);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Apply magenta color to a string
|
|
80
|
+
*
|
|
81
|
+
* @param text - The text to colorize
|
|
82
|
+
* @returns The magenta string
|
|
83
|
+
*/
|
|
84
|
+
export function magenta(text) {
|
|
85
|
+
return colorize(text, COLORS.fg.magenta);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Apply cyan color to a string
|
|
89
|
+
*
|
|
90
|
+
* @param text - The text to colorize
|
|
91
|
+
* @returns The cyan string
|
|
92
|
+
*/
|
|
93
|
+
export function cyan(text) {
|
|
94
|
+
return colorize(text, COLORS.fg.cyan);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Apply gray color to a string
|
|
98
|
+
*
|
|
99
|
+
* @param text - The text to colorize
|
|
100
|
+
* @returns The gray string
|
|
101
|
+
*/
|
|
102
|
+
export function gray(text) {
|
|
103
|
+
return colorize(text, COLORS.fg.gray);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if terminal supports colors
|
|
107
|
+
*
|
|
108
|
+
* @returns Whether the terminal supports colors
|
|
109
|
+
*/
|
|
110
|
+
export function supportsColor() {
|
|
111
|
+
if (process.env.FORCE_COLOR === '0') {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (process.env.FORCE_COLOR) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (process.platform === 'win32') {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
if ('CI' in process.env) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
if (process.env.COLORTERM) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (process.env.TERM === 'dumb') {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (process.stdout.isTTY) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 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}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -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,110 @@
|
|
|
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 function getFunctionName(fn) {
|
|
11
|
+
if (fn.name) {
|
|
12
|
+
return fn.name;
|
|
13
|
+
}
|
|
14
|
+
// Try to extract name from function toString()
|
|
15
|
+
const fnStr = fn.toString();
|
|
16
|
+
const nameMatch = fnStr.match(/function\s+([^(]+)/);
|
|
17
|
+
if (nameMatch) {
|
|
18
|
+
return nameMatch[1].trim();
|
|
19
|
+
}
|
|
20
|
+
// For arrow functions or anonymous functions
|
|
21
|
+
const arrowMatch = fnStr.match(/^\s*(?:async\s+)?(?:\([^)]*\)|\w+)\s*=>/);
|
|
22
|
+
if (arrowMatch) {
|
|
23
|
+
return '<arrow function>';
|
|
24
|
+
}
|
|
25
|
+
return '<anonymous>';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the current call stack
|
|
29
|
+
*
|
|
30
|
+
* @returns An array of function names in the call stack
|
|
31
|
+
*/
|
|
32
|
+
export function getCallStack() {
|
|
33
|
+
const stack = new Error().stack;
|
|
34
|
+
if (!stack) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
// Parse the stack trace
|
|
38
|
+
return stack
|
|
39
|
+
.split('\n')
|
|
40
|
+
.slice(2) // Skip the Error and this function
|
|
41
|
+
.map(line => {
|
|
42
|
+
const match = line.match(/at\s+([^\s]+)/);
|
|
43
|
+
return match ? match[1] : line.trim();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* CallStackManager - Manages a call stack for execution tracking
|
|
48
|
+
*/
|
|
49
|
+
export class CallStackManager {
|
|
50
|
+
constructor() {
|
|
51
|
+
this._stack = [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Push a function name onto the call stack
|
|
55
|
+
*
|
|
56
|
+
* @param name - The function name
|
|
57
|
+
* @returns The current stack depth
|
|
58
|
+
*/
|
|
59
|
+
push(name) {
|
|
60
|
+
this._stack.push(name);
|
|
61
|
+
return this._stack.length;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pop a function name from the call stack
|
|
65
|
+
*
|
|
66
|
+
* @returns The popped function name or undefined if the stack is empty
|
|
67
|
+
*/
|
|
68
|
+
pop() {
|
|
69
|
+
return this._stack.pop();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the current call stack
|
|
73
|
+
*
|
|
74
|
+
* @returns A copy of the current call stack
|
|
75
|
+
*/
|
|
76
|
+
getStack() {
|
|
77
|
+
return [...this._stack];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the current stack depth
|
|
81
|
+
*
|
|
82
|
+
* @returns The current stack depth
|
|
83
|
+
*/
|
|
84
|
+
getDepth() {
|
|
85
|
+
return this._stack.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clear the call stack
|
|
89
|
+
*/
|
|
90
|
+
clear() {
|
|
91
|
+
this._stack = [];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the current function name (top of the stack)
|
|
95
|
+
*
|
|
96
|
+
* @returns The current function name or undefined if the stack is empty
|
|
97
|
+
*/
|
|
98
|
+
getCurrentFunction() {
|
|
99
|
+
return this._stack[this._stack.length - 1];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the parent function name
|
|
103
|
+
*
|
|
104
|
+
* @returns The parent function name or undefined if there is no parent
|
|
105
|
+
*/
|
|
106
|
+
getParentFunction() {
|
|
107
|
+
return this._stack[this._stack.length - 2];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/utils/stack.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,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,CAAC;QACd,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,6CAA6C;IAC7C,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC1E,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wBAAwB;IACxB,OAAO,KAAK;SACT,KAAK,CAAC,IAAI,CAAC;SACX,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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,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;AAC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AAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,QAAQ;QACb,OAAO,GAAG,IAAI,CAAC,MAAM,KAAK,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;IACjE,CAAC;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -30,4 +30,17 @@ __exportStar(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"}
|
package/dist/types/config.js
CHANGED
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.1",
|
|
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\"",
|