@contrail/util 1.1.15-alpha-4 → 1.1.15-alpha-5

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const performance_util_1 = require("./performance-util");
4
+ function demonstrateStartEndSpan() {
5
+ console.log('--- Demonstrating startSpan/endSpan functionality ---\n');
6
+ (0, performance_util_1.clearDefaultTimingProfile)();
7
+ console.log('Example 1: Simple span');
8
+ (0, performance_util_1.startSpan)('Data Processing');
9
+ const start1 = performance.now();
10
+ while (performance.now() < start1 + 100) {
11
+ }
12
+ (0, performance_util_1.endSpan)('Data Processing');
13
+ (0, performance_util_1.displayTimingTree)();
14
+ console.log('\nExample 2: Nested spans');
15
+ (0, performance_util_1.clearDefaultTimingProfile)();
16
+ (0, performance_util_1.startSpan)('Complete Task');
17
+ (0, performance_util_1.startSpan)('Initialization');
18
+ const start2 = performance.now();
19
+ while (performance.now() < start2 + 50) { }
20
+ (0, performance_util_1.endSpan)('Initialization');
21
+ (0, performance_util_1.startSpan)('Main Processing');
22
+ (0, performance_util_1.startSpan)('Sub-task 1');
23
+ const start3 = performance.now();
24
+ while (performance.now() < start3 + 30) { }
25
+ (0, performance_util_1.endSpan)('Sub-task 1');
26
+ (0, performance_util_1.startSpan)('Sub-task 2');
27
+ const start4 = performance.now();
28
+ while (performance.now() < start4 + 40) { }
29
+ (0, performance_util_1.endSpan)('Sub-task 2');
30
+ (0, performance_util_1.endSpan)('Main Processing');
31
+ (0, performance_util_1.startSpan)('Cleanup');
32
+ const start5 = performance.now();
33
+ while (performance.now() < start5 + 20) { }
34
+ (0, performance_util_1.endSpan)('Cleanup');
35
+ (0, performance_util_1.endSpan)('Complete Task');
36
+ (0, performance_util_1.displayTimingTree)();
37
+ console.log('\nExample 3: Multiple sequential spans');
38
+ (0, performance_util_1.clearDefaultTimingProfile)();
39
+ (0, performance_util_1.startSpan)('Phase 1');
40
+ const start6 = performance.now();
41
+ while (performance.now() < start6 + 60) { }
42
+ (0, performance_util_1.endSpan)('Phase 1');
43
+ (0, performance_util_1.startSpan)('Phase 2');
44
+ const start7 = performance.now();
45
+ while (performance.now() < start7 + 80) { }
46
+ (0, performance_util_1.endSpan)('Phase 2');
47
+ (0, performance_util_1.startSpan)('Phase 3');
48
+ const start8 = performance.now();
49
+ while (performance.now() < start8 + 40) { }
50
+ (0, performance_util_1.endSpan)('Phase 3');
51
+ (0, performance_util_1.displayTimingTree)();
52
+ }
53
+ function demonstrateWarningBehavior() {
54
+ console.log('\n--- Demonstrating Warning Behavior ---\n');
55
+ (0, performance_util_1.clearDefaultTimingProfile)();
56
+ console.log('Example 4: Warning behavior');
57
+ (0, performance_util_1.startSpan)('Test Span');
58
+ console.log('Started "Test Span"');
59
+ (0, performance_util_1.startSpan)('Test Span');
60
+ console.log('Attempted to start "Test Span" again (should see warning above)');
61
+ (0, performance_util_1.endSpan)('Test Span');
62
+ console.log('Ended "Test Span"');
63
+ (0, performance_util_1.endSpan)('Non-existent Span');
64
+ console.log('Attempted to end "Non-existent Span" (should see warning above)');
65
+ (0, performance_util_1.displayTimingTree)();
66
+ }
67
+ demonstrateStartEndSpan();
68
+ demonstrateWarningBehavior();
@@ -99,7 +99,8 @@ function displayTimingTree(nodes = DEFAULT_TIMING_PROFILE.timingSpans, depth = 0
99
99
  }
100
100
  function startSpan(spanName) {
101
101
  if (DEFAULT_TIMING_PROFILE.activeSpans.has(spanName)) {
102
- throw new Error(`Span "${spanName}" is already active. Please end it before starting a new one with the same name.`);
102
+ console.warn(`Span "${spanName}" is already active. Please end it before starting a new one with the same name.`);
103
+ return;
103
104
  }
104
105
  const startTime = performance.now();
105
106
  const timingNode = { label: spanName, durationMs: 0, children: [] };
@@ -119,7 +120,8 @@ function startSpan(spanName) {
119
120
  function endSpan(spanName) {
120
121
  const activeSpan = DEFAULT_TIMING_PROFILE.activeSpans.get(spanName);
121
122
  if (!activeSpan) {
122
- throw new Error(`No active span found with name "${spanName}". Make sure to call startSpan() first.`);
123
+ console.warn(`No active span found with name "${spanName}". Make sure to call startSpan() first.`);
124
+ return;
123
125
  }
124
126
  const endTime = performance.now();
125
127
  activeSpan.node.durationMs = endTime - activeSpan.startTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.1.15-alpha-4",
3
+ "version": "1.1.15-alpha-5",
4
4
  "description": "General JavaScript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",