ci_benchmark_calibration.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/python3
  2. import json
  3. from platform import platform
  4. import sys
  5. import os
  6. import fcntl
  7. benchmark_result_file_path = sys.argv[1]
  8. with open(benchmark_result_file_path, 'r', encoding='utf8') as json_in:
  9. json_data = dict(json.load(json_in))
  10. benchmarks_data = list(json_data['benchmarks'])
  11. c_base_real_time = benchmarks_data[-1]['cpu_time']
  12. c_base_cali_time = 0.005
  13. cali_ratio = c_base_cali_time/c_base_real_time
  14. platform_cali_ratio = 1
  15. if abs(cali_ratio - 2.005326432941315) < 0.01:
  16. platform_cali_ratio = 1.1549
  17. print('c_base_real_time:', c_base_real_time)
  18. print('c_base_cali_time:', c_base_cali_time)
  19. print('cali_ratio:', cali_ratio)
  20. for i in range(len(benchmarks_data)):
  21. benchmarks_data[i]['cpu_time'] *= cali_ratio
  22. benchmarks_data[i]['real_time'] *= cali_ratio
  23. benchmarks_data[i]['family_index'] += 1
  24. # new a banchmark
  25. benchmarks_data.insert(0, benchmarks_data[0].copy())
  26. performance_point_name = 'Performance Points'
  27. performance_point_res = benchmarks_data[-1]['cpu_time'] / \
  28. benchmarks_data[-2]['cpu_time'] * 100 * 100000 * platform_cali_ratio
  29. benchmarks_data[0]['name'] = performance_point_name
  30. benchmarks_data[0]['run_name'] = performance_point_name
  31. benchmarks_data[0]['family_index'] = 0
  32. benchmarks_data[0]['repetitions'] = 1
  33. benchmarks_data[0]['iterations'] = 1
  34. benchmarks_data[0]['real_time'] = performance_point_res
  35. benchmarks_data[0]['cpu_time'] = performance_point_res
  36. benchmarks_data[0]['time_unit'] = 'Point'
  37. print('---------------------------------------------')
  38. print('Perfomance point:', int(performance_point_res), '\n')
  39. # update json_data
  40. json_data['benchmarks'] = benchmarks_data
  41. # save json
  42. with open(benchmark_result_file_path, 'w') as benchmark_reqult_file:
  43. json.dump(json_data, benchmark_reqult_file)
  44. lock_file_path = 'performance_data.lock'
  45. # save performance_data
  46. with open('performance_data.json', 'r') as perf_json_file:
  47. # lock
  48. fcntl.flock(perf_json_file.fileno(), fcntl.LOCK_EX)
  49. perf_json_data: list = json.load(perf_json_file)
  50. with open('performance_data.json', 'w') as perf_json_file:
  51. perf_json_data.append(performance_point_res)
  52. json.dump(perf_json_data, perf_json_file)