33import os
44import pathlib
55import shutil
6- import stat
76import subprocess
87import sys
98import tempfile
2221 redis_benchmark_from_stdout_csv_to_json ,
2322 redis_benchmark_ensure_min_version_local ,
2423)
24+ from redisbench_admin .run .ycsb .ycsb import post_process_ycsb_results
2525from redisbench_admin .utils .local import (
2626 spin_up_local_redis ,
2727 get_local_run_full_filename ,
@@ -230,6 +230,19 @@ def post_process_benchmark_results(
230230 )
231231 with open (local_benchmark_output_filename , "w" ) as json_file :
232232 json .dump (results_dict , json_file , indent = True )
233+ if benchmark_tool == "ycsb" :
234+ logging .info (
235+ "Converting ycsb output to json. Storing it in: {}" .format (
236+ local_benchmark_output_filename
237+ )
238+ )
239+ results_dict = post_process_ycsb_results (
240+ stdout .decode ("ascii" ),
241+ start_time_ms ,
242+ start_time_str ,
243+ )
244+ with open (local_benchmark_output_filename , "w" ) as json_file :
245+ json .dump (results_dict , json_file , indent = True )
233246
234247
235248def check_benchmark_binaries_local_requirements (
@@ -242,6 +255,7 @@ def check_benchmark_binaries_local_requirements(
242255 benchmark_min_tool_version_patch ,
243256 benchmark_tool ,
244257 tool_source ,
258+ tool_source_bin_path ,
245259 ) = extract_benchmark_tool_settings (benchmark_config )
246260 which_benchmark_tool = None
247261 if benchmark_tool is not None :
@@ -255,57 +269,17 @@ def check_benchmark_binaries_local_requirements(
255269 logging .info ("Checking benchmark tool {} is accessible" .format (benchmark_tool ))
256270 which_benchmark_tool = shutil .which (benchmark_tool )
257271 if which_benchmark_tool is None :
258- if tool_source is not None :
259- logging .info (
260- "Tool {} was not detected on path. Using remote source to retrieve it: {}" .format (
261- benchmark_tool , tool_source
262- )
263- )
264- if tool_source .startswith ("http" ):
265- if not os .path .isdir (binaries_localtemp_dir ):
266- os .mkdir (binaries_localtemp_dir )
267- filename = tool_source .split ("/" )[- 1 ]
268- full_path = "{}/{}" .format (binaries_localtemp_dir , filename )
269- if not os .path .exists (full_path ):
270- logging .info (
271- "Retrieving remote file from {} to {}. Using the dir {} as a cache for next time." .format (
272- tool_source , full_path , binaries_localtemp_dir
273- )
274- )
275- wget .download (tool_source , full_path )
276- logging .info (
277- "Decompressing {} into {}." .format (
278- full_path , binaries_localtemp_dir
279- )
280- )
281- if not os .path .exists (get_decompressed_filename (full_path )):
282- full_path = decompress_file (full_path , binaries_localtemp_dir )
283- else :
284- full_path = get_decompressed_filename (full_path )
285- benchmark_tool_workdir = os .path .abspath (full_path )
286- executable = stat .S_IEXEC | stat .S_IXGRP | stat .S_IXOTH
287- which_benchmark_tool = which_local (
288- benchmark_tool , executable , full_path , which_benchmark_tool
289- )
290- if which_benchmark_tool is None :
291- raise Exception (
292- "Benchmark tool {} was not acessible at {}. Aborting..." .format (
293- benchmark_tool , full_path
294- )
295- )
296- else :
297- logging .info (
298- "Reusing cached remote file (located at {} )." .format (
299- full_path
300- )
301- )
302-
303- else :
304- raise Exception (
305- "Benchmark tool {} was not acessible. Aborting..." .format (
306- benchmark_tool
307- )
308- )
272+ (
273+ benchmark_tool_workdir ,
274+ which_benchmark_tool ,
275+ ) = fetch_benchmark_tool_from_source_to_local (
276+ benchmark_tool ,
277+ benchmark_tool_workdir ,
278+ binaries_localtemp_dir ,
279+ tool_source ,
280+ tool_source_bin_path ,
281+ which_benchmark_tool ,
282+ )
309283 else :
310284 logging .info (
311285 "Tool {} was detected at {}" .format (
@@ -332,6 +306,61 @@ def check_benchmark_binaries_local_requirements(
332306 return benchmark_tool , which_benchmark_tool , benchmark_tool_workdir
333307
334308
309+ def fetch_benchmark_tool_from_source_to_local (
310+ benchmark_tool ,
311+ benchmark_tool_workdir ,
312+ binaries_localtemp_dir ,
313+ tool_source ,
314+ bin_path ,
315+ which_benchmark_tool ,
316+ ):
317+ if tool_source is not None and bin_path is not None :
318+ logging .info (
319+ "Tool {} was not detected on path. Using remote source to retrieve it: {}" .format (
320+ benchmark_tool , tool_source
321+ )
322+ )
323+ if tool_source .startswith ("http" ):
324+ if not os .path .isdir (binaries_localtemp_dir ):
325+ os .mkdir (binaries_localtemp_dir )
326+ filename = tool_source .split ("/" )[- 1 ]
327+ full_path = "{}/{}" .format (binaries_localtemp_dir , filename )
328+ if not os .path .exists (full_path ):
329+ logging .info (
330+ "Retrieving remote file from {} to {}. Using the dir {} as a cache for next time." .format (
331+ tool_source , full_path , binaries_localtemp_dir
332+ )
333+ )
334+ wget .download (tool_source , full_path )
335+ logging .info (
336+ "Decompressing {} into {}." .format (full_path , binaries_localtemp_dir )
337+ )
338+ if not os .path .exists (get_decompressed_filename (full_path )):
339+ full_path = decompress_file (full_path , binaries_localtemp_dir )
340+ else :
341+ full_path = get_decompressed_filename (full_path )
342+ benchmark_tool_workdir = os .path .abspath (full_path )
343+ which_benchmark_tool = os .path .abspath (
344+ "{}/{}" .format (benchmark_tool_workdir , bin_path )
345+ )
346+ if which_benchmark_tool is None :
347+ raise Exception (
348+ "Benchmark tool {} was not acessible at {}. Aborting..." .format (
349+ benchmark_tool , full_path
350+ )
351+ )
352+ else :
353+ logging .info (
354+ "Reusing cached remote file (located at {} )." .format (full_path )
355+ )
356+
357+ else :
358+ raise Exception (
359+ "Benchmark tool {} was not acessible. Aborting..." .format (benchmark_tool )
360+ )
361+ return benchmark_tool_workdir , which_benchmark_tool
362+
363+
335364def which_local (benchmark_tool , executable , full_path , which_benchmark_tool ):
336365 if which_benchmark_tool :
337366 return which_benchmark_tool
0 commit comments