diff --git a/xmetrics/Dockerfile b/xmetrics/Dockerfile index a47b8e6..8ad21b4 100644 --- a/xmetrics/Dockerfile +++ b/xmetrics/Dockerfile @@ -1,138 +1,150 @@ -FROM python:3.11 as metrics-base +FROM python:3.11 AS metrics-base WORKDIR /code/ -FROM metrics-base as metrics-tmg +FROM metrics-base AS metrics-tmg RUN git clone https://github.com/OnGoTeam/TMGmod.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 82db35f2db92572c98d84ef781f64f8d65d2f023 ENV SRCPATTERN="./build/src/**/*.cs" -FROM metrics-base as metrics-radn +FROM metrics-base AS metrics-radn RUN git clone https://gitea.parrrate.ru/PTV/radn-rs.git repo WORKDIR /code/repo/ -RUN git fetch && git checkout dc98e38b8fbc10e6329c86cad110ce653b94eafd +RUN git fetch && git checkout 02550c0ded5358e78cd7bb64675085ceec005ea5 -FROM metrics-base as metrics-meta +FROM metrics-base AS metrics-meta RUN git clone https://gitea.parrrate.ru/PTV/radn-dev.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 33d8daee79e53fc0eded5f7d56486f68aac4d26d ENV SRCPATTERN="./*metrics/**/*" -FROM metrics-base as metrics-mdbook +FROM metrics-base AS metrics-mdbook RUN git clone https://github.com/rust-lang/mdBook.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 904aa530b5f59387f19feb0dbe0e959de3f247d2 -FROM metrics-base as metrics-rustup +FROM metrics-base AS metrics-rustup RUN git clone https://github.com/rust-lang/rustup.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 849adb7c1b8c97e4145e350a934c3a665f61798e -FROM metrics-base as metrics-cargo +FROM metrics-base AS metrics-cargo RUN git clone https://github.com/rust-lang/cargo.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 5b377cece0e0dd0af686cf53ce4637d5d85c2a10 -FROM metrics-base as metrics-rust +FROM metrics-base AS metrics-rust RUN git clone https://github.com/rust-lang/rust.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 32d81eccd64513bacef9dfa1574543ada6b45d85 -FROM metrics-base as metrics-ocen +FROM metrics-base AS metrics-ocen RUN git clone https://github.com/ocen-lang/ocen.git repo WORKDIR /code/repo/ RUN git fetch && git checkout 0b1a63d0e141fc3032f10c70b5cae117429e2dcb ENV SRCPATTERN="./**/*.[oa][ec]" -FROM metrics-base as metrics-aecor +FROM metrics-base AS metrics-aecor RUN git clone https://github.com/mustafaquraish/aecor.git repo WORKDIR /code/repo/ RUN git fetch && git checkout f81543a34ee363dcc00e8632fd7cfcd4a3478b23 ENV SRCDIR="." ENV SRCPATTERN="./**/*.[ach]*" -FROM metrics-radn as metrics-repo +FROM metrics-base AS metrics-ruchei +RUN git clone https://github.com/parrrate/ruchei.git repo +WORKDIR /code/repo/ +RUN git fetch && git checkout 8ee80921f7ca7b6dd197870278df4ad4260f266a +ENV SRCPATTERN="./**/*.rs ./**/*.toml" -FROM metrics-repo as metrics-commits +FROM metrics-base AS metrics-temp +COPY temp repo +WORKDIR /code/repo/ +ENV SRCPATTERN="./**/*.rs ./**/*.sql" + +FROM metrics-temp AS metrics-repo + +FROM metrics-repo AS metrics-commits COPY common.py /code/common.py COPY commits.py /code/commits.py RUN python3 /code/commits.py -FROM metrics-repo as metrics +FROM metrics-repo AS metrics COPY common.py /code/common.py COPY metrics.py /code/metrics.py COPY --from=metrics-commits /code/commits.dat commits.dat RUN python3 /code/metrics.py -FROM metrics-base as metrics-process +FROM metrics-base AS metrics-process RUN python3 -m pip install numpy -FROM metrics-process as metrics-data +FROM metrics-process AS metrics-data COPY --from=metrics /code/metrics.dat metrics.dat -FROM metrics-process as metrics-plot +FROM metrics-process AS metrics-plot RUN python3 -m pip install matplotlib -FROM metrics-data as metrics-entries +FROM metrics-data AS metrics-entries COPY entries.py entries.py RUN python3 entries.py -FROM metrics-data as metrics-y +FROM metrics-data AS metrics-y COPY cors.py cors.py RUN python3 cors.py -FROM metrics-plot as metrics-c +FROM metrics-plot AS metrics-c COPY --from=metrics-y /code/Y.dat Y.dat COPY k2c.py k2c.py -FROM metrics-c as metrics-c-linear +FROM metrics-c AS metrics-c-linear COPY c_linear.py c_linear.py RUN python3 c_linear.py -FROM metrics-c as metrics-c-proportional +FROM metrics-c AS metrics-c-proportional COPY c_proportional.py c_proportional.py RUN python3 c_proportional.py -FROM metrics-process as metrics-x +FROM metrics-process AS metrics-x COPY --from=metrics-y /code/Y.dat Y.dat -FROM metrics-x as metrics-x-linear +FROM metrics-x AS metrics-x-linear COPY x_linear.py x_linear.py RUN python3 x_linear.py -FROM metrics-x as metrics-x-proportional +FROM metrics-x AS metrics-x-proportional COPY x_proportional.py x_proportional.py RUN python3 x_proportional.py -FROM metrics-plot as metrics-render +FROM metrics-plot AS metrics-render RUN mkdir /code/metrics/ -FROM metrics-render as metrics-render-ploc +FROM metrics-render AS metrics-render-ploc COPY --from=metrics-entries /code/entries.dat entries.dat COPY render_ploc.py render_ploc.py RUN python3 render_ploc.py -FROM metrics-render as metrics-render-hist +FROM metrics-render AS metrics-render-hist COPY --from=metrics-y /code/Y.dat Y.dat COPY render_hist.py render_hist.py -FROM metrics-render-hist as metrics-render-01x +FROM metrics-render-hist AS metrics-render-01x COPY --from=metrics-x-linear /code/X.dat X.dat COPY --from=metrics-c-linear /code/C.dat C.dat RUN python3 render_hist.py -FROM metrics-render-hist as metrics-render-02y +FROM metrics-render-hist AS metrics-render-02y COPY --from=metrics-x-linear /code/X.dat X.dat COPY --from=metrics-c-proportional /code/C.dat C.dat RUN python3 render_hist.py -FROM metrics-render-hist as metrics-render-03xy +FROM metrics-render-hist AS metrics-render-03xy +ENV SAME_UNITS=true COPY --from=metrics-x-proportional /code/X.dat X.dat COPY --from=metrics-c-proportional /code/C.dat C.dat RUN python3 render_hist.py -FROM metrics-base -COPY --from=metrics-render-ploc /code/metrics/out.png /code/metrics/metrics.png -COPY --from=metrics-render-01x /code/metrics/out.png /code/metrics/metrics-01x.png -COPY --from=metrics-render-02y /code/metrics/out.png /code/metrics/metrics-02y.png -COPY --from=metrics-render-03xy /code/metrics/out.png /code/metrics/metrics-03xy.png +FROM scratch +COPY --from=metrics-render-ploc /code/metrics/out.png /metrics.png +COPY --from=metrics-render-01x /code/metrics/out.png /metrics-01x.png +COPY --from=metrics-render-02y /code/metrics/out.png /metrics-02y.png +COPY --from=metrics-render-03xy /code/metrics/out.png /metrics-03xy.png diff --git a/xmetrics/commits.py b/xmetrics/commits.py index d5dbea8..2d270e8 100644 --- a/xmetrics/commits.py +++ b/xmetrics/commits.py @@ -1,5 +1,4 @@ import pickle -from random import randrange from subprocess import check_output from common import set_ diff --git a/xmetrics/common.py b/xmetrics/common.py index 4ccbfd7..8c37396 100644 --- a/xmetrics/common.py +++ b/xmetrics/common.py @@ -12,11 +12,17 @@ def _counter(commit: str, unique: bool, to_counter: bool) -> Counter | set: all_lines = set() else: all_lines = Counter() - for path in Path.cwd().rglob(os.getenv("SRCPATTERN", "./src/**/*.rs")): - lines = path.read_bytes().splitlines() - lines = (line.strip() for line in lines) - lines = (line for line in lines if line) - all_lines.update(lines) + seen = set() + for pattern in os.getenv("SRCPATTERN", "./src/**/*.rs").split(): + for path in Path.cwd().rglob(pattern): + if path in seen: + continue + else: + seen.add(path) + lines = path.read_bytes().splitlines() + lines = (line.strip() for line in lines) + lines = (line for line in lines if line) + all_lines.update(lines) if isinstance(all_lines, set) and to_counter: return Counter(all_lines) else: diff --git a/xmetrics/docker-compose.yml b/xmetrics/docker-compose.yml deleted file mode 100644 index 6d3cb9c..0000000 --- a/xmetrics/docker-compose.yml +++ /dev/null @@ -1,6 +0,0 @@ -services: - metrics: - container_name: temp-metrics - build: . - tty: true - stop_signal: SIGKILL diff --git a/xmetrics/metrics.py b/xmetrics/metrics.py index 622a5db..f687e03 100644 --- a/xmetrics/metrics.py +++ b/xmetrics/metrics.py @@ -5,15 +5,15 @@ from common import counter with open("commits.dat", "rb") as file: commits: list[str] = pickle.load(file) -entries = [] +entries = [(0, 0, 0, 0)] last_ctr = Counter() last_cor = [] cors = [] C = min(len(commits), 720) -for i, commit in enumerate(reversed(commits)): +for i, commit in enumerate(reversed(commits), 1): print(f"P={i / len(commits):6f}", flush=True) print("running", commit, flush=True) - current_ctr = counter(commit, True) + current_ctr = counter(commit, False) added = current_ctr - last_ctr deleted = last_ctr - current_ctr entries.append((i, current_ctr.total(), added.total(), deleted.total())) diff --git a/xmetrics/render.sh b/xmetrics/render.sh index 56e9372..5bcdd97 100755 --- a/xmetrics/render.sh +++ b/xmetrics/render.sh @@ -1,4 +1,2 @@ clear -docker compose up -d --build metrics -docker cp temp-metrics:/code/metrics/ . -docker compose down +docker build . --output ./metrics diff --git a/xmetrics/render_hist.py b/xmetrics/render_hist.py index 39e2466..09fce08 100644 --- a/xmetrics/render_hist.py +++ b/xmetrics/render_hist.py @@ -1,3 +1,4 @@ +import os import pickle import matplotlib.pyplot as plt @@ -15,6 +16,12 @@ with open("X.dat", "rb") as file: X = pickle.load(file) with open("C.dat", "rb") as file: C = pickle.load(file) +if os.getenv("SAME_UNITS"): + color = (0.5, 0.5, 0.5, 0.5) + plt.axline((0, 0), slope=1.0, linestyle="--", color=color, zorder=-10) + plt.axline((0, 0), slope=0.75, linestyle="--", color=color, zorder=-10) + plt.axline((0, 0), slope=0.5, linestyle="--", color=color, zorder=-10) + plt.axline((0, 0), slope=0.25, linestyle="--", color=color, zorder=-10) plt.stackplot( X, Y, @@ -22,4 +29,4 @@ plt.stackplot( aa=False, linewidth=0.0, ) -plt.savefig(f"/code/metrics/out.png") +plt.savefig("/code/metrics/out.png")