33
44//! Generic benchmark runner infrastructure to reduce boilerplate across engine-specific benchmarks.
55
6+ use std:: env;
7+ use std:: fmt;
68use std:: fs:: File ;
79use std:: future:: Future ;
810use std:: io:: Write ;
@@ -12,7 +14,11 @@ use std::time::Duration;
1214use std:: time:: Instant ;
1315
1416use indicatif:: ProgressBar ;
17+ use vortex:: array:: debug:: arrow_path_counters;
18+ use vortex:: array:: debug:: reset_arrow_path_counters;
1519use vortex:: error:: vortex_panic;
20+ use vortex:: scan:: debug:: counters as scan_debug_counters;
21+ use vortex:: scan:: debug:: reset_counters as reset_scan_debug_counters;
1622
1723use crate :: Benchmark ;
1824use crate :: BenchmarkDataset ;
@@ -45,6 +51,47 @@ use crate::measurements::QueryMeasurement;
4551use crate :: memory:: BenchmarkMemoryTracker ;
4652use crate :: url_scheme_to_storage;
4753
54+ #[ derive( Debug , Clone , Copy , Default ) ]
55+ struct DebugCounterSnapshot {
56+ list_to_list : u64 ,
57+ list_view_zctl : u64 ,
58+ execute_list_view : u64 ,
59+ legacy_stream_fallbacks : u64 ,
60+ }
61+
62+ impl fmt:: Display for DebugCounterSnapshot {
63+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
64+ write ! (
65+ f,
66+ "list_to_list={}, list_view_zctl={}, execute_list_view={}, legacy_stream_fallbacks={}" ,
67+ self . list_to_list,
68+ self . list_view_zctl,
69+ self . execute_list_view,
70+ self . legacy_stream_fallbacks
71+ )
72+ }
73+ }
74+
75+ fn debug_counters_enabled ( ) -> bool {
76+ env:: var_os ( "VORTEX_BENCH_DEBUG_COUNTERS" ) . is_some ( )
77+ }
78+
79+ fn reset_debug_counters ( ) {
80+ reset_arrow_path_counters ( ) ;
81+ reset_scan_debug_counters ( ) ;
82+ }
83+
84+ fn snapshot_debug_counters ( ) -> DebugCounterSnapshot {
85+ let arrow = arrow_path_counters ( ) ;
86+ let scan = scan_debug_counters ( ) ;
87+ DebugCounterSnapshot {
88+ list_to_list : arrow. list_to_list ,
89+ list_view_zctl : arrow. list_view_zctl ,
90+ execute_list_view : arrow. execute_list_view ,
91+ legacy_stream_fallbacks : scan. legacy_stream_fallbacks ,
92+ }
93+ }
94+
4895/// Results from a benchmark run.
4996pub struct BenchmarkResults {
5097 pub query_measurements : Vec < QueryMeasurement > ,
@@ -130,6 +177,9 @@ impl SqlBenchmarkRunner {
130177 let mut row_count = None ;
131178
132179 for _ in 0 ..iterations {
180+ if debug_counters_enabled ( ) {
181+ reset_debug_counters ( ) ;
182+ }
133183 let start = Instant :: now ( ) ;
134184 let ( timing, result) = f ( ) ;
135185 let elapsed = timing. unwrap_or_else ( || start. elapsed ( ) ) ;
@@ -138,6 +188,15 @@ impl SqlBenchmarkRunner {
138188 if row_count. is_none ( ) {
139189 row_count = Some ( result. row_count ( ) ) ;
140190 }
191+
192+ if debug_counters_enabled ( ) {
193+ tracing:: info!(
194+ query_idx,
195+ %format,
196+ counters = %snapshot_debug_counters( ) ,
197+ "debug counters"
198+ ) ;
199+ }
141200 }
142201
143202 let row_count = row_count. expect ( "iterations must be > 0" ) ;
@@ -363,6 +422,9 @@ impl SqlBenchmarkRunner {
363422 tracing:: debug!( %format, query_idx, "Running query" ) ;
364423
365424 for _ in 0 ..iterations {
425+ if debug_counters_enabled ( ) {
426+ reset_debug_counters ( ) ;
427+ }
366428 let start = Instant :: now ( ) ;
367429 let ( timing, result) = execute ( query_idx, & ctx, query. as_str ( ) )
368430 . await
@@ -375,6 +437,15 @@ impl SqlBenchmarkRunner {
375437 if row_count. is_none ( ) {
376438 row_count = Some ( result. row_count ( ) ) ;
377439 }
440+
441+ if debug_counters_enabled ( ) {
442+ tracing:: info!(
443+ query_idx,
444+ %format,
445+ counters = %snapshot_debug_counters( ) ,
446+ "debug counters"
447+ ) ;
448+ }
378449 }
379450
380451 let row_count = row_count. expect ( "iterations must be > 0" ) ;
0 commit comments