(project, statistics_dir)
| 34 | |
| 35 | |
| 36 | def process_coverage(project, statistics_dir): |
| 37 | work_dir = os.path.join(OTUPUT_DIR, project, "work") |
| 38 | cov_so_path = get_cov_shared_lib_path(project) |
| 39 | |
| 40 | if not os.path.isdir(work_dir): |
| 41 | print(f"Directory not found: {work_dir}") |
| 42 | return 0 |
| 43 | |
| 44 | seeds = [] |
| 45 | for dir_name in os.listdir(work_dir): |
| 46 | if not dir_name.startswith("id_"): |
| 47 | continue |
| 48 | |
| 49 | seed_dir = os.path.join(work_dir, dir_name) |
| 50 | profdata_path = os.path.join(seed_dir, "default.profdata") |
| 51 | |
| 52 | if os.path.isfile(profdata_path): |
| 53 | mtime = os.path.getmtime(profdata_path) |
| 54 | seeds.append({ |
| 55 | "id": dir_name, |
| 56 | "profdata": profdata_path, |
| 57 | "time": mtime |
| 58 | }) |
| 59 | |
| 60 | if not seeds: |
| 61 | print("No default.profdata found in work directory.") |
| 62 | return 0 |
| 63 | |
| 64 | seeds.sort(key=lambda x: x["time"]) |
| 65 | |
| 66 | start_time = seeds[0]["time"] |
| 67 | times = [] |
| 68 | coverages = [] |
| 69 | |
| 70 | merged_profdata = os.path.join(statistics_dir, f"{project}_merged.profdata") |
| 71 | |
| 72 | for i, seed in enumerate(seeds): |
| 73 | relative_time = seed["time"] - start_time |
| 74 | |
| 75 | if i == 0: |
| 76 | cmd = ["llvm-profdata", "merge", "-sparse", seed["profdata"], "-o", merged_profdata] |
| 77 | else: |
| 78 | cmd = ["llvm-profdata", "merge", "-sparse", merged_profdata, seed["profdata"], "-o", merged_profdata] |
| 79 | |
| 80 | subprocess.run(cmd, capture_output=True) |
| 81 | covered_branches = get_coverage(merged_profdata, cov_so_path) |
| 82 | |
| 83 | times.append(relative_time) |
| 84 | coverages.append(covered_branches) |
| 85 | print(f"Processed {i+1}/{len(seeds)}: {seed['id']} at {relative_time:.2f}s - {covered_branches} branches") |
| 86 | |
| 87 | |
| 88 | output_json = os.path.join(statistics_dir, "coverage_growth.json") |
| 89 | with open(output_json, "w") as f: |
| 90 | json.dump({"times": times, "coverages": coverages}, f, indent=4) |
| 91 | print(f"Coverage data saved to {output_json}") |
| 92 | |
| 93 | return coverages[-1] if coverages else 0 |
no test coverage detected