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,127 @@
|
|
|
1
|
+
import { LogMode, ITrackOptions } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* ILogger - Interface for the main logger functionality
|
|
4
|
+
*/
|
|
5
|
+
export interface ILogger {
|
|
6
|
+
/**
|
|
7
|
+
* Log an informational message
|
|
8
|
+
*
|
|
9
|
+
* @param message - The message to log
|
|
10
|
+
* @param args - Additional arguments to include in the log
|
|
11
|
+
*/
|
|
12
|
+
info(message: string | object, ...args: any[]): void;
|
|
13
|
+
/**
|
|
14
|
+
* Log a warning message
|
|
15
|
+
*
|
|
16
|
+
* @param message - The message to log
|
|
17
|
+
* @param args - Additional arguments to include in the log
|
|
18
|
+
*/
|
|
19
|
+
warn(message: string | object, ...args: any[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Log an error message
|
|
22
|
+
*
|
|
23
|
+
* @param message - The message to log
|
|
24
|
+
* @param args - Additional arguments to include in the log
|
|
25
|
+
*/
|
|
26
|
+
error(message: string | object, ...args: any[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Log a debug message
|
|
29
|
+
*
|
|
30
|
+
* @param message - The message to log
|
|
31
|
+
* @param args - Additional arguments to include in the log
|
|
32
|
+
*/
|
|
33
|
+
debug(message: string | object, ...args: any[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Start a new log group with the given label
|
|
36
|
+
*
|
|
37
|
+
* @param label - The label for the group
|
|
38
|
+
*/
|
|
39
|
+
group(label: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* End the current log group
|
|
42
|
+
*/
|
|
43
|
+
groupEnd(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Set the operational mode for the logger
|
|
46
|
+
*
|
|
47
|
+
* @param mode - The mode to set
|
|
48
|
+
*/
|
|
49
|
+
setMode(mode: LogMode): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get the current operational mode
|
|
52
|
+
*
|
|
53
|
+
* @returns The current mode
|
|
54
|
+
*/
|
|
55
|
+
getMode(): LogMode;
|
|
56
|
+
/**
|
|
57
|
+
* Track the execution of a function and log performance metrics
|
|
58
|
+
*
|
|
59
|
+
* @param fn - The function to track
|
|
60
|
+
* @param options - Options for tracking
|
|
61
|
+
* @returns The return value of the tracked function
|
|
62
|
+
*/
|
|
63
|
+
track<T>(fn: () => T, options?: ITrackOptions): T;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* IExecutionTracker - Interface for tracking function execution
|
|
67
|
+
*/
|
|
68
|
+
export interface IExecutionTracker {
|
|
69
|
+
/**
|
|
70
|
+
* Track the execution of a function
|
|
71
|
+
*
|
|
72
|
+
* @param fn - The function to track
|
|
73
|
+
* @param options - Options for tracking
|
|
74
|
+
* @returns The return value of the tracked function
|
|
75
|
+
*/
|
|
76
|
+
track<T>(fn: () => T, options?: ITrackOptions): T;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current call stack
|
|
79
|
+
*
|
|
80
|
+
* @returns The current call stack
|
|
81
|
+
*/
|
|
82
|
+
getCallStack(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Generate a visual representation of the execution flow
|
|
85
|
+
*
|
|
86
|
+
* @returns ASCII flow chart of the execution
|
|
87
|
+
*/
|
|
88
|
+
generateFlowChart(): string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* IPerformanceMonitor - Interface for monitoring performance
|
|
92
|
+
*/
|
|
93
|
+
export interface IPerformanceMonitor {
|
|
94
|
+
/**
|
|
95
|
+
* Start timing an operation
|
|
96
|
+
*
|
|
97
|
+
* @param label - Label for the operation
|
|
98
|
+
* @returns A unique identifier for the timing operation
|
|
99
|
+
*/
|
|
100
|
+
startTimer(label: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* End timing an operation
|
|
103
|
+
*
|
|
104
|
+
* @param id - The identifier returned by startTimer
|
|
105
|
+
* @returns The duration in milliseconds
|
|
106
|
+
*/
|
|
107
|
+
endTimer(id: string): number;
|
|
108
|
+
/**
|
|
109
|
+
* Check if an operation exceeds the performance threshold
|
|
110
|
+
*
|
|
111
|
+
* @param duration - The duration in milliseconds
|
|
112
|
+
* @param threshold - The threshold to check against
|
|
113
|
+
* @returns Whether the operation is considered slow
|
|
114
|
+
*/
|
|
115
|
+
isBottleneck(duration: number, threshold?: number): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Get memory usage information
|
|
118
|
+
*
|
|
119
|
+
* @returns Memory usage in bytes
|
|
120
|
+
*/
|
|
121
|
+
getMemoryUsage(): {
|
|
122
|
+
heapUsed: number;
|
|
123
|
+
heapTotal: number;
|
|
124
|
+
external: number;
|
|
125
|
+
rss: number;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/types/logger.ts"],"names":[],"mappings":""}
|
|
@@ -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,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
|
+
}
|
|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IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -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,O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+
/**
|
|
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
|
+
}
|