Test ring buffer performance characteristics
(self)
| 244 | assert "n_threads" in repr_str, "String representation should contain n_threads" |
| 245 | |
| 246 | def test_ring_buffer_performance(self): |
| 247 | """Test ring buffer performance characteristics""" |
| 248 | ring_name = "/test/ring_buffer_perf" |
| 249 | test_entries = 100 |
| 250 | |
| 251 | # Step 1: Create ring buffer |
| 252 | cli_cmd = f"test stats ring-buffer-gen {ring_name} {test_entries} {INTERVAL_USEC} {RING_SIZE}" |
| 253 | result = self.vapi.cli(cli_cmd) |
| 254 | assert "Generated" in result, f"CLI failed: {result}" |
| 255 | |
| 256 | # Step 2: Get ring buffer |
| 257 | ring_buffer = self.statistics.get_ring_buffer(f"{ring_name}") |
| 258 | |
| 259 | # Step 3: Test individual consume performance |
| 260 | start_time = time.time() |
| 261 | individual_count = 0 |
| 262 | for _ in range(100): # 100 operations |
| 263 | data = ring_buffer.consume_data(thread_index=0, max_entries=1) |
| 264 | individual_count += len(data) |
| 265 | individual_time = time.time() - start_time |
| 266 | |
| 267 | # Step 4: Reset and test batch consume performance |
| 268 | ring_buffer.local_tails[0] = 0 |
| 269 | ring_buffer.last_sequences[0] = None |
| 270 | |
| 271 | start_time = time.time() |
| 272 | batch_count = 0 |
| 273 | for _ in range(10): # 10 batch operations |
| 274 | data = ring_buffer.consume_data_batch(thread_index=0, max_entries=10) |
| 275 | batch_count += len(data) |
| 276 | batch_time = time.time() - start_time |
| 277 | |
| 278 | # Step 5: Calculate performance metrics |
| 279 | individual_throughput = 100 / individual_time if individual_time > 0 else 0 |
| 280 | batch_throughput = 100 / batch_time if batch_time > 0 else 0 |
| 281 | |
| 282 | print(f"Individual consume: {individual_throughput:.0f} ops/sec") |
| 283 | print(f"Batch consume: {batch_throughput:.0f} ops/sec") |
| 284 | |
| 285 | # Step 6: Validate performance (basic sanity checks) |
| 286 | assert individual_time > 0, "Individual operations should take some time" |
| 287 | assert batch_time > 0, "Batch operations should take some time" |
| 288 | assert individual_count >= 0, "Individual count should be non-negative" |
| 289 | assert batch_count >= 0, "Batch count should be non-negative" |
| 290 | |
| 291 | def test_ring_buffer_multiple_threads(self): |
| 292 | """Test ring buffer access across multiple threads""" |
nothing calls this directly
no test coverage detected