Files
ccc/test.py
2026-02-10 23:22:08 +01:00

99 lines
2.8 KiB
Python

import os
import subprocess
import time
def get_source_files(root_dir):
source_files = []
total_size = 0
for root, _, files in os.walk(root_dir):
for file in files:
if file.endswith(('.c', '.h')) and len(source_files) < 30000:
path = os.path.join(root, file)
source_files.append(path)
total_size += os.path.getsize(path)
return source_files, total_size
def monitor_process(proc):
max_rss = 0
while proc.poll() is None:
try:
with open(f"/proc/{proc.pid}/status") as f:
for line in f:
if line.startswith("VmHWM:"):
rss = int(line.split()[1]) # kB
if rss > max_rss:
max_rss = rss
break
except FileNotFoundError:
break
time.sleep(0.05)
return max_rss
def main():
target_dir = "linux"
if not os.path.exists(target_dir):
print(f"Erreur: Le dossier {target_dir} n'existe pas.")
return
print(f"--- Analyse de {target_dir} ---")
files, total_raw_size = get_source_files(target_dir)
raw_mo = total_raw_size / (1024 * 1024)
print(f"Fichiers trouvés : {len(files)}")
print(f"Taille totale brute : {raw_mo:.2f} Mo")
# 1. TAR
print("\n--- Lancement de TAR -cJf (XZ) ---")
start_tar = time.time()
tar_cmd = ["tar", "-cJf", "linux_sources.tar.xz", "--files-from=-"]
process_tar = subprocess.Popen(tar_cmd, stdin=subprocess.PIPE)
process_tar.stdin.write("\n".join(files).encode())
process_tar.stdin.close()
peak_tar = monitor_process(process_tar)
process_tar.wait()
end_tar = time.time()
# 2. CCC
print("\n--- Lancement de CCC (Output temps réel) ---")
print("-" * 40)
start_ccc = time.time()
try:
process_ccc = subprocess.Popen(["./ccc"] + files)
peak_ccc = monitor_process(process_ccc)
process_ccc.wait()
except OSError as e:
print(f"\nErreur système : {e}")
return
end_ccc = time.time()
print("-" * 40)
# Résultats
print("\n" + "=" * 40)
print(f" RÉSULTATS (Source: {raw_mo:.2f} Mo)")
print("=" * 40)
for name, filename in [("TAR.XZ", "linux_sources.tar.xz"), ("CCC", "test.ccc")]:
if os.path.exists(filename):
size_mo = os.path.getsize(filename) / (1024 * 1024)
ratio = (size_mo / raw_mo) * 100
print(f"{name:10} : {size_mo:8.2f} Mo ({ratio:5.2f}%)")
else:
print(f"{name:10} : Non généré")
print(f"\nTemps TAR : {end_tar - start_tar:.2f}s")
print(f"Temps CCC : {end_ccc - start_ccc:.2f}s")
print(f"\nPic RAM TAR : {peak_tar / 1024:.2f} Mo")
print(f"Pic RAM CCC : {peak_ccc / 1024:.2f} Mo")
if __name__ == "__main__":
main()