-
Notifications
You must be signed in to change notification settings - Fork 3
139 lines (120 loc) · 4.84 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Benchmark new formats
on:
pull_request:
paths:
- 'waveform_benchmark/formats/**'
jobs:
benchmark-new-formats:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
permissions:
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Install libsndfile library (required by soundfile)
run: |
sudo apt-get update
sudo apt-get install libsndfile1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install -r requirements.txt
- name: Discover JVM Path
run: |
JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
echo "JAVA_HOME: $JAVA_HOME"
if [ -d "$JAVA_HOME/lib/server" ]; then
echo "JPY_JVM_DLL=$JAVA_HOME/lib/server/libjvm.so"
elif [ -d "$JAVA_HOME/jre/lib/server" ]; then
echo "JPY_JVM_DLL=$JAVA_HOME/jre/lib/server/libjvm.so"
elif [ -d "$JAVA_HOME/lib/client" ]; then
echo "JPY_JVM_DLL=$JAVA_HOME/lib/client/libjvm.so"
else
echo "libjvm.so not found in usual locations"
fi
- name: Copy .env.example to .env
run: cp .env.example .env
- name: Update .env with JVM DLL Path
run: |
echo "export JPY_JVM_DLL='/opt/hostedtoolcache/Java_Adopt_jdk/11.0.23-9/x64/lib/server/libjvm.so'" >> .env
cat .env # Optionally display the .env file to verify changes
- name: Find new or modified benchmark files
id: find-formats
run: |
git fetch origin main
FILES=$(git diff --diff-filter=AM --name-only origin/main...HEAD 'waveform_benchmark/formats/*.py')
echo "$FILES" > format_files.txt
cat format_files.txt
- name: Run benchmark tests on new or modified format files
run: |
FORMAT_FILES=$(cat format_files.txt)
if [ -z "$FORMAT_FILES" ]; then
echo "No format files found to process."
exit 0
fi
IFS=' ' read -ra FILES <<< "$FORMAT_FILES"
RECORD_NAME="./data/waveforms/mimic_iv/waves/p100/p10079700/85594648/85594648"
for file in "${FILES[@]}"
do
# Skip base.py file
if [[ "$file" == *"base.py" ]]; then
echo "Skipping benchmark for $file"
continue
fi
# Extract the module path from the file path
MODULE_PATH=$(echo "$file" | sed 's/\//./g' | sed 's/\.py$//')
# Find and list all classes in the module
echo "Running benchmarks for classes in $MODULE_PATH"
CLASSES=$(python3 -c "import sys; import inspect; from importlib import import_module; mod = import_module('$MODULE_PATH'); print(' '.join(cls for cls, obj in inspect.getmembers(mod, inspect.isclass) if obj.__module__ == mod.__name__ and not cls.startswith('Base')))")
IFS=' ' read -ra CLS <<< "$CLASSES"
for cls in "${CLS[@]}"
do
CLASS_PATH="$MODULE_PATH.$cls"
FILENAME="benchmark_results_${cls}.txt"
echo "Benchmarking $CLASS_PATH"
./waveform_benchmark.py -r "$RECORD_NAME" -f "$CLASS_PATH" > "$FILENAME"
done
done
- name: Concatenate results
run: |
if ls benchmark_results_*.txt 1> /dev/null 2>&1; then
cat benchmark_results_*.txt > final_results.txt
echo "Benchmark results:"
cat final_results.txt
else
echo "No benchmarks were run." > final_results.txt
fi
# Requires private TOKEN to be added to run on PRS from external repos
# - name: Post results to pull request
# uses: actions/github-script@v7
# with:
# script: |
# const fs = require('fs');
# const filePath = 'final_results.txt';
# if (!fs.existsSync(filePath) || fs.statSync(filePath).size === 0) {
# console.log("No results to post.");
# return;
# }
# const resultContent = fs.readFileSync(filePath, 'utf8');
# await github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: context.issue.number,
# body: `Benchmark results:\n\`\`\`\n${resultContent}\n\`\`\``
# });