Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit e3ef933

Browse files
Add profile test for kbuild (#487)
Measures profiling data for kompilation and rekompilation. --------- Co-authored-by: devops <[email protected]>
1 parent 8f87eae commit e3ef933

File tree

14 files changed

+97
-12
lines changed

14 files changed

+97
-12
lines changed

.github/workflows/test-pr.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,28 @@ jobs:
5858
profile:
5959
needs: code-quality-checks
6060
name: 'Profiling'
61-
runs-on: ubuntu-latest
61+
runs-on: [self-hosted, linux, normal-ephemeral]
6262
steps:
6363
- name: 'Check out code'
6464
uses: actions/checkout@v3
65+
- name: 'Install Python'
66+
uses: actions/setup-python@v4
67+
with:
68+
python-version: '3.10'
6569
- name: 'Install Poetry'
6670
uses: Gr1N/setup-poetry@v8
71+
- name: 'Install K'
72+
run: |
73+
K_VERSION=$(cat deps/k_release)
74+
DEB_PACKAGE_NAME=kframework_${K_VERSION}_amd64_ubuntu_jammy.deb
75+
wget https://github.com/runtimeverification/k/releases/download/v${K_VERSION}/${DEB_PACKAGE_NAME}
76+
sudo apt-get update
77+
sudo apt-get -y install ./${DEB_PACKAGE_NAME}
78+
kompile --version
6779
- name: 'Run profiling'
6880
run: |
6981
make profile
70-
find /tmp/pytest-of-${USER}/pytest-current/ -type f | sort | xargs tail -n +1
82+
find /tmp/pytest-of-${USER}/pytest-current/ -type f -name '*.prof' | sort | xargs tail -n +1
7183
7284
integration-tests:
7385
needs: code-quality-checks

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.329
1+
0.1.330

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.329"
7+
version = "0.1.330"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/testing/_profiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, tmp_path: Path):
1919
@contextmanager
2020
def __call__(
2121
self,
22-
file_name: str = 'profile.txt',
22+
file_name: str = 'profile.prof',
2323
*,
2424
sort_keys: Iterable[str | SortKey] = (),
2525
patterns: Iterable[str] = (),

src/tests/profiling/profile_kast_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def test_kast_json(profile: Profiler) -> None:
1717
with json_file.open() as f:
1818
json_data = json.load(f)
1919

20-
with profile('profile-json-kast.txt', sort_keys=('cumtime',), limit=20):
20+
with profile('json-to-kast.prof', sort_keys=('cumtime',), limit=20):
2121
kast: KAst = kast_term(json_data)
2222

23-
with profile('profile-kast-json.txt', sort_keys=('cumtime',), limit=20):
23+
with profile('kast-to-json.prof', sort_keys=('cumtime',), limit=20):
2424
kast.to_dict()

src/tests/profiling/profile_kast_to_kore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ def test_kast_to_kore(profile: Profiler) -> None:
2222

2323
sys.setrecursionlimit(10**8)
2424

25-
with profile('init-kast-defn.txt', sort_keys=('cumtime',), limit=50):
25+
with profile('init-kast-defn.prof', sort_keys=('cumtime',), limit=50):
2626
kast_defn = read_kast_definition(kast_defn_file)
2727

28-
with profile('init-kore-defn.txt', sort_keys=('cumtime',), limit=50):
28+
with profile('init-kore-defn.prof', sort_keys=('cumtime',), limit=50):
2929
kore_defn = KompiledKore(kast_to_kore_dir)
3030
kore_defn.definition
3131

3232
kast = KInner.from_json(kinner_file.read_text())
3333

34-
for file_name in ['kast-to-kore-1.txt', 'kast-to-kore-2.txt']:
34+
for file_name in ['kast-to-kore-1.prof', 'kast-to-kore-2.prof']:
3535
with profile(file_name, sort_keys=('cumtime',), limit=25):
3636
kore = kast_to_kore(kast_defn, kore_defn, kast, sort=KSort('GeneratedTopCell'))
3737

38-
with profile('kore-to-kast.txt', sort_keys=('cumtime',), limit=25):
38+
with profile('kore-to-kast.prof', sort_keys=('cumtime',), limit=25):
3939
kore_to_kast(kast_defn, kore)

src/tests/profiling/profile_kbuild.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import pytest
6+
7+
from pyk.kbuild import KBuild, Package
8+
9+
from .utils import TEST_DATA_DIR
10+
11+
if TYPE_CHECKING:
12+
from pathlib import Path
13+
from typing import Final
14+
15+
from pyk.testing import Profiler
16+
17+
18+
A_SEMANTICS_DIR: Final = TEST_DATA_DIR / 'kbuild/a-semantics'
19+
20+
21+
@pytest.fixture
22+
def kbuild(tmp_path: Path) -> KBuild:
23+
return KBuild(tmp_path / 'kbuild')
24+
25+
26+
def test_kbuild(kbuild: KBuild, profile: Profiler) -> None:
27+
with profile('kompile.prof', sort_keys=('cumtime', 'tottime'), limit=35):
28+
package = Package.create(A_SEMANTICS_DIR / 'kbuild.toml')
29+
kbuild.kompile(package, 'llvm')
30+
31+
with profile('rekompile.prof', sort_keys=('cumtime', 'tottime'), limit=35):
32+
package = Package.create(A_SEMANTICS_DIR / 'kbuild.toml')
33+
kbuild.kompile(package, 'llvm')

src/tests/profiling/profile_kore_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ def test_kore_parse(profile: Profiler) -> None:
1818

1919
sys.setrecursionlimit(10**8)
2020

21-
with profile(sort_keys=('cumtime',), limit=50):
21+
with profile('parse_kore.prof', sort_keys=('cumtime',), limit=50):
2222
parser.definition()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
requires "b-semantics/b.k"
2+
requires "c-semantics/c.k"
3+
4+
module A-SYNTAX
5+
endmodule
6+
7+
module A
8+
imports B
9+
imports C
10+
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "a-semantics"
3+
version = "0.1.0"
4+
source = "."
5+
6+
[dependencies]
7+
b-semantics = { path = "../b-semantics" }
8+
c-semantics = { path = "../c-semantics" }
9+
10+
[targets.llvm]
11+
main-file = 'a.k'
12+
backend='llvm'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module B-SYNTAX
2+
endmodule
3+
4+
module B
5+
endmodule
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[project]
2+
name = "b-semantics"
3+
version = "0.1.0"
4+
source = "."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module C-SYNTAX
2+
endmodule
3+
4+
module C
5+
endmodule
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[project]
2+
name = "c-semantics"
3+
version = "0.1.0"
4+
source = "."

0 commit comments

Comments
 (0)