traceperf 0.1.4 → 0.2.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/README.md +230 -263
- package/dist/browser.d.ts +52 -7
- package/dist/browser.js +198 -35
- package/dist/browser.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/optimized-performance-monitor.d.ts +227 -0
- package/dist/core/optimized-performance-monitor.js +543 -0
- package/dist/core/optimized-performance-monitor.js.map +1 -0
- package/dist/esm/browser.d.ts +52 -7
- package/dist/esm/browser.js +196 -34
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/core/index.d.ts +1 -0
- package/dist/esm/core/index.js +1 -0
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/optimized-performance-monitor.d.ts +227 -0
- package/dist/esm/core/optimized-performance-monitor.js +535 -0
- package/dist/esm/core/optimized-performance-monitor.js.map +1 -0
- package/dist/esm/index.d.ts +7 -8
- package/dist/esm/index.js +18 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/trackers/execution.d.ts +34 -26
- package/dist/esm/trackers/execution.js +99 -60
- package/dist/esm/trackers/execution.js.map +1 -1
- package/dist/esm/trackers/performance.d.ts +7 -21
- package/dist/esm/trackers/performance.js +25 -19
- package/dist/esm/trackers/performance.js.map +1 -1
- package/dist/esm/types/config.d.ts +16 -2
- package/dist/esm/types/index.d.ts +32 -34
- package/dist/esm/types/logger.d.ts +11 -2
- package/dist/esm/utils/colors.js +12 -0
- package/dist/esm/utils/colors.js.map +1 -1
- package/dist/esm/utils/string.d.ts +29 -0
- package/dist/esm/utils/string.js +45 -0
- package/dist/esm/utils/string.js.map +1 -0
- package/dist/index.d.ts +7 -8
- package/dist/index.js +42 -20
- package/dist/index.js.map +1 -1
- package/dist/trackers/execution.d.ts +34 -26
- package/dist/trackers/execution.js +98 -59
- package/dist/trackers/execution.js.map +1 -1
- package/dist/trackers/performance.d.ts +7 -21
- package/dist/trackers/performance.js +25 -19
- package/dist/trackers/performance.js.map +1 -1
- package/dist/types/config.d.ts +16 -2
- package/dist/types/index.d.ts +32 -34
- package/dist/types/logger.d.ts +11 -2
- package/dist/types.d.ts +65 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/colors.js +12 -0
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/string.d.ts +29 -0
- package/dist/utils/string.js +50 -0
- package/dist/utils/string.js.map +1 -0
- package/package.json +11 -8
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized Performance Monitoring Library
|
|
3
|
+
*
|
|
4
|
+
* This implementation incorporates all optimizations from benchmarking:
|
|
5
|
+
* 1. Tiered tracking modes for performance vs. detail balance
|
|
6
|
+
* 2. Context preservation for object methods
|
|
7
|
+
* 3. Async/Promise support
|
|
8
|
+
* 4. Browser/Node.js environment detection
|
|
9
|
+
* 5. Memory usage tracking optimizations
|
|
10
|
+
* 6. Module registration capability
|
|
11
|
+
* 7. Enhanced visualization
|
|
12
|
+
*/
|
|
13
|
+
export declare const TrackingModes: {
|
|
14
|
+
PERFORMANCE: string;
|
|
15
|
+
BALANCED: string;
|
|
16
|
+
DETAILED: string;
|
|
17
|
+
DEBUG: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Get current memory usage with environment detection
|
|
21
|
+
* @returns Memory usage in bytes
|
|
22
|
+
*/
|
|
23
|
+
export declare const getMemoryUsage: () => number;
|
|
24
|
+
/**
|
|
25
|
+
* Get high-resolution timestamp with environment detection
|
|
26
|
+
* @returns Timestamp in nanoseconds
|
|
27
|
+
*/
|
|
28
|
+
export declare const getTimestamp: () => number;
|
|
29
|
+
/**
|
|
30
|
+
* Calculate time difference between two timestamps
|
|
31
|
+
* @param startTime Starting timestamp in nanoseconds
|
|
32
|
+
* @returns Duration in nanoseconds
|
|
33
|
+
*/
|
|
34
|
+
export declare const getDuration: (startTime: number) => number;
|
|
35
|
+
/**
|
|
36
|
+
* Interface for execution tracking options
|
|
37
|
+
*/
|
|
38
|
+
export interface ExecutionTrackerOptions {
|
|
39
|
+
trackingMode?: string;
|
|
40
|
+
silent?: boolean;
|
|
41
|
+
showMemoryUsage?: boolean;
|
|
42
|
+
enableNestedTracking?: boolean;
|
|
43
|
+
threshold?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Interface for timer options
|
|
47
|
+
*/
|
|
48
|
+
export interface TimerOptions {
|
|
49
|
+
trackMemory?: boolean;
|
|
50
|
+
captureArgs?: boolean;
|
|
51
|
+
args?: any[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Interface for execution data
|
|
55
|
+
*/
|
|
56
|
+
export interface ExecutionData {
|
|
57
|
+
id: string;
|
|
58
|
+
label: string;
|
|
59
|
+
startTime: number;
|
|
60
|
+
endTime: number;
|
|
61
|
+
duration: number;
|
|
62
|
+
parentId: string | null;
|
|
63
|
+
children: string[];
|
|
64
|
+
args?: string[];
|
|
65
|
+
complete: boolean;
|
|
66
|
+
memoryAtStart?: number;
|
|
67
|
+
memoryAtEnd?: number;
|
|
68
|
+
memoryDelta?: number;
|
|
69
|
+
result?: any;
|
|
70
|
+
error?: Error | null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Optimized tracker for individual function executions
|
|
74
|
+
*/
|
|
75
|
+
export declare class OptimizedExecutionTracker {
|
|
76
|
+
private executionTree;
|
|
77
|
+
private currentExecutionId;
|
|
78
|
+
private activeExecutions;
|
|
79
|
+
showMemoryUsage: boolean;
|
|
80
|
+
enableNestedTracking: boolean;
|
|
81
|
+
silent: boolean;
|
|
82
|
+
trackingMode: string;
|
|
83
|
+
defaultThreshold: number;
|
|
84
|
+
private _formatters;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new execution tracker
|
|
87
|
+
* @param options Tracker configuration options
|
|
88
|
+
*/
|
|
89
|
+
constructor(options?: ExecutionTrackerOptions);
|
|
90
|
+
/**
|
|
91
|
+
* Start timing a function execution
|
|
92
|
+
* @param label Function name or label
|
|
93
|
+
* @param parentExecutionId ID of parent execution if nested
|
|
94
|
+
* @param options Additional options
|
|
95
|
+
* @returns Execution ID
|
|
96
|
+
*/
|
|
97
|
+
startTimer(label: string, parentExecutionId?: string | null, options?: TimerOptions): string;
|
|
98
|
+
/**
|
|
99
|
+
* End timing a function execution
|
|
100
|
+
* @param executionId ID of the execution to end
|
|
101
|
+
* @param result Result of the function
|
|
102
|
+
* @param error Error if the function threw
|
|
103
|
+
* @returns Execution data
|
|
104
|
+
*/
|
|
105
|
+
endTimer(executionId: string, result?: any, error?: Error | null): ExecutionData | null;
|
|
106
|
+
/**
|
|
107
|
+
* Generate a visualization of the execution flow
|
|
108
|
+
* @param execution The execution to visualize
|
|
109
|
+
* @param depth Current depth in the tree
|
|
110
|
+
* @param isLastChild Whether this is the last child
|
|
111
|
+
* @param ancestors Array tracking if parents were last children
|
|
112
|
+
* @returns Formatted execution flow chart
|
|
113
|
+
*/
|
|
114
|
+
private _generateExecutionFlowChart;
|
|
115
|
+
/**
|
|
116
|
+
* Create a trackable version of a function
|
|
117
|
+
* @param fn Function to track
|
|
118
|
+
* @param options Tracking options
|
|
119
|
+
* @returns Tracked version of the function
|
|
120
|
+
*/
|
|
121
|
+
createTrackable<T extends (...args: any[]) => any>(fn: T, options?: Record<string, any>): (...args: Parameters<T>) => ReturnType<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Track a module's methods
|
|
124
|
+
* @param module Module to track
|
|
125
|
+
* @param options Tracking options
|
|
126
|
+
* @returns Tracked module
|
|
127
|
+
*/
|
|
128
|
+
trackModule<T extends Record<string, any>>(module: T, options?: Record<string, any>): T;
|
|
129
|
+
/**
|
|
130
|
+
* Track a function execution directly
|
|
131
|
+
* @param fn Function to track
|
|
132
|
+
* @param options Tracking options
|
|
133
|
+
* @returns Function result
|
|
134
|
+
*/
|
|
135
|
+
track<T>(fn: () => T, options?: Record<string, any>): T;
|
|
136
|
+
/**
|
|
137
|
+
* Reset the tracker state
|
|
138
|
+
*/
|
|
139
|
+
reset(): void;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Interface for performance monitor options
|
|
143
|
+
*/
|
|
144
|
+
export interface PerformanceMonitorOptions {
|
|
145
|
+
trackingMode?: string;
|
|
146
|
+
silent?: boolean;
|
|
147
|
+
trackMemory?: boolean;
|
|
148
|
+
enableNestedTracking?: boolean;
|
|
149
|
+
threshold?: number;
|
|
150
|
+
sampleRate?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Main performance monitoring interface
|
|
154
|
+
*/
|
|
155
|
+
export declare class OptimizedPerformanceMonitor {
|
|
156
|
+
private config;
|
|
157
|
+
private executionTracker;
|
|
158
|
+
/**
|
|
159
|
+
* Create a new performance monitor instance
|
|
160
|
+
* @param options Configuration options
|
|
161
|
+
*/
|
|
162
|
+
constructor(options?: PerformanceMonitorOptions);
|
|
163
|
+
/**
|
|
164
|
+
* Track a function execution
|
|
165
|
+
* @param fn The function to track
|
|
166
|
+
* @param options Tracking options
|
|
167
|
+
* @returns Result of the tracked function
|
|
168
|
+
*/
|
|
169
|
+
track<T>(fn: () => T, options?: Record<string, any>): T;
|
|
170
|
+
/**
|
|
171
|
+
* Create a trackable version of a function
|
|
172
|
+
* @param fn The function to track
|
|
173
|
+
* @param options Tracking options
|
|
174
|
+
* @returns Tracked version of the function
|
|
175
|
+
*/
|
|
176
|
+
createTrackable<T extends (...args: any[]) => any>(fn: T, options?: Record<string, any>): (...args: Parameters<T>) => ReturnType<T>;
|
|
177
|
+
/**
|
|
178
|
+
* Register a module for tracking
|
|
179
|
+
* @param module The module or object containing methods to track
|
|
180
|
+
* @param options Tracking options
|
|
181
|
+
* @returns Modified module with tracked methods
|
|
182
|
+
*/
|
|
183
|
+
registerModule<T extends Record<string, any>>(module: T, options?: Record<string, any>): T;
|
|
184
|
+
/**
|
|
185
|
+
* Set configuration options
|
|
186
|
+
* @param config Configuration to update
|
|
187
|
+
* @returns Current configuration after update
|
|
188
|
+
*/
|
|
189
|
+
setConfig(config?: Partial<PerformanceMonitorOptions>): Record<string, any>;
|
|
190
|
+
/**
|
|
191
|
+
* Enable silent mode (no console output)
|
|
192
|
+
* @returns This instance for chaining
|
|
193
|
+
*/
|
|
194
|
+
enableSilentMode(): OptimizedPerformanceMonitor;
|
|
195
|
+
/**
|
|
196
|
+
* Disable silent mode (allow console output)
|
|
197
|
+
* @returns This instance for chaining
|
|
198
|
+
*/
|
|
199
|
+
disableSilentMode(): OptimizedPerformanceMonitor;
|
|
200
|
+
/**
|
|
201
|
+
* Set the tracking mode
|
|
202
|
+
* @param mode Tracking mode from TrackingMode enum
|
|
203
|
+
* @returns This instance for chaining
|
|
204
|
+
*/
|
|
205
|
+
setTrackingMode(mode: string): OptimizedPerformanceMonitor;
|
|
206
|
+
/**
|
|
207
|
+
* Enable memory usage tracking
|
|
208
|
+
* @returns This instance for chaining
|
|
209
|
+
*/
|
|
210
|
+
enableMemoryTracking(): OptimizedPerformanceMonitor;
|
|
211
|
+
/**
|
|
212
|
+
* Disable memory usage tracking
|
|
213
|
+
* @returns This instance for chaining
|
|
214
|
+
*/
|
|
215
|
+
disableMemoryTracking(): OptimizedPerformanceMonitor;
|
|
216
|
+
/**
|
|
217
|
+
* Set the sampling rate
|
|
218
|
+
* @param rate Sampling rate between 0.0 and 1.0
|
|
219
|
+
* @returns This instance for chaining
|
|
220
|
+
*/
|
|
221
|
+
setSampleRate(rate: number): OptimizedPerformanceMonitor;
|
|
222
|
+
/**
|
|
223
|
+
* Reset the tracker state
|
|
224
|
+
* @returns This instance for chaining
|
|
225
|
+
*/
|
|
226
|
+
reset(): OptimizedPerformanceMonitor;
|
|
227
|
+
}
|