Skip to content

Commit

Permalink
implement more features
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamilcuk committed Nov 27, 2024
1 parent bffcdfc commit 977b312
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 148 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ venv/
# due to using nox and pytest
.nox
.cache
profile.*
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MAKEFLAGS = -rR
all:
echo
test:
pytest -sv
L_lib:
L_bash_profile profile profile.txt '. ../L_lib/bin/L_lib.sh test'
xdot:
L_bash_profile analyze profile.txt --dot profile.dot --dotlimit 3
xdot profile.dot
snakeviz:
L_bash_profile analyze profile.txt --pstatsfile profile.pstats
snakeviz profile.pstats
16 changes: 16 additions & 0 deletions scripts/example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail

f() {
sleep 0.1
sleep 0.1
sleep 0.1
}

g() {
sleep 0.1
f 2
}

g 1
sleep 0.1
15 changes: 15 additions & 0 deletions scripts/profiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail

_trap_DEBUG() {
local txt i
for i in ${!BASH_SOURCE[@]}; do
txt+=$'\t'"$i:${BASH_SOURCE[i]}:${BASH_LINENO[i]}:${FUNCNAME[i]}"
done
echo "# ${BASH_COMMAND@Q}$txt"
}
# trap 'echo "# ${BASH_COMMAND@Q} ${#BASH_SOURCE[@]} ${BASH_SOURCE[0]@Q} $LINENO ${FUNCNAME[0]:-}"' DEBUG
trap '_trap_DEBUG' DEBUG
set -T
"$@"
: END
1 change: 1 addition & 0 deletions tests/script.py → scripts/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def c():
time.sleep(0.3)
a()
b()

print("c")
with tempfile.NamedTemporaryFile() as statsfile:
cProfile.run("(b(0),b(0),b(1),b(1))", statsfile.name)
Expand Down
Loading

0 comments on commit 977b312

Please sign in to comment.