2929import benchUtil
3030import constants
3131import ps_head
32+ from benchUtil import PERF_EXE
3233from common import getLuceneDirFromGradleProperties
3334
3435# Measure vector search recall and latency while exploring hyperparameters
5859# Set this to True to generate the disassembled code to verify the intended SIMD instructions are getting used or not
5960PERF_MODE = False
6061
61- PERF_PATH = shutil .which ("perf" )
62-
6362# e.g. to compile KnnIndexer:
6463#
6564# javac -d build -cp /l/trunk/lucene/core/build/libs/lucene-core-10.0.0-SNAPSHOT.jar:/l/trunk/lucene/join/build/libs/lucene-join-10.0.0-SNAPSHOT.jar src/main/knn/*.java src/main/WikiVectors.java src/main/perf/VectorDictionary.java
@@ -351,9 +350,9 @@ def run_knn_benchmark(checkout, values, log_path):
351350 ]
352351 )
353352
354- if PERF_MODE and PERF_PATH :
353+ if PERF_MODE and PERF_EXE :
355354 print ("Will be recording the executed instructions in perf.data file" )
356- perf_cmd = [PERF_PATH , "record" , "-e" , "instructions:u" , "-o" , f"perf{ index_run } .data" , "-g" ] + this_cmd
355+ perf_cmd = [PERF_EXE , "record" , "-e" , "instructions:u" , "-o" , f"perf{ index_run } .data" , "-g" ] + this_cmd
357356 job = subprocess .run (perf_cmd , check = False )
358357 if NOISY :
359358 print (f" cmd: { perf_cmd } " )
@@ -389,14 +388,13 @@ def run_knn_benchmark(checkout, values, log_path):
389388 re_summary = re .compile (r"^SUMMARY: (.*?)$" , re .MULTILINE )
390389 summary = None
391390 hit_exception = False
392- lines = ""
393- while True :
391+ while job .poll () is None :
394392 line = job .stdout .readline ()
395- if line == "" :
396- break
397- lines += line
393+ if not line :
394+ continue
398395 if NOISY :
399396 sys .stdout .write (line )
397+ sys .stdout .flush ()
400398 m = re_summary .match (line )
401399 if m is not None :
402400 summary = m .group (1 )
@@ -421,11 +419,11 @@ def run_knn_benchmark(checkout, values, log_path):
421419
422420 if hit_exception :
423421 raise RuntimeError ("unhandled java exception while running" )
424- if summary is None :
425- raise RuntimeError ("could not find summary line in output! " + lines )
426422 job .wait ()
427423 if job .returncode != 0 :
428424 raise RuntimeError (f"command failed with exit { job .returncode } " )
425+ if summary is None :
426+ raise RuntimeError ("could not find summary line in output! " )
429427 all_results .append ((summary , args ))
430428 if DO_PROFILING :
431429 benchUtil .profilerOutput (constants .JAVA_EXE , jfr_output , benchUtil .checkoutToPath (checkout ), 30 , (1 ,))
0 commit comments