Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/scripts/build_tests/test_ccache.py
Views: 1862
#!/usr/bin/env python31# test ccache efficiency building two similar boards2# AP_FLAKE8_CLEAN34import subprocess5import re6import argparse7import sys8import os910parser = argparse.ArgumentParser(description='test ccache performance')11parser.add_argument('--boards', default='MatekF405-bdshot,MatekF405-TE-bdshot', help='boards to test')12parser.add_argument('--min-cache-pct', type=int, default=75, help='minimum acceptable ccache hit rate')13parser.add_argument('--display', action='store_true', help='parse and show ccache stats')1415args = parser.parse_args()161718def ccache_stats():19'''return hits/misses from ccache -s'''20hits = 021miss = 022stats = str(subprocess.Popen(["ccache", "-s"], stdout=subprocess.PIPE).communicate()[0], encoding='ascii')23for line in stats.split('\n'):24m = re.match(r"cache.hit\D*(\d+)$", line)25if m is not None:26hits += int(m.group(1))2728m = re.match(r"cache.miss\D*(\d+)", line)29if m is not None:30miss += int(m.group(1))3132m = re.match(r"\s*Hits:\s*(\d+)", line)33if m is not None:34hits += int(m.group(1))3536m = re.match(r"\s*Misses:\s*(\d+)", line)37if m is not None:38miss += int(m.group(1))3940if line.startswith("Primary"):41break42return (hits, miss)434445def build_board(boardname):46subprocess.run(["./waf", "configure", "--board", boardname, '--disable-networking'])47subprocess.run(["./waf", "clean", "copter"])484950if args.display:51(hits, misses) = ccache_stats()52print("Hits=%u misses=%u" % (hits, misses))53sys.exit(0)5455boards = args.boards.split(",")56if len(boards) != 2:57print(boards)58print("Must specify exactly 2 boards (comma separated)")59sys.exit(1)6061os.environ['CCACHE_DIR'] = os.path.join(os.getcwd(), 'build', 'ccache')62subprocess.run(["ccache", "--version"])63subprocess.run(["ccache", "-C", "-z"])64build_board(boards[0])65subprocess.run(["ccache", "-z"])66build_board(boards[1])67result = subprocess.run(["ccache", "-s"], capture_output=True, text=True)68print(result.stdout)6970# Get the GitHub Actions summary file path71summary_file = os.getenv('GITHUB_STEP_SUMMARY')7273post = ccache_stats()74hit_pct = 100 * post[0] / float(post[0]+post[1])75print("ccache hit percentage: %.1f%% %s" % (hit_pct, post))76if summary_file:77# Append the output to the summary file78with open(summary_file, 'a') as f:79f.write(f"### ccache -s Output with {boards}\n")80f.write(f"```\n{result.stdout}\n```\n")81f.write(f"### ccache hit percentage (min {args.min_cache_pct})\n")82f.write("ccache hit percentage: %.1f%% %s\n" % (hit_pct, post))83if hit_pct < args.min_cache_pct:84print("ccache hits too low, need %d%%" % args.min_cache_pct)85sys.exit(1)86else:87print("ccache hits good")888990