traceperf 0.1.5 → 0.2.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.
Files changed (57) hide show
  1. package/README.md +279 -227
  2. package/dist/browser.d.ts +52 -7
  3. package/dist/browser.js +198 -35
  4. package/dist/browser.js.map +1 -1
  5. package/dist/core/index.d.ts +1 -0
  6. package/dist/core/index.js +1 -0
  7. package/dist/core/index.js.map +1 -1
  8. package/dist/core/optimized-performance-monitor.d.ts +227 -0
  9. package/dist/core/optimized-performance-monitor.js +543 -0
  10. package/dist/core/optimized-performance-monitor.js.map +1 -0
  11. package/dist/esm/browser.d.ts +52 -7
  12. package/dist/esm/browser.js +196 -34
  13. package/dist/esm/browser.js.map +1 -1
  14. package/dist/esm/core/index.d.ts +1 -0
  15. package/dist/esm/core/index.js +1 -0
  16. package/dist/esm/core/index.js.map +1 -1
  17. package/dist/esm/core/optimized-performance-monitor.d.ts +227 -0
  18. package/dist/esm/core/optimized-performance-monitor.js +535 -0
  19. package/dist/esm/core/optimized-performance-monitor.js.map +1 -0
  20. package/dist/esm/index.d.ts +7 -8
  21. package/dist/esm/index.js +18 -19
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/trackers/execution.d.ts +34 -26
  24. package/dist/esm/trackers/execution.js +99 -60
  25. package/dist/esm/trackers/execution.js.map +1 -1
  26. package/dist/esm/trackers/performance.d.ts +7 -21
  27. package/dist/esm/trackers/performance.js +25 -19
  28. package/dist/esm/trackers/performance.js.map +1 -1
  29. package/dist/esm/types/config.d.ts +16 -2
  30. package/dist/esm/types/index.d.ts +32 -34
  31. package/dist/esm/types/logger.d.ts +11 -2
  32. package/dist/esm/utils/colors.js +12 -0
  33. package/dist/esm/utils/colors.js.map +1 -1
  34. package/dist/esm/utils/string.d.ts +29 -0
  35. package/dist/esm/utils/string.js +45 -0
  36. package/dist/esm/utils/string.js.map +1 -0
  37. package/dist/index.d.ts +7 -8
  38. package/dist/index.js +42 -20
  39. package/dist/index.js.map +1 -1
  40. package/dist/trackers/execution.d.ts +34 -26
  41. package/dist/trackers/execution.js +98 -59
  42. package/dist/trackers/execution.js.map +1 -1
  43. package/dist/trackers/performance.d.ts +7 -21
  44. package/dist/trackers/performance.js +25 -19
  45. package/dist/trackers/performance.js.map +1 -1
  46. package/dist/types/config.d.ts +16 -2
  47. package/dist/types/index.d.ts +32 -34
  48. package/dist/types/logger.d.ts +11 -2
  49. package/dist/types.d.ts +65 -0
  50. package/dist/types.js +6 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/utils/colors.js +12 -0
  53. package/dist/utils/colors.js.map +1 -1
  54. package/dist/utils/string.d.ts +29 -0
  55. package/dist/utils/string.js +50 -0
  56. package/dist/utils/string.js.map +1 -0
  57. package/package.json +11 -8
package/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # TracePerf
2
2
 
3
- Advanced console logging & performance tracking for Node.js applications.
3
+ Advanced performance tracking and execution monitoring for Node.js applications.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/traceperf.svg)](https://www.npmjs.com/package/traceperf)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
8
  ## Features
9
9
 
10
- - **Structured and Visually Appealing Logs**: A better alternative to `console.log()` with colors, icons, and formatting.
11
- - **Execution Flow Tracing**: Track function calls and visualize the execution flow with ASCII art.
12
- - **Nested Function Tracking**: Multiple approaches to track nested function calls with detailed visualization.
13
- - **Performance Bottleneck Detection**: Identify slow functions and get suggestions for optimization.
14
- - **Conditional Logging Modes**: Different logging levels for development, staging, and production.
15
- - **Nested Logging**: Group related logs with indentation for better readability.
16
- - **Auto-Remove Debug Logs**: Automatically filter out debug logs in production.
17
- - **Universal Module Compatibility**: Works with both CommonJS and ESM environments.
10
+ - **High-Performance Execution Monitoring**: Track function execution time with minimal overhead
11
+ - **Memory Usage Tracking**: Monitor memory consumption of your functions and identify memory leaks
12
+ - **Flexible Tracking Modes**: Choose between performance, balanced, and detailed tracking based on your needs
13
+ - **Execution Flow Visualization**: Visualize execution flows with intelligent formatting
14
+ - **Nested Function Tracking**: Track function calls within other functions to understand complex flows
15
+ - **Customizable Threshold Detection**: Focus on functions that exceed specific execution time thresholds
16
+ - **Sampling Control**: Adjust sampling rates to minimize performance impact in production
17
+ - **Universal Module Compatibility**: Works with both CommonJS and ESM environments
18
18
 
19
19
  ## Installation
20
20
 
@@ -22,296 +22,348 @@ Advanced console logging & performance tracking for Node.js applications.
22
22
  npm install traceperf
23
23
  ```
24
24
 
25
- ## Basic Usage
26
-
27
- ### CommonJS (Node.js)
25
+ ## Quick Start
28
26
 
29
27
  ```javascript
30
- const tracePerf = require('traceperf');
31
-
32
- // Basic logging
33
- tracePerf.info('This is an info message');
34
- tracePerf.warn('This is a warning message');
35
- tracePerf.error('This is an error message');
36
- tracePerf.debug('This is a debug message');
37
-
38
- // Logging with objects
39
- tracePerf.info('User data:', { id: 1, name: 'John Doe' });
40
-
41
- // Nested logging with groups
42
- tracePerf.group('User Authentication');
43
- tracePerf.info('Checking credentials');
44
- tracePerf.warn('Invalid password attempt');
45
- tracePerf.groupEnd();
28
+ const traceperf = require('traceperf');
29
+
30
+ // Track a synchronous function
31
+ const result = traceperf.track(() => {
32
+ // Your code here
33
+ return 'result';
34
+ }, { label: 'myFunction' });
35
+
36
+ // Track an asynchronous function
37
+ async function main() {
38
+ const result = await traceperf.track(async () => {
39
+ // Your async code here
40
+ return 'async result';
41
+ }, { label: 'asyncFunction' });
42
+ }
46
43
  ```
47
44
 
48
- ### ESM (ECMAScript Modules)
45
+ ## Tracking Modes
46
+
47
+ TracePerf provides different tracking modes to balance performance with detail:
49
48
 
50
49
  ```javascript
51
- import tracePerf from 'traceperf';
50
+ const { TrackingMode, createTracePerf } = require('traceperf');
51
+
52
+ // Create a custom instance with performance-focused tracking
53
+ const performanceTracker = createTracePerf({
54
+ trackingMode: TrackingMode.PERFORMANCE,
55
+ silent: true,
56
+ threshold: 100, // only track functions that take more than 100ms
57
+ sampleRate: 0.1 // only track 10% of function calls
58
+ });
52
59
 
53
- // Use the same API as with CommonJS
54
- tracePerf.info('This is an info message');
60
+ // Create a custom instance with detailed tracking for development
61
+ const devTracker = createTracePerf({
62
+ trackingMode: TrackingMode.DETAILED,
63
+ trackMemory: true,
64
+ enableNestedTracking: true
65
+ });
55
66
  ```
56
67
 
57
-
58
-
59
- ## Conditional Logging Modes
68
+ ## Tracking Individual Functions
60
69
 
61
70
  ```javascript
62
- // Development mode (default)
63
- tracePerf.setMode('dev');
64
- tracePerf.debug('Debug message'); // Shown
65
- tracePerf.info('Info message'); // Shown
66
- tracePerf.warn('Warning message'); // Shown
67
- tracePerf.error('Error message'); // Shown
68
-
69
- // Staging mode
70
- tracePerf.setMode('staging');
71
- tracePerf.debug('Debug message'); // Not shown
72
- tracePerf.info('Info message'); // Not shown
73
- tracePerf.warn('Warning message'); // Shown
74
- tracePerf.error('Error message'); // Shown
75
-
76
- // Production mode
77
- tracePerf.setMode('prod');
78
- tracePerf.debug('Debug message'); // Not shown
79
- tracePerf.info('Info message'); // Not shown
80
- tracePerf.warn('Warning message'); // Not shown
81
- tracePerf.error('Error message'); // Shown
82
- ```
71
+ // Track a single function execution
72
+ const result = traceperf.track(() => {
73
+ // Function body
74
+ return someValue;
75
+ }, {
76
+ label: 'functionName',
77
+ threshold: 50, // ms
78
+ trackMemory: true
79
+ });
83
80
 
84
- ## Browser Usage (React, Next.js, etc.)
81
+ // Create a trackable version of an existing function
82
+ const myFunction = (a, b) => a + b;
83
+ const trackedFunction = traceperf.createTrackable(myFunction, {
84
+ label: 'addition'
85
+ });
85
86
 
86
- TracePerf also provides a browser-compatible version for use in frontend applications:
87
+ // Now use it normally
88
+ const sum = trackedFunction(5, 3); // will be tracked
89
+ ```
87
90
 
88
- ### ESM (Modern Browsers)
91
+ ## Tracking Methods in a Module
89
92
 
90
93
  ```javascript
91
- // Import the browser version
92
- import tracePerf from 'traceperf/browser';
94
+ const userService = {
95
+ getUser: async (id) => { /* implementation */ },
96
+ updateUser: async (id, data) => { /* implementation */ },
97
+ deleteUser: async (id) => { /* implementation */ }
98
+ };
99
+
100
+ // Register all methods for tracking
101
+ const trackedUserService = traceperf.registerModule(userService);
93
102
 
94
- // Use it just like the Node.js version
95
- tracePerf.info('This works in the browser!');
103
+ // Now all method calls will be tracked
104
+ const user = await trackedUserService.getUser(123);
96
105
  ```
97
106
 
98
- ### CommonJS (Bundlers with CommonJS support)
107
+ ## Advanced Configuration
99
108
 
100
109
  ```javascript
101
- // Import the browser version with require
102
- const tracePerf = require('traceperf/browser');
110
+ const { createTracePerf, TrackingMode } = require('traceperf');
103
111
 
104
- // Use it just like the Node.js version
105
- tracePerf.info('This works in the browser with CommonJS bundlers!');
112
+ const customTracker = createTracePerf({
113
+ // Tracking mode affects detail level and performance impact
114
+ trackingMode: TrackingMode.BALANCED,
115
+
116
+ // Enable or disable performance statistics in console
117
+ silent: false,
118
+
119
+ // Track memory usage (slight performance impact)
120
+ trackMemory: true,
121
+
122
+ // Enable tracking of nested function calls
123
+ enableNestedTracking: true,
124
+
125
+ // Minimum execution time to track (milliseconds)
126
+ threshold: 50,
127
+
128
+ // Percentage of function calls to track (0.0 to 1.0)
129
+ sampleRate: 1.0
130
+ });
106
131
  ```
107
132
 
108
- ### Browser Example
133
+ ## Browser Support
109
134
 
110
- ```javascript
111
- // Import using your preferred method
112
- import tracePerf from 'traceperf/browser';
135
+ TracePerf provides a fully synchronized browser implementation that matches the Node.js API:
113
136
 
114
- // Track function performance
115
- function expensiveCalculation() {
116
- // ...complex logic
117
- return result;
118
- }
137
+ ```javascript
138
+ import { createTracePerf, BrowserLogger } from 'traceperf/browser';
139
+
140
+ // Create a browser-optimized instance
141
+ const browserTracker = createTracePerf({
142
+ logger: new BrowserLogger({
143
+ silent: false,
144
+ trackMemory: true
145
+ })
146
+ });
119
147
 
120
- const result = tracePerf.track(expensiveCalculation);
148
+ // Track function execution
149
+ browserTracker.track(() => {
150
+ // Your browser-side code
151
+ }, { label: 'browserOperation' });
152
+
153
+ // Create trackable functions
154
+ const trackedFn = browserTracker.createTrackable(() => {
155
+ // Function implementation
156
+ }, { label: 'trackedBrowserFn' });
157
+
158
+ // Track async operations
159
+ await browserTracker.track(async () => {
160
+ const response = await fetch('/api/data');
161
+ return response.json();
162
+ }, { label: 'fetchData' });
121
163
  ```
122
164
 
123
- ### React Component Example
124
-
125
- ```jsx
126
- import React, { useEffect } from 'react';
127
- import tracePerf from 'traceperf/browser';
128
-
129
- function DataComponent() {
130
- useEffect(() => {
131
- tracePerf.group('Component Lifecycle');
132
- tracePerf.info('Component mounted');
133
-
134
- // Fetch data with performance tracking
135
- tracePerf.track(async () => {
136
- const data = await fetchData();
137
- // Process data...
138
- }, { label: 'fetchAndProcessData', threshold: 300 });
139
-
140
- return () => {
141
- tracePerf.info('Component unmounting');
142
- tracePerf.groupEnd();
143
- };
144
- }, []);
165
+ You can also use it via script tag:
166
+
167
+ ```html
168
+ <script src="dist/traceperf.browser.js"></script>
169
+ <script>
170
+ const { createTracePerf, BrowserLogger } = TracePerf;
145
171
 
146
- // Component rendering...
147
- }
172
+ const browserTracker = createTracePerf({
173
+ logger: new BrowserLogger({
174
+ silent: false,
175
+ trackMemory: true
176
+ })
177
+ });
178
+
179
+ // Use the same API as in Node.js
180
+ browserTracker.track(() => {
181
+ // DOM operations or other browser-side logic
182
+ }, { label: 'domOperation' });
183
+ </script>
148
184
  ```
149
185
 
150
- ## Advanced Usage
151
-
152
- ### Tracking Nested Function Calls
186
+ ## Synchronized Features
153
187
 
154
- TracePerf provides two approaches for tracking nested function calls, allowing you to visualize the complete execution flow of your application:
188
+ TracePerf now provides a consistent API across Node.js and browser environments:
155
189
 
156
- 1. **Using the `createTrackable` method** (recommended)
157
- 2. **Using nested `track` calls**
190
+ - **Unified Tracking API**: The same tracking methods work identically in both environments
191
+ - **Consistent Configuration**: Logger and tracker options are synchronized
192
+ - **Memory Tracking**: Both environments support memory usage tracking
193
+ - **Performance Optimization**: Browser-specific optimizations while maintaining API compatibility
194
+ - **Execution Flow**: Track complex execution flows consistently across environments
158
195
 
159
- #### Using createTrackable (Recommended)
160
-
161
- The `createTrackable` method creates tracked versions of your functions that can be used in place of the original functions:
196
+ Example of cross-environment usage:
162
197
 
163
198
  ```javascript
164
- function fetchData() {
165
- processData();
166
- calculateResults();
167
- }
168
-
169
- function processData() {
170
- // Some processing logic
171
- }
172
-
173
- function calculateResults() {
174
- // Some calculation logic
199
+ // Node.js
200
+ const { createTracePerf } = require('traceperf');
201
+ const nodeTracker = createTracePerf();
202
+
203
+ // Browser
204
+ import { createTracePerf } from 'traceperf/browser';
205
+ const browserTracker = createTracePerf();
206
+
207
+ // Both environments support the same API
208
+ async function trackOperation(tracker) {
209
+ return await tracker.track(async () => {
210
+ const result = await someAsyncOperation();
211
+ return processResult(result);
212
+ }, {
213
+ label: 'mainOperation',
214
+ trackMemory: true
215
+ });
175
216
  }
176
-
177
- // Create tracked versions of all functions
178
- const trackedFetchData = tracePerf.createTrackable(fetchData, { label: 'fetchData' });
179
- const trackedProcessData = tracePerf.createTrackable(processData, { label: 'processData' });
180
- const trackedCalculateResults = tracePerf.createTrackable(calculateResults, { label: 'calculateResults' });
181
-
182
- // Replace the global references to enable tracking
183
- global.processData = trackedProcessData;
184
- global.calculateResults = trackedCalculateResults;
185
-
186
- // Execute the tracked top-level function
187
- trackedFetchData();
188
217
  ```
189
218
 
190
- This will produce a complete execution flow chart showing all nested function calls:
219
+ ## Examples
191
220
 
192
- ```
193
- Execution Flow:
194
- ┌──────────────────────────────┐
195
- │ fetchData │ ⏱ 200ms
196
- └──────────────────────────────┘
197
- │
198
- ▼
199
- ┌──────────────────────────────┐
200
- │ processData │ ⏱ 500ms ⚠️ SLOW
201
- └──────────────────────────────┘
202
- │
203
- ▼
204
- ┌──────────────────────────────┐
205
- │ calculateResults │ ⏱ 300ms
206
- └──────────────────────────────┘
207
- ```
221
+ TracePerf includes several example files to help you get started:
208
222
 
209
- #### Using Nested Track Calls
223
+ - **`examples/optimized-tracking-example.js`**: Demonstrates various ways to use the optimized tracking implementation
224
+ - **`examples/browser-example.js`**: Shows how to use TracePerf in browser environments
210
225
 
211
- For more complex scenarios, you can use nested `track` calls:
226
+ ### Tracking an Async Function
212
227
 
213
228
  ```javascript
214
- tracePerf.track(() => {
215
- // Top-level function logic
216
-
217
- tracePerf.track(() => {
218
- // Nested function logic
219
-
220
- tracePerf.track(() => {
221
- // Deeply nested function logic
222
- }, { label: 'deeplyNestedFunction' });
223
-
224
- }, { label: 'nestedFunction' });
225
-
226
- }, { label: 'topLevelFunction' });
229
+ const { createTracePerf } = require('traceperf');
230
+ const traceperf = createTracePerf();
231
+
232
+ async function fetchData(url) {
233
+ return traceperf.track(async () => {
234
+ const response = await fetch(url);
235
+ return response.json();
236
+ }, {
237
+ label: 'fetchData',
238
+ trackMemory: true
239
+ });
240
+ }
227
241
  ```
228
242
 
229
- #### Controlling Nested Tracking
230
-
231
- You can control nested tracking with the following option:
243
+ ### Tracking Nested Functions
232
244
 
233
245
  ```javascript
234
- // Disable nested tracking entirely
235
- tracePerf.track(fetchData, { enableNestedTracking: false });
236
- ```
246
+ const { createTracePerf } = require('traceperf');
247
+ const traceperf = createTracePerf({ enableNestedTracking: true });
248
+
249
+ async function processData() {
250
+ return await traceperf.track(async () => {
251
+ // This function call will be automatically tracked as a child
252
+ const data = await fetchData();
253
+ return transformData(data);
254
+ }, {
255
+ label: 'processData'
256
+ });
257
+ }
237
258
 
238
- For more examples, see the `examples/nested-tracking.js` and `examples/auto-tracking-example.js` files in the repository.
259
+ async function fetchData() {
260
+ return await traceperf.track(async () => {
261
+ // Implementation
262
+ }, { label: 'fetchData' });
263
+ }
239
264
 
240
- ## API Reference for Nested Tracking
265
+ function transformData(data) {
266
+ return traceperf.track(() => {
267
+ // Implementation
268
+ }, { label: 'transformData' });
269
+ }
270
+ ```
241
271
 
242
- ### createTrackable
272
+ ### Optimizing for Production
243
273
 
244
274
  ```javascript
245
- tracePerf.createTrackable(fn, options)
246
- ```
275
+ const { createTracePerf, TrackingMode } = require('traceperf');
276
+
277
+ // Development environment
278
+ const devTracker = createTracePerf({
279
+ trackingMode: TrackingMode.DETAILED,
280
+ silent: false,
281
+ trackMemory: true,
282
+ threshold: 0 // track everything
283
+ });
247
284
 
248
- Creates a tracked version of a function that can be used for nested function tracking.
285
+ // Production environment
286
+ const prodTracker = createTracePerf({
287
+ trackingMode: TrackingMode.PERFORMANCE,
288
+ silent: true, // don't log to console
289
+ trackMemory: false, // minimize overhead
290
+ threshold: 100, // only track slow functions
291
+ sampleRate: 0.01 // track only 1% of function calls
292
+ });
249
293
 
250
- - `fn`: The function to make trackable
251
- - `options`: Options for tracking
252
- - `label`: Custom label for the function (defaults to function name)
253
- - `threshold`: Performance threshold in milliseconds
254
- - `includeMemory`: Whether to include memory usage tracking
255
- - `enableNestedTracking`: Whether to enable nested tracking (default: true)
294
+ // Use based on environment
295
+ const traceperf = process.env.NODE_ENV === 'production' ? prodTracker : devTracker;
296
+ ```
297
+
298
+ ## Browser Usage
256
299
 
257
- Returns a new function that, when called, will track the execution of the original function.
300
+ To use TracePerf in the browser:
258
301
 
259
- ### Track Options for Nested Tracking
302
+ ```html
303
+ <script src="dist/traceperf.browser.js"></script>
304
+ <script>
305
+ const { createTracePerf, TrackingMode } = TracePerf;
306
+
307
+ const browserTracker = createTracePerf({
308
+ trackingMode: TrackingMode.BALANCED,
309
+ trackMemory: true
310
+ });
311
+
312
+ // Now use it to track your functions
313
+ browserTracker.track(() => {
314
+ // DOM operations or other browser-side logic
315
+ }, { label: 'domOperation' });
316
+ </script>
317
+ ```
260
318
 
261
- When using the `track` method, you can control nested tracking with these options:
319
+ Or with ES modules:
262
320
 
263
321
  ```javascript
264
- tracePerf.track(fn, {
265
- // ... other options
266
- enableNestedTracking: true, // Enable/disable nested tracking
267
- });
268
- ```
322
+ import { createTracePerf, TrackingMode } from 'traceperf/browser';
269
323
 
270
- ```javascript
271
- const { createLogger } = require('traceperf');
272
-
273
- // Create a custom logger instance
274
- const logger = createLogger({
275
- mode: 'dev',
276
- level: 'debug',
277
- colorize: true,
278
- timestamp: true,
279
- performanceThreshold: 100, // ms
280
- indentSize: 2,
324
+ const browserTracker = createTracePerf({
325
+ trackingMode: TrackingMode.BALANCED
281
326
  });
282
327
 
283
- // Use the custom logger
284
- logger.info('Custom logger');
328
+ // Track a DOM operation
329
+ browserTracker.track(() => {
330
+ document.getElementById('output').textContent = 'Updated';
331
+ }, { label: 'updateDOM' });
285
332
  ```
286
333
 
287
- ## API Reference
288
-
289
- ### Logging Methods
334
+ ## Advanced Tracking Features
290
335
 
291
- - `info(message, ...args)`: Log an informational message
292
- - `warn(message, ...args)`: Log a warning message
293
- - `error(message, ...args)`: Log an error message
294
- - `debug(message, ...args)`: Log a debug message (filtered in production)
336
+ ### Tracking with Different Modes
295
337
 
296
- ### Grouping
297
-
298
- - `group(label)`: Start a new log group with the given label
299
- - `groupEnd()`: End the current log group
338
+ ```javascript
339
+ const { createTracePerf, TrackingMode } = require('traceperf');
300
340
 
301
- ### Execution Tracking
341
+ // Performance mode - minimal overhead
342
+ const performanceTracker = createTracePerf({
343
+ trackingMode: TrackingMode.PERFORMANCE
344
+ });
302
345
 
303
- - `track(fn, options)`: Track the execution of a function and log performance metrics
304
- - `options.label`: Custom label for the tracked function
305
- - `options.threshold`: Performance threshold in milliseconds
306
- - `options.includeMemory`: Whether to include memory usage tracking
307
- - `options.silent`: Whether to suppress logging for this tracking
346
+ // Balanced mode - moderate detail with reasonable overhead
347
+ const balancedTracker = createTracePerf({
348
+ trackingMode: TrackingMode.BALANCED
349
+ });
308
350
 
309
- ### Configuration
351
+ // Detailed mode - maximum information
352
+ const detailedTracker = createTracePerf({
353
+ trackingMode: TrackingMode.DETAILED
354
+ });
355
+ ```
310
356
 
311
- - `setMode(mode)`: Set the operational mode ('dev', 'staging', 'prod')
312
- - `getMode()`: Get the current operational mode
357
+ ### Using Thresholds to Filter Results
313
358
 
314
- ## License
359
+ ```javascript
360
+ const { createTracePerf } = require('traceperf');
361
+ const tracker = createTracePerf();
315
362
 
316
- MIT
363
+ // Only log functions that take more than 50ms
364
+ tracker.track(slowFunction, { threshold: 50 });
317
365
 
366
+ // Different thresholds for different functions
367
+ tracker.track(criticalFunction, { threshold: 10 }); // Low threshold for critical paths
368
+ tracker.track(backgroundTask, { threshold: 200 }); // Higher threshold for background tasks
369
+ ```