Skip to content

Commit 743a6a5

Browse files
committed
🆕 [perf] init
0 parents  commit 743a6a5

File tree

9 files changed

+11355
-0
lines changed

9 files changed

+11355
-0
lines changed

.github/LICENSE

Lines changed: 314 additions & 0 deletions
Large diffs are not rendered by default.

.github/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../perf

.github/scripts/export.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#
2+
# The MIT License (MIT)
3+
#
4+
# Copyright (c) 2024-2025 Kris Jusiak <[email protected]>
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#
24+
# Requirements:
25+
# - apt-get install coreutils # base64
26+
# - apt-get install imagemagick # convert
27+
# - apt-get install libsixel-bin # sixel
28+
# - pip install ansi2html # ansi2html
29+
#
30+
# Usage:
31+
# ./app 2>&1 | ./export.sh markdown > app.md
32+
# ./app 2>&1 | ./export.sh notebook > app.ipynb
33+
# ./app 2>&1 | ./export.sh html > app.html
34+
35+
function markdown() {
36+
rm -rf tmp
37+
mkdir tmp
38+
stdin=$(mktemp)
39+
stdout=$(mktemp)
40+
41+
cat - > $stdin
42+
43+
i=0
44+
while grep -q $'\x1bP' $stdin; do
45+
sed -z 's/\(.*\)\x1bP.*/\1/' $stdin >> $stdout
46+
sed -z 's/.*\(\x1bP.*\x1b\\\).*/\1/' $stdin | \
47+
convert sixel:- png:- > tmp/$((i++)).png
48+
sed -z 's/.*\x1b\\\(.*\)/\1/' $stdin >> $stdout
49+
mv $stdout $stdin
50+
done
51+
52+
cat $stdin > tmp/$((i++))
53+
}
54+
55+
function html() {
56+
stdin=$(mktemp)
57+
stdout=$(mktemp)
58+
59+
cat - | ansi2html > $stdin
60+
61+
while grep -q $'\x1bP' $stdin; do
62+
sed -z 's/\(.*\)\x1bP.*/\1/' $stdin >> $stdout
63+
sed -z 's/.*\(\x1bP.*\x1b\\\).*/\1/' $stdin | \
64+
convert sixel:- png:- | base64 | tr -d '\n' | \
65+
xargs -i{} echo "<img src='data:image/png;base64,{}'/><br />" >> $stdout
66+
sed -z 's/.*\x1b\\\(.*\)/\1/' $stdin >> $stdout
67+
mv $stdout $stdin
68+
done
69+
cat $stdin
70+
}
71+
72+
function notebook() {
73+
cat <<EOF
74+
{
75+
"cells": [
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
$(cat - | markdown | sed 's/.*/"&\\n",/')
81+
""
82+
]
83+
}
84+
],
85+
"metadata": {
86+
"jupytext": {
87+
"cell_metadata_filter": "-all",
88+
"main_language": "python",
89+
"notebook_metadata_filter": "-all"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 5
94+
}
95+
EOF
96+
}
97+
98+
if [ $# -lt 1 ]; then
99+
echo "Usage: $0 <markdown|notebook|html> # reads from stdin"
100+
exit 1
101+
fi
102+
103+
cat - | $1

.github/scripts/setup.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2024-2025 Kris Jusiak <[email protected]>
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
sudo mount -o remount,mode=755 /sys/kernel/debug
26+
sudo mount -o remount,mode=755 /sys/kernel/debug/tracing
27+
echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
28+
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
29+
sudo chown "$(whoami)" /sys/kernel/debug/tracing/uprobe_events
30+
sudo chmod a+rw /sys/kernel/debug/tracing/uprobe_events
31+
32+
if [[ -n "$MAX_SAMPLE_RATE" ]]; then
33+
echo "$MAX_SAMPLE_RATE" | sudo tee /proc/sys/kernel/perf_event_max_sample_rate
34+
fi

.github/scripts/tune.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2024-2025 Kris Jusiak <[email protected]>
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
sudo cpupower frequency-set --governor performance # Disable CPU Frequency Scaling (apt install cpufrequtils)
26+
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space # Disable Address Space Randomization
27+
echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost # Disable Processor Boosting
28+
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo # Disable Turbo Mode
29+
echo off | sudo tee /sys/devices/system/cpu/smt/control # Disable Hyper-threading

.github/workflows/Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2024-2025 Kris Jusiak <[email protected]>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
# ```
24+
# docker build -t perf .
25+
# ```
26+
27+
# ```
28+
# docker run \
29+
# --rm \
30+
# --user $(id -u):$(id -g) \
31+
# --privileged \
32+
# --network=host \
33+
# -e DISPLAY=${DISPLAY} \
34+
# -v ${PWD}:${PWD} \
35+
# -w ${PWD} \
36+
# perf
37+
# ```
38+
39+
FROM ubuntu:24.04
40+
ARG CLANG=20
41+
ARG GCC=14
42+
43+
RUN apt-get update && apt-get install -y \
44+
gnupg software-properties-common lsb-release ca-certificates \
45+
python3-pip python3-venv cmake \
46+
wget bzip2 vim pkg-config dbus-x11 git gh \
47+
kmod linux-headers-generic linux-tools-generic linux-tools-*-generic util-linux hwloc msr-tools \
48+
llvm-dev libpfm4 libpapi-dev papi-tools libipt-dev \
49+
libgoogle-perftools-dev google-perftools valgrind kcachegrind coz-profiler pahole likwid hotspot hyperfine \
50+
graphviz gnuplot coreutils imagemagick libsixel-bin
51+
52+
RUN python3 -m venv /venv
53+
RUN /venv/bin/pip install \
54+
pyperf osaca \
55+
jupyter numpy pandas matplotlib ansi2html
56+
57+
RUN wget -qO - https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | \
58+
gpg --dearmor -o /usr/share/keyrings/intel-oneapi-archive-keyring.gpg
59+
RUN echo "deb [signed-by=/usr/share/keyrings/intel-oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | \
60+
tee /etc/apt/sources.list.d/oneAPI.list
61+
RUN apt-get update && apt-get install -y libnss3 intel-oneapi-vtune
62+
63+
RUN wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh $CLANG && rm llvm.sh
64+
RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt update && apt install -y g++-$GCC
65+
66+
ENV PATH="/venv/bin:$PATH"
67+
ENV DISPLAY=:0

.github/workflows/linux.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: linux
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v3
17+
18+
- name: image
19+
run: docker build -f .github/workflows/Dockerfile -t perf .
20+
21+
- name: build
22+
run: |
23+
cat <<EOF > perf.cpp
24+
#include <perf>
25+
int main() { }
26+
EOF
27+
docker run --rm --privileged -v ${PWD}:${PWD} -w ${PWD} perf sh -c "\
28+
clang++-20 -DPERF_INTEL=0 -std=c++23 -O3 -I. -I/usr/lib/llvm-20/include -lLLVM-20 -lipt perf.cpp -o perf && ./perf"

0 commit comments

Comments
 (0)