8def run(cmd, check=True):
18 out =
run([
"ccache",
"--print-stats"])
24 m =
re.match(
r"^local_storage_hit\s+(\d+)$", line)
28 m =
re.match(
r"^local_storage_miss\s+(\d+)$", line)
37 with open(output_path,
"a", encoding=
"utf-8")
as f:
41 on_default_branch =
os.environ[
"ON_DEFAULT_BRANCH"] ==
"true"
47 target_rate = 95
if on_default_branch
else 80
51 print(
"::group::ccache_stats")
58 hit_pct =
int((hits / total) * 100)
if total > 0
else 100
60 print(f
"hits: {hits}, misses: {misses}, hit_pct: {hit_pct}, target rate: {target_rate}")
65 if hit_pct >= target_rate:
66 print(f
"hit rate {hit_pct} is above target of {target_rate}, skip creating new cache entry")
69 print(f
"only {misses} misses, skip creating new cache entry")
72 print(f
"hit rate {hit_pct} is below target of {target_rate}, create new cache entry")
85 print(
"::group::ccache_shrink")
86 print(
run([
"ccache",
"--evict-older-than", f
"{45*60}s"]))
99 print(
run([
"killall",
"ccache"], check=
False))
103if __name__ ==
"__main__":
void print(const void *obj)
append_github_output(key, value)
Datum lower(PG_FUNCTION_ARGS)