-
Notifications
You must be signed in to change notification settings - Fork 0
Initial Implementation and testing #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abulgit
wants to merge
6
commits into
master
Choose a base branch
from
perf-dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e9c2b8
Implement Perfrunner initial
abulgit 0a3538e
Disable other workflows as of now
abulgit 6c3d449
Add deliberate busy loop
abulgit 293ef3b
Refactor a bit
abulgit 2481caa
Build with ldc and remove busy loop
abulgit 7c5c2f1
Puting the loop again(see if LDC2 optimizes it)
abulgit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env python3 | ||
| """Render the perfrunner results.json into a sticky PR comment. | ||
|
|
||
| also upserts a single comment identified by a hidden marker so | ||
| pushes update one comment instead of spamming. | ||
| """ | ||
|
|
||
| import json | ||
| import os | ||
| import sys | ||
| import urllib.request | ||
|
|
||
| MARKER = "<!-- dmd-perf-bot -->" | ||
|
abulgit marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def fmt_value(value, unit): | ||
| if unit == "count": | ||
| return f"{value / 1e6:,.1f} M" | ||
| if unit == "bytes": | ||
| return f"{value / (1024 * 1024):.2f} MB" | ||
| if unit == "kb": | ||
| return f"{value / 1024:.0f} MB" | ||
| return str(value) | ||
|
|
||
|
|
||
| def fmt_delta(pct): | ||
| return f"+{pct:.2f}%" if pct > 0 else f"{pct:.2f}%" | ||
|
|
||
|
|
||
| def render(results): | ||
| lines = [ | ||
| MARKER, | ||
| "### DMD perf check", | ||
| "", | ||
| "| Metric | Base | PR | delta |", | ||
| "|--------|------|----|-------|", | ||
| ] | ||
| for m in results["metrics"]: | ||
| lines.append("| {} | {} | {} | {} |".format( | ||
| m["label"], | ||
| fmt_value(m["base"], m["unit"]), | ||
| fmt_value(m["head"], m["unit"]), | ||
| fmt_delta(m["delta_pct"]), | ||
| )) | ||
| return "\n".join(lines) + "\n" | ||
|
|
||
|
|
||
| def api(method, url, token, payload=None): | ||
| data = json.dumps(payload).encode() if payload is not None else None | ||
| req = urllib.request.Request(url, data=data, method=method) | ||
| req.add_header("Authorization", f"Bearer {token}") | ||
| req.add_header("Accept", "application/vnd.github+json") | ||
| if data: | ||
| req.add_header("Content-Type", "application/json") | ||
| with urllib.request.urlopen(req) as resp: | ||
| return json.loads(resp.read() or "null") | ||
|
|
||
|
|
||
| def upsert(body, repo, pr, token): | ||
| base = f"https://api.github.com/repos/{repo}" | ||
| comments = api("GET", f"{base}/issues/{pr}/comments?per_page=100", token) | ||
|
abulgit marked this conversation as resolved.
|
||
| existing = next((c for c in comments if MARKER in (c.get("body") or "")), None) | ||
| if existing: | ||
| api("PATCH", f"{base}/issues/comments/{existing['id']}", token, {"body": body}) | ||
| else: | ||
| api("POST", f"{base}/issues/{pr}/comments", token, {"body": body}) | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 2: | ||
| sys.exit("usage: perf_comment.py results.json") | ||
|
|
||
| with open(sys.argv[1]) as f: | ||
| results = json.load(f) | ||
|
|
||
| body = render(results) | ||
| print(body) | ||
|
|
||
| token = os.environ.get("GITHUB_TOKEN") | ||
| repo = os.environ.get("REPO") | ||
| pr = os.environ.get("PR_NUMBER") | ||
| if token and repo and pr: | ||
| upsert(body, repo, pr, token) | ||
| print(f"upserted comment on {repo}#{pr}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: perf | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths-ignore: | ||
| - 'spec/**' | ||
| - 'changelog/**' | ||
| - '**/*.md' | ||
| push: | ||
| branches: [master] | ||
|
|
||
| concurrency: | ||
| group: perf-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| perf: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 60 | ||
| env: | ||
| OS_NAME: linux | ||
| MODEL: 64 | ||
| FULL_BUILD: false | ||
| HOST_DMD: ldc-1.42.0 | ||
| ENABLE_LTO: 1 | ||
| defaults: | ||
| run: | ||
| shell: bash | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set parallelism | ||
| run: echo "N=$(nproc)" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Compute base/head SHAs | ||
| id: refs | ||
| run: | | ||
| set -uexo pipefail | ||
| HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}" | ||
| git fetch --no-tags origin master | ||
| BASE_SHA="$(git merge-base "$HEAD_SHA" origin/master)" | ||
| echo "head=$HEAD_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "base=$BASE_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "branch=${GITHUB_BASE_REF:-master}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Install prerequisites | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y valgrind time | ||
| valgrind --version | ||
|
|
||
| - name: Install host compiler | ||
| run: ci/run.sh install_host_compiler | ||
|
|
||
| - name: Build dmd at base and head | ||
| run: | | ||
| set -uexo pipefail | ||
| build_ref() { | ||
| local dir="$RUNNER_TEMP/$2/dmd" | ||
| mkdir -p "$RUNNER_TEMP/$2" | ||
| git worktree add --force "$dir" "$1" | ||
| ( cd "$dir" && ci/run.sh setup_repos "${{ steps.refs.outputs.branch }}" && ci/run.sh build 0 ) | ||
|
abulgit marked this conversation as resolved.
|
||
| } | ||
| build_ref "${{ steps.refs.outputs.base }}" base | ||
| build_ref "${{ steps.refs.outputs.head }}" head | ||
|
|
||
| - name: Measure | ||
| run: | | ||
| set -uexo pipefail | ||
| source ~/dlang/*/activate | ||
| built=generated/$OS_NAME/release/$MODEL/dmd | ||
| cd tools/perfrunner | ||
| dub run -- \ | ||
| --base-dmd "$RUNNER_TEMP/base/dmd/$built" \ | ||
| --head-dmd "$RUNNER_TEMP/head/dmd/$built" \ | ||
| --base-sha "${{ steps.refs.outputs.base }}" \ | ||
| --head-sha "${{ steps.refs.outputs.head }}" \ | ||
| --pr "${{ github.event.pull_request.number || 0 }}" \ | ||
| --host-dmd "$HOST_DMD" \ | ||
| --out "$GITHUB_WORKSPACE/results.json" | ||
|
|
||
| - name: Post sticky PR comment | ||
| if: github.event_name == 'pull_request' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: python3 .github/scripts/perf_comment.py results.json | ||
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .dub/ | ||
| perfrunner | ||
| perfrunner.exe | ||
| *-test-* | ||
| *.o | ||
| *.obj | ||
| results.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "perfrunner", | ||
| "description": "DMD performance measurement (dev-phase)", | ||
| "targetType": "executable", | ||
| "sourcePaths": ["source"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| module app; | ||
|
|
||
| import std.file : mkdirRecurse, tempDir, write; | ||
| import std.getopt : getopt; | ||
| import std.path : buildPath, dirName; | ||
| import std.stdio : stderr, writeln; | ||
|
|
||
| import metrics : measure, initials; | ||
| import report : MetricResult, render, Report; | ||
|
|
||
| // Initial workload: the one source file compile to measure DMD. | ||
| enum workload = buildPath(__FILE_FULL_PATH__.dirName.dirName, "workloads", "hello.d"); | ||
|
|
||
| version (unittest) {} else | ||
| int main(string[] args) | ||
| { | ||
| string baseDmd, headDmd, baseSha, headSha, hostDmd; | ||
| string os = "ubuntu-latest"; | ||
| string outPath = "results.json"; | ||
| long pr; | ||
|
|
||
| auto help = getopt(args, | ||
| "base-dmd", "path to the base (merge-base) dmd binary", &baseDmd, | ||
| "head-dmd", "path to the head (PR) dmd binary", &headDmd, | ||
| "base-sha", "base commit sha (metadata)", &baseSha, | ||
| "head-sha", "head commit sha (metadata)", &headSha, | ||
| "pr", "pull request number (metadata)", &pr, | ||
| "os", "runner OS label (metadata)", &os, | ||
| "host-dmd", "bootstrap dmd version (metadata)", &hostDmd, | ||
| "out", "where to write results.json", &outPath, | ||
| ); | ||
|
|
||
| if (help.helpWanted) | ||
| { | ||
| writeln("usage: perfrunner --base-dmd <path> --head-dmd <path> " | ||
| ~ "[--base-sha <sha> --head-sha <sha> --pr <n>] --out results.json"); | ||
| return 0; | ||
| } | ||
|
|
||
| if (baseDmd.length == 0 || headDmd.length == 0) | ||
| { | ||
| stderr.writeln("error: --base-dmd and --head-dmd are required"); | ||
| return 2; | ||
| } | ||
|
|
||
| auto tmp = buildPath(tempDir, "perfrunner"); | ||
| mkdirRecurse(tmp); | ||
|
|
||
| auto base = measure(baseDmd, workload, tmp, "base"); | ||
| auto head = measure(headDmd, workload, tmp, "head"); | ||
|
|
||
| MetricResult[] metrics; | ||
| foreach (def; initials) | ||
| metrics ~= MetricResult(def.id, def.label, def.unit, def.method, | ||
| base[def.id], head[def.id]); | ||
|
|
||
| auto rep = Report(baseSha, "merge-base", headSha, pr, os, hostDmd, metrics); | ||
| write(outPath, render(rep)); | ||
| writeln("wrote ", outPath); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| module cachegrind; | ||
|
|
||
| import std.algorithm : startsWith; | ||
| import std.array : split; | ||
| import std.conv : to; | ||
| import std.file : readText; | ||
| import std.path : buildPath; | ||
| import std.process : execute; | ||
| import std.string : lineSplitter, strip; | ||
|
|
||
| long parseInstructions(string cgout) | ||
| { | ||
| foreach (line; cgout.lineSplitter) | ||
| if (line.startsWith("summary:")) | ||
| return line["summary:".length .. $].strip.split[0].to!long; | ||
| throw new Exception("could not find 'summary:' line in cachegrind output"); | ||
| } | ||
|
|
||
| // Compile the workload under cachegrind | ||
| long instructions(string dmd, string[] dflags, string workload, string tmp, string tag) | ||
| { | ||
| auto obj = buildPath(tmp, tag ~ ".o"); | ||
| auto cgOut = buildPath(tmp, tag ~ ".cgout"); | ||
| auto cmd = ["valgrind", "--tool=cachegrind", "--cachegrind-out-file=" ~ cgOut, | ||
| dmd, "-c"] ~ dflags ~ [workload, "-of=" ~ obj]; | ||
| auto r = execute(cmd); | ||
| if (r.status != 0) | ||
| throw new Exception("cachegrind failed:\n" ~ r.output); | ||
| return parseInstructions(readText(cgOut)); | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| auto sample = "events: Ir\nfn=(1) main\n5 100\nsummary: 1234500000\n"; | ||
| assert(parseInstructions(sample) == 1_234_500_000); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.