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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible version of TracePerf
|
|
3
|
+
*
|
|
4
|
+
* This file provides a browser-compatible version of TracePerf that can be used
|
|
5
|
+
* in React, Next.js, or other frontend applications.
|
|
6
|
+
*/
|
|
7
|
+
import { ILoggerConfig, LogMode, ITrackOptions } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Browser-compatible performance monitoring
|
|
10
|
+
*/
|
|
11
|
+
declare class BrowserPerformanceMonitor {
|
|
12
|
+
private _timers;
|
|
13
|
+
private _defaultThreshold;
|
|
14
|
+
constructor(options?: {
|
|
15
|
+
defaultThreshold?: number;
|
|
16
|
+
});
|
|
17
|
+
startTimer(label: string): string;
|
|
18
|
+
endTimer(id: string): number;
|
|
19
|
+
isBottleneck(duration: number, threshold?: number): boolean;
|
|
20
|
+
getMemoryUsage(): {
|
|
21
|
+
heapUsed: number;
|
|
22
|
+
heapTotal: number;
|
|
23
|
+
external: number;
|
|
24
|
+
rss: number;
|
|
25
|
+
};
|
|
26
|
+
generateSuggestion(functionName: string, duration: number, memoryUsage?: number): string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Browser-compatible execution tracker for tracking function calls and generating flow charts
|
|
30
|
+
*/
|
|
31
|
+
declare class BrowserExecutionTracker {
|
|
32
|
+
private _callStack;
|
|
33
|
+
private _executions;
|
|
34
|
+
private _currentExecution;
|
|
35
|
+
private _defaultThreshold;
|
|
36
|
+
private _instrumentedFunctions;
|
|
37
|
+
private _isInstrumented;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new BrowserExecutionTracker instance
|
|
40
|
+
*
|
|
41
|
+
* @param options - Tracker options
|
|
42
|
+
*/
|
|
43
|
+
constructor(options?: {
|
|
44
|
+
defaultThreshold?: number;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Generate a performance optimization suggestion based on execution duration
|
|
48
|
+
*
|
|
49
|
+
* @param name - Function name
|
|
50
|
+
* @param duration - Execution duration in ms
|
|
51
|
+
* @returns Optimization suggestion
|
|
52
|
+
*/
|
|
53
|
+
private generateSuggestion;
|
|
54
|
+
/**
|
|
55
|
+
* Track the execution of a function
|
|
56
|
+
*
|
|
57
|
+
* @param fn - The function to track
|
|
58
|
+
* @param options - Options for tracking
|
|
59
|
+
* @returns The return value of the tracked function
|
|
60
|
+
*/
|
|
61
|
+
track<T>(fn: () => T, options?: any): T;
|
|
62
|
+
/**
|
|
63
|
+
* Instrument a function to track nested function calls
|
|
64
|
+
*
|
|
65
|
+
* @param fn - The function to instrument
|
|
66
|
+
* @returns The instrumented function
|
|
67
|
+
*/
|
|
68
|
+
private instrumentFunction;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current call stack
|
|
71
|
+
*
|
|
72
|
+
* @returns The current call stack
|
|
73
|
+
*/
|
|
74
|
+
getCallStack(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Generate a visual representation of the execution flow
|
|
77
|
+
*
|
|
78
|
+
* @returns ASCII flow chart of the execution
|
|
79
|
+
*/
|
|
80
|
+
generateFlowChart(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Prepare execution data for the flow chart
|
|
83
|
+
*
|
|
84
|
+
* @param executions - The execution records to prepare
|
|
85
|
+
* @returns A list of execution data
|
|
86
|
+
*/
|
|
87
|
+
private prepareExecutionData;
|
|
88
|
+
/**
|
|
89
|
+
* Add children to the result list
|
|
90
|
+
*
|
|
91
|
+
* @param children - The children to add
|
|
92
|
+
* @param result - The result list
|
|
93
|
+
*/
|
|
94
|
+
private addChildrenToResult;
|
|
95
|
+
/**
|
|
96
|
+
* Clear all execution records
|
|
97
|
+
*/
|
|
98
|
+
clear(): void;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Browser-compatible logger
|
|
102
|
+
*/
|
|
103
|
+
declare class BrowserLogger {
|
|
104
|
+
private _mode;
|
|
105
|
+
private _indentLevel;
|
|
106
|
+
private _executionTracker;
|
|
107
|
+
private _performanceMonitor;
|
|
108
|
+
constructor(config?: Partial<ILoggerConfig>);
|
|
109
|
+
info(message: string | object, ...args: any[]): void;
|
|
110
|
+
warn(message: string | object, ...args: any[]): void;
|
|
111
|
+
error(message: string | object, ...args: any[]): void;
|
|
112
|
+
debug(message: string | object, ...args: any[]): void;
|
|
113
|
+
group(label: string): void;
|
|
114
|
+
groupEnd(): void;
|
|
115
|
+
setMode(mode: LogMode): void;
|
|
116
|
+
getMode(): LogMode;
|
|
117
|
+
track<T>(fn: () => T, options?: ITrackOptions): T;
|
|
118
|
+
private log;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a new browser logger instance
|
|
122
|
+
*
|
|
123
|
+
* @param config - Configuration options
|
|
124
|
+
* @returns A new BrowserLogger instance
|
|
125
|
+
*/
|
|
126
|
+
export declare function createBrowserLogger(config?: Partial<ILoggerConfig>): BrowserLogger;
|
|
127
|
+
declare const defaultBrowserLogger: BrowserLogger;
|
|
128
|
+
export default defaultBrowserLogger;
|
|
129
|
+
export { BrowserLogger, BrowserPerformanceMonitor, BrowserExecutionTracker };
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible version of TracePerf
|
|
3
|
+
*
|
|
4
|
+
* This file provides a browser-compatible version of TracePerf that can be used
|
|
5
|
+
* in React, Next.js, or other frontend applications.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Browser-compatible performance monitoring
|
|
9
|
+
*/
|
|
10
|
+
class BrowserPerformanceMonitor {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
this._timers = new Map();
|
|
14
|
+
this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
|
|
15
|
+
}
|
|
16
|
+
startTimer(label) {
|
|
17
|
+
const id = `${label}-${Math.random().toString(36).substring(2, 9)}`;
|
|
18
|
+
this._timers.set(id, performance.now());
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
endTimer(id) {
|
|
22
|
+
const startTime = this._timers.get(id);
|
|
23
|
+
if (!startTime) {
|
|
24
|
+
throw new Error(`Timer with id ${id} not found`);
|
|
25
|
+
}
|
|
26
|
+
const duration = performance.now() - startTime;
|
|
27
|
+
this._timers.delete(id);
|
|
28
|
+
return duration;
|
|
29
|
+
}
|
|
30
|
+
isBottleneck(duration, threshold) {
|
|
31
|
+
const effectiveThreshold = threshold !== null && threshold !== void 0 ? threshold : this._defaultThreshold;
|
|
32
|
+
return duration > effectiveThreshold;
|
|
33
|
+
}
|
|
34
|
+
getMemoryUsage() {
|
|
35
|
+
// Use browser performance API if available
|
|
36
|
+
if (performance && 'memory' in performance) {
|
|
37
|
+
const memory = performance.memory;
|
|
38
|
+
return {
|
|
39
|
+
heapUsed: (memory === null || memory === void 0 ? void 0 : memory.usedJSHeapSize) || 0,
|
|
40
|
+
heapTotal: (memory === null || memory === void 0 ? void 0 : memory.totalJSHeapSize) || 0,
|
|
41
|
+
external: 0, // Not available in browser
|
|
42
|
+
rss: 0, // Not available in browser
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Fallback for browsers without memory API
|
|
46
|
+
return {
|
|
47
|
+
heapUsed: 0,
|
|
48
|
+
heapTotal: 0,
|
|
49
|
+
external: 0,
|
|
50
|
+
rss: 0,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
generateSuggestion(functionName, duration, memoryUsage) {
|
|
54
|
+
if (duration > 1000) {
|
|
55
|
+
return `🛠 Potential Fix: Consider optimizing or adding caching to ${functionName}`;
|
|
56
|
+
}
|
|
57
|
+
if (duration > 500) {
|
|
58
|
+
return `🛠 Potential Fix: Look for blocking operations in ${functionName}`;
|
|
59
|
+
}
|
|
60
|
+
return `🛠 Potential Fix: Review ${functionName} for performance optimizations`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Browser-compatible execution tracker for tracking function calls and generating flow charts
|
|
65
|
+
*/
|
|
66
|
+
class BrowserExecutionTracker {
|
|
67
|
+
/**
|
|
68
|
+
* Create a new BrowserExecutionTracker instance
|
|
69
|
+
*
|
|
70
|
+
* @param options - Tracker options
|
|
71
|
+
*/
|
|
72
|
+
constructor(options = {}) {
|
|
73
|
+
var _a;
|
|
74
|
+
this._callStack = [];
|
|
75
|
+
this._executions = [];
|
|
76
|
+
this._currentExecution = null;
|
|
77
|
+
this._instrumentedFunctions = new Map();
|
|
78
|
+
this._isInstrumented = false;
|
|
79
|
+
this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generate a performance optimization suggestion based on execution duration
|
|
83
|
+
*
|
|
84
|
+
* @param name - Function name
|
|
85
|
+
* @param duration - Execution duration in ms
|
|
86
|
+
* @returns Optimization suggestion
|
|
87
|
+
*/
|
|
88
|
+
generateSuggestion(name, duration) {
|
|
89
|
+
if (duration > 500) {
|
|
90
|
+
return `Function "${name}" took ${duration.toFixed(2)}ms to execute. Consider optimizing or breaking it down into smaller functions.`;
|
|
91
|
+
}
|
|
92
|
+
else if (duration > 200) {
|
|
93
|
+
return `Function "${name}" took ${duration.toFixed(2)}ms to execute. Consider optimizing if called frequently.`;
|
|
94
|
+
}
|
|
95
|
+
else if (duration > 100) {
|
|
96
|
+
return `Function "${name}" took ${duration.toFixed(2)}ms to execute. Monitor if called in critical paths.`;
|
|
97
|
+
}
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Track the execution of a function
|
|
102
|
+
*
|
|
103
|
+
* @param fn - The function to track
|
|
104
|
+
* @param options - Options for tracking
|
|
105
|
+
* @returns The return value of the tracked function
|
|
106
|
+
*/
|
|
107
|
+
track(fn, options = {}) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const fnName = options.label || fn.name || 'anonymous';
|
|
110
|
+
const threshold = (_a = options.threshold) !== null && _a !== void 0 ? _a : this._defaultThreshold;
|
|
111
|
+
const enableNestedTracking = (_b = options.enableNestedTracking) !== null && _b !== void 0 ? _b : true;
|
|
112
|
+
// Add to call stack
|
|
113
|
+
this._callStack.push(fnName);
|
|
114
|
+
// Create execution record
|
|
115
|
+
const execution = {
|
|
116
|
+
name: fnName,
|
|
117
|
+
duration: 0,
|
|
118
|
+
isSlow: false,
|
|
119
|
+
level: this._callStack.length - 1,
|
|
120
|
+
startTime: performance.now(),
|
|
121
|
+
children: [],
|
|
122
|
+
};
|
|
123
|
+
// Set parent-child relationship
|
|
124
|
+
if (this._currentExecution) {
|
|
125
|
+
execution.parent = this._currentExecution;
|
|
126
|
+
this._currentExecution.children.push(execution);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// This is a root execution
|
|
130
|
+
this._executions.push(execution);
|
|
131
|
+
}
|
|
132
|
+
// Save the previous current execution
|
|
133
|
+
const previousExecution = this._currentExecution;
|
|
134
|
+
// Set this as the current execution
|
|
135
|
+
this._currentExecution = execution;
|
|
136
|
+
// Flag to track if we're already instrumenting to avoid recursion
|
|
137
|
+
const wasInstrumented = this._isInstrumented;
|
|
138
|
+
let result;
|
|
139
|
+
try {
|
|
140
|
+
// If this is the top-level call and nested tracking is enabled, instrument the function
|
|
141
|
+
if (enableNestedTracking && !wasInstrumented) {
|
|
142
|
+
this._isInstrumented = true;
|
|
143
|
+
// Instrument the function to track nested calls
|
|
144
|
+
const instrumentedFn = this.instrumentFunction(fn);
|
|
145
|
+
result = instrumentedFn();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Execute the function normally
|
|
149
|
+
result = fn();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
// End timing
|
|
154
|
+
const endTime = performance.now();
|
|
155
|
+
execution.endTime = endTime;
|
|
156
|
+
execution.duration = endTime - execution.startTime;
|
|
157
|
+
execution.isSlow = execution.duration > threshold;
|
|
158
|
+
// Restore the previous current execution
|
|
159
|
+
this._currentExecution = previousExecution;
|
|
160
|
+
// Remove from call stack
|
|
161
|
+
this._callStack.pop();
|
|
162
|
+
// Reset instrumentation flag if this was the top-level call
|
|
163
|
+
if (!wasInstrumented) {
|
|
164
|
+
this._isInstrumented = false;
|
|
165
|
+
}
|
|
166
|
+
// Re-throw the error
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
// End timing
|
|
170
|
+
const endTime = performance.now();
|
|
171
|
+
execution.endTime = endTime;
|
|
172
|
+
execution.duration = endTime - execution.startTime;
|
|
173
|
+
execution.isSlow = execution.duration > threshold;
|
|
174
|
+
// Generate suggestion if slow
|
|
175
|
+
if (execution.isSlow) {
|
|
176
|
+
execution.suggestion = this.generateSuggestion(fnName, execution.duration);
|
|
177
|
+
}
|
|
178
|
+
// Restore the previous current execution
|
|
179
|
+
this._currentExecution = previousExecution;
|
|
180
|
+
// Remove from call stack
|
|
181
|
+
this._callStack.pop();
|
|
182
|
+
// Reset instrumentation flag if this was the top-level call
|
|
183
|
+
if (!wasInstrumented) {
|
|
184
|
+
this._isInstrumented = false;
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Instrument a function to track nested function calls
|
|
190
|
+
*
|
|
191
|
+
* @param fn - The function to instrument
|
|
192
|
+
* @returns The instrumented function
|
|
193
|
+
*/
|
|
194
|
+
instrumentFunction(fn) {
|
|
195
|
+
// If we've already instrumented this function, return the instrumented version
|
|
196
|
+
if (this._instrumentedFunctions.has(fn)) {
|
|
197
|
+
return this._instrumentedFunctions.get(fn);
|
|
198
|
+
}
|
|
199
|
+
// Create a new instrumented function
|
|
200
|
+
const instrumentedFn = () => {
|
|
201
|
+
// Execute the function and track nested calls
|
|
202
|
+
try {
|
|
203
|
+
// We can't actually modify the function at runtime to track nested calls,
|
|
204
|
+
// so we'll just execute it and rely on the call stack for visualization
|
|
205
|
+
return fn();
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
// Re-throw any errors
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
// Cache the instrumented function
|
|
213
|
+
this._instrumentedFunctions.set(fn, instrumentedFn);
|
|
214
|
+
return instrumentedFn;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get the current call stack
|
|
218
|
+
*
|
|
219
|
+
* @returns The current call stack
|
|
220
|
+
*/
|
|
221
|
+
getCallStack() {
|
|
222
|
+
return [...this._callStack];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Generate a visual representation of the execution flow
|
|
226
|
+
*
|
|
227
|
+
* @returns ASCII flow chart of the execution
|
|
228
|
+
*/
|
|
229
|
+
generateFlowChart() {
|
|
230
|
+
let result = 'Execution Flow:\n';
|
|
231
|
+
// Process each execution
|
|
232
|
+
this.prepareExecutionData(this._executions).forEach(execution => {
|
|
233
|
+
const indent = ' '.repeat(execution.level);
|
|
234
|
+
const durationStr = execution.duration.toFixed(2);
|
|
235
|
+
const slowMarker = execution.isSlow ? ' [SLOW]' : '';
|
|
236
|
+
result += `${indent}→ ${execution.name} (${durationStr}ms)${slowMarker}\n`;
|
|
237
|
+
// Add suggestion if available
|
|
238
|
+
if (execution.suggestion) {
|
|
239
|
+
result += `${indent} ⚠️ ${execution.suggestion}\n`;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Prepare execution data for the flow chart
|
|
246
|
+
*
|
|
247
|
+
* @param executions - The execution records to prepare
|
|
248
|
+
* @returns A list of execution data
|
|
249
|
+
*/
|
|
250
|
+
prepareExecutionData(executions) {
|
|
251
|
+
const result = [];
|
|
252
|
+
// Process each root execution
|
|
253
|
+
executions.forEach(execution => {
|
|
254
|
+
// Add the root execution
|
|
255
|
+
result.push({
|
|
256
|
+
name: execution.name,
|
|
257
|
+
duration: execution.duration,
|
|
258
|
+
isSlow: execution.isSlow,
|
|
259
|
+
suggestion: execution.suggestion,
|
|
260
|
+
level: execution.level,
|
|
261
|
+
});
|
|
262
|
+
// Add children recursively
|
|
263
|
+
this.addChildrenToResult(execution.children, result);
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Add children to the result list
|
|
269
|
+
*
|
|
270
|
+
* @param children - The children to add
|
|
271
|
+
* @param result - The result list
|
|
272
|
+
*/
|
|
273
|
+
addChildrenToResult(children, result) {
|
|
274
|
+
children.forEach(child => {
|
|
275
|
+
// Add the child
|
|
276
|
+
result.push({
|
|
277
|
+
name: child.name,
|
|
278
|
+
duration: child.duration,
|
|
279
|
+
isSlow: child.isSlow,
|
|
280
|
+
suggestion: child.suggestion,
|
|
281
|
+
level: child.level,
|
|
282
|
+
});
|
|
283
|
+
// Add grandchildren recursively
|
|
284
|
+
this.addChildrenToResult(child.children, result);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Clear all execution records
|
|
289
|
+
*/
|
|
290
|
+
clear() {
|
|
291
|
+
this._executions = [];
|
|
292
|
+
this._currentExecution = null;
|
|
293
|
+
this._callStack = [];
|
|
294
|
+
this._instrumentedFunctions.clear();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Browser-compatible logger
|
|
299
|
+
*/
|
|
300
|
+
class BrowserLogger {
|
|
301
|
+
constructor(config = {}) {
|
|
302
|
+
this._mode = 'dev';
|
|
303
|
+
this._indentLevel = 0;
|
|
304
|
+
this._mode = config.mode || 'dev';
|
|
305
|
+
this._executionTracker = new BrowserExecutionTracker({
|
|
306
|
+
defaultThreshold: config.performanceThreshold || 100,
|
|
307
|
+
});
|
|
308
|
+
this._performanceMonitor = new BrowserPerformanceMonitor({
|
|
309
|
+
defaultThreshold: config.performanceThreshold || 100,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
info(message, ...args) {
|
|
313
|
+
this.log('info', message, args);
|
|
314
|
+
}
|
|
315
|
+
warn(message, ...args) {
|
|
316
|
+
this.log('warn', message, args);
|
|
317
|
+
}
|
|
318
|
+
error(message, ...args) {
|
|
319
|
+
this.log('error', message, args);
|
|
320
|
+
}
|
|
321
|
+
debug(message, ...args) {
|
|
322
|
+
if (this._mode === 'prod') {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.log('debug', message, args);
|
|
326
|
+
}
|
|
327
|
+
group(label) {
|
|
328
|
+
this.info(label);
|
|
329
|
+
this._indentLevel++;
|
|
330
|
+
if (typeof console.group === 'function') {
|
|
331
|
+
console.group(label);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
groupEnd() {
|
|
335
|
+
if (this._indentLevel > 0) {
|
|
336
|
+
this._indentLevel--;
|
|
337
|
+
}
|
|
338
|
+
if (typeof console.groupEnd === 'function') {
|
|
339
|
+
console.groupEnd();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
setMode(mode) {
|
|
343
|
+
this._mode = mode;
|
|
344
|
+
}
|
|
345
|
+
getMode() {
|
|
346
|
+
return this._mode;
|
|
347
|
+
}
|
|
348
|
+
track(fn, options) {
|
|
349
|
+
var _a;
|
|
350
|
+
const silent = (_a = options === null || options === void 0 ? void 0 : options.silent) !== null && _a !== void 0 ? _a : false;
|
|
351
|
+
// Track the function execution
|
|
352
|
+
const result = this._executionTracker.track(fn, options);
|
|
353
|
+
// Log the execution flow if not silent
|
|
354
|
+
if (!silent) {
|
|
355
|
+
const flowChart = this._executionTracker.generateFlowChart();
|
|
356
|
+
console.log(flowChart);
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
log(level, message, args) {
|
|
361
|
+
// Skip logs based on mode
|
|
362
|
+
if (this._mode === 'prod' && level !== 'error') {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (this._mode === 'staging' && (level === 'debug' || level === 'info')) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
// Format the message
|
|
369
|
+
let formattedMessage;
|
|
370
|
+
if (typeof message === 'string') {
|
|
371
|
+
formattedMessage = message;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
try {
|
|
375
|
+
formattedMessage = JSON.stringify(message, null, 2);
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
formattedMessage = String(message);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// Add indentation
|
|
382
|
+
const indent = ' '.repeat(this._indentLevel);
|
|
383
|
+
formattedMessage = `${indent}${formattedMessage}`;
|
|
384
|
+
// Log to console with appropriate method
|
|
385
|
+
switch (level) {
|
|
386
|
+
case 'info':
|
|
387
|
+
console.info(formattedMessage, ...args);
|
|
388
|
+
break;
|
|
389
|
+
case 'warn':
|
|
390
|
+
console.warn(formattedMessage, ...args);
|
|
391
|
+
break;
|
|
392
|
+
case 'error':
|
|
393
|
+
console.error(formattedMessage, ...args);
|
|
394
|
+
break;
|
|
395
|
+
case 'debug':
|
|
396
|
+
console.debug(formattedMessage, ...args);
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Create a new browser logger instance
|
|
403
|
+
*
|
|
404
|
+
* @param config - Configuration options
|
|
405
|
+
* @returns A new BrowserLogger instance
|
|
406
|
+
*/
|
|
407
|
+
export function createBrowserLogger(config = {}) {
|
|
408
|
+
return new BrowserLogger(config);
|
|
409
|
+
}
|
|
410
|
+
// Create a singleton instance
|
|
411
|
+
const defaultBrowserLogger = new BrowserLogger();
|
|
412
|
+
// Export the singleton instance as the default export
|
|
413
|
+
export default defaultBrowserLogger;
|
|
414
|
+
// Export classes for advanced usage
|
|
415
|
+
export { BrowserLogger, BrowserPerformanceMonitor, BrowserExecutionTracker };
|
|
416
|
+
// Add CommonJS compatibility
|
|
417
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
418
|
+
module.exports = Object.assign(defaultBrowserLogger, {
|
|
419
|
+
default: defaultBrowserLogger,
|
|
420
|
+
createBrowserLogger,
|
|
421
|
+
BrowserLogger,
|
|
422
|
+
BrowserPerformanceMonitor,
|
|
423
|
+
BrowserExecutionTracker
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,yBAAyB;IAI7B,YAAY,UAAyC,EAAE;;QAH/C,YAAO,GAA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,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,MAAM;gBACT,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACzC,MAAM;YACR,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACzC,MAAM;QACV,CAAC;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiC,EAAE;IACrE,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,8BAA8B;AAC9B,MAAM,oBAAoB,GAAG,IAAI,aAAa,EAAE,CAAC;AAEjD,sDAAsD;AACtD,eAAe,oBAAoB,CAAC;AAEpC,oCAAoC;AACpC,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,CAAC;AAE7E,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE;QACnD,OAAO,EAAE,oBAAoB;QAC7B,mBAAmB;QACnB,aAAa;QACb,yBAAyB;QACzB,uBAAuB;KACxB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ILoggerConfig, LogLevel, LogMode } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration manager for the logger
|
|
4
|
+
* Handles merging user config with defaults and provides utility methods
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfigManager {
|
|
7
|
+
private _config;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new ConfigManager instance
|
|
10
|
+
*
|
|
11
|
+
* @param userConfig - User-provided configuration options
|
|
12
|
+
*/
|
|
13
|
+
constructor(userConfig?: Partial<ILoggerConfig>);
|
|
14
|
+
/**
|
|
15
|
+
* Get the current configuration
|
|
16
|
+
*
|
|
17
|
+
* @returns The current configuration
|
|
18
|
+
*/
|
|
19
|
+
getConfig(): ILoggerConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Update the configuration
|
|
22
|
+
*
|
|
23
|
+
* @param newConfig - New configuration options to merge
|
|
24
|
+
*/
|
|
25
|
+
updateConfig(newConfig: Partial<ILoggerConfig>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the current mode
|
|
28
|
+
*
|
|
29
|
+
* @returns The current mode
|
|
30
|
+
*/
|
|
31
|
+
getMode(): LogMode;
|
|
32
|
+
/**
|
|
33
|
+
* Set the current mode
|
|
34
|
+
*
|
|
35
|
+
* @param mode - The mode to set
|
|
36
|
+
*/
|
|
37
|
+
setMode(mode: LogMode): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a log level should be displayed based on the current mode and level
|
|
40
|
+
*
|
|
41
|
+
* @param level - The log level to check
|
|
42
|
+
* @returns Whether the log level should be displayed
|
|
43
|
+
*/
|
|
44
|
+
shouldLog(level: LogLevel): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get the higher priority level between two log levels
|
|
47
|
+
*
|
|
48
|
+
* @param levelA - First log level
|
|
49
|
+
* @param levelB - Second log level
|
|
50
|
+
* @returns The higher priority level
|
|
51
|
+
*/
|
|
52
|
+
private getHigherPriorityLevel;
|
|
53
|
+
/**
|
|
54
|
+
* Get the performance threshold
|
|
55
|
+
*
|
|
56
|
+
* @returns The performance threshold in milliseconds
|
|
57
|
+
*/
|
|
58
|
+
getPerformanceThreshold(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Get the indentation size
|
|
61
|
+
*
|
|
62
|
+
* @returns The number of spaces for each indentation level
|
|
63
|
+
*/
|
|
64
|
+
getIndentSize(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Check if colorization is enabled
|
|
67
|
+
*
|
|
68
|
+
* @returns Whether colorization is enabled
|
|
69
|
+
*/
|
|
70
|
+
isColorEnabled(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Check if timestamps are enabled
|
|
73
|
+
*
|
|
74
|
+
* @returns Whether timestamps are enabled
|
|
75
|
+
*/
|
|
76
|
+
isTimestampEnabled(): boolean;
|
|
77
|
+
}
|