forked from Erotemic/hotspotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler.sh
More file actions
executable file
·74 lines (63 loc) · 2.06 KB
/
profiler.sh
File metadata and controls
executable file
·74 lines (63 loc) · 2.06 KB
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
#!/bin/sh
# Globals
export TIMESTAMP=$(date -d "today" +"%Y-%m-%d_%H-%M-%S")
export RAW_SUFFIX=raw.prof
export CLEAN_SUFFIX=clean.prof
# Input
export pyscript=$1
# Output Stage 1
export line_profile_output=$pyscript.lprof
# Output Stage 2
export raw_profile=raw_profile.$pyscript.$TIMESTAMP.$RAW_SUFFIX
export clean_profile=clean_profile.$pyscript.$TIMESTAMP.$CLEAN_SUFFIX
remove_profiles()
{
echo "Removing profiles"
#rm *.profile.txt
rm *raw.prof
rm *clean.prof
rm *.lprof
echo "Finshed removing profiles"
}
echo "Input: $@"
if [ "$pyscript" = "clean" ]; then
remove_profiles
exit
fi
echo "pyscript: $pyscript"
echo "line_profile_output: $line_profile_output"
echo "Profiling $pyscript"
export SYSNAME="$(expr substr $(uname -s) 1 10)"
# Choose one
export PROFILE_TYPE="kernprof" # plop or kernprof
#export PROFILE_TYPE="plop" # plop or kernprof
if [ $PROFILE_TYPE = "plop" ]; then
python -m plop.collector $@
echo "http://localhost:8888"
python -m plop.viewer --datadir=profiles
elif [ $PROFILE_TYPE = "kernprof" ]; then
# Line profile the python code w/ command line args
if [ "$SYSNAME" = "MINGW32_NT" ]; then
export MINGW_PYEXE=$(python -c "import sys; print(sys.executable)")
export MINGW_PYDIR=$(python -c "import sys, os; print(os.path.dirname(sys.executable))")
$MINGW_PYEXE $MINGW_PYDIR/Scripts/kernprof.py -l $@
else
kernprof.py -l $@
fi
# Dump the line profile output to a text file
python -m line_profiler $line_profile_output >> $raw_profile
# Clean the line profile output
python _scripts/profiler_cleaner.py $raw_profile $clean_profile
# Print the cleaned output
cat $clean_profile
fi
# In windows I had to set the default .sh extension to run with
# C:\MinGW\msys\1.0\bin\sh.exe
#assoc .sh=sh_auto_file
#ftype sh_auto_file="C:\MinGW\msys\1.0\bin\sh.exe" %1 %*
#
#set PATHEXT=.sh;%PATHEXT%
#assoc .sh
#assoc .sh=bashscript
#ftype bashscript="C:\MinGW\msys\1.0\bin\sh.exe" %1 %*
#https://stackoverflow.com/questions/105075/how-can-i-associate-sh-files-with-cygwin