-
Notifications
You must be signed in to change notification settings - Fork 603
Add performance metrics to Autobahn test parser #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,16 +34,26 @@ function parseResults() { | |
| failedTests: [], | ||
| nonStrictTests: [], | ||
| unimplementedTests: [], | ||
| informationalTests: [] | ||
| informationalTests: [], | ||
| performance: { | ||
| totalDuration: 0, | ||
| testCount: 0, | ||
| byCategory: { | ||
| 'limits': { tests: [], totalDuration: 0, description: '9.x - Limits/Performance' }, | ||
| 'largeMessages': { tests: [], totalDuration: 0, description: '10.x - Large Messages' }, | ||
| 'fragmentation': { tests: [], totalDuration: 0, description: '12.x - WebSocket Fragmentation' }, | ||
| 'other': { tests: [], totalDuration: 0, description: 'Other Tests' } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Parse each test case | ||
| for (const [testCase, result] of Object.entries(testResults)) { | ||
| summary.total++; | ||
|
|
||
| const behavior = result.behavior; | ||
| const behaviorClose = result.behaviorClose; | ||
|
|
||
| if (behavior === 'OK' && behaviorClose === 'OK') { | ||
| summary.ok++; | ||
| } else if (behavior === 'UNIMPLEMENTED') { | ||
|
|
@@ -81,6 +91,31 @@ function parseResults() { | |
| remoteCloseCode: result.remoteCloseCode | ||
| }); | ||
| } | ||
|
|
||
| // Track performance metrics | ||
| if (result.duration !== undefined) { | ||
| summary.performance.totalDuration += result.duration; | ||
| summary.performance.testCount++; | ||
|
|
||
| // Categorize performance tests | ||
| const majorCategory = testCase.split('.')[0]; | ||
| let category = 'other'; | ||
|
|
||
| if (majorCategory === '9') { | ||
| category = 'limits'; | ||
| } else if (majorCategory === '10') { | ||
| category = 'largeMessages'; | ||
| } else if (majorCategory === '12') { | ||
| category = 'fragmentation'; | ||
| } | ||
|
|
||
| summary.performance.byCategory[category].tests.push({ | ||
| case: testCase, | ||
|
||
| duration: result.duration, | ||
| description: result.description | ||
| }); | ||
| summary.performance.byCategory[category].totalDuration += result.duration; | ||
| } | ||
| } | ||
|
|
||
| // Print summary | ||
|
|
@@ -144,7 +179,48 @@ function parseResults() { | |
| } | ||
| } | ||
|
|
||
| console.log('\n'); | ||
| // Print performance summary | ||
| if (summary.performance.testCount > 0) { | ||
| console.log('=== PERFORMANCE METRICS ==='); | ||
| console.log(` Total test duration: ${summary.performance.totalDuration.toLocaleString()}ms`); | ||
| console.log(` Tests with timing data: ${summary.performance.testCount}`); | ||
| console.log(` Average duration: ${(summary.performance.totalDuration / summary.performance.testCount).toFixed(2)}ms\n`); | ||
|
|
||
| // Print category breakdown for performance-focused tests | ||
| const perfCategories = ['limits', 'largeMessages', 'fragmentation']; | ||
|
||
| let hasPerfData = false; | ||
|
|
||
| for (const categoryKey of perfCategories) { | ||
| const category = summary.performance.byCategory[categoryKey]; | ||
| if (category.tests.length > 0) { | ||
| hasPerfData = true; | ||
| const avgDuration = (category.totalDuration / category.tests.length).toFixed(2); | ||
| console.log(` ${category.description}:`); | ||
| console.log(` Tests: ${category.tests.length}`); | ||
| console.log(` Total duration: ${category.totalDuration.toLocaleString()}ms`); | ||
| console.log(` Average duration: ${avgDuration}ms`); | ||
|
|
||
| // Show top 5 slowest tests in this category | ||
| const slowestTests = category.tests | ||
| .sort((a, b) => b.duration - a.duration) | ||
| .slice(0, 5); | ||
|
||
|
|
||
| if (slowestTests.length > 0) { | ||
| console.log(' Slowest tests:'); | ||
| slowestTests.forEach(test => { | ||
| console.log(` ${test.case}: ${test.duration}ms`); | ||
| }); | ||
| } | ||
| console.log(''); | ||
| } | ||
| } | ||
|
|
||
| if (!hasPerfData) { | ||
| console.log(' No performance-focused tests (9.x, 10.x, 12.x) executed.\n'); | ||
| } | ||
| } | ||
|
|
||
| console.log(''); | ||
|
|
||
| // Exit with error code if there are actual failures | ||
| if (summary.failed > 0) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if/else ifchain works, but using a map object would be more concise and easier to maintain if more categories are added in the future. For optimal performance, this map could be defined once outside the loop.