# based on http://www.brendangregg.com/blog/2014-09-17/node-flame-graphs-on-linux.html
rm *.log
rm flamegraph.txt
rm *.svg

rm perf.data
rm perf.data.old

#JSFILE=hello.js
JSFILE=test_subdivisions2.compiled.js

node --perf-basic-prof $JSFILE & #>output.txt &
pgrep -n node || echo "node NOT RUNNING"
pgrep -n node && echo "YES: RUNNNING"
echo "SLEEP 30. Wait..."
#pgrep -n node && sudo perf record -F 99 -p `pgrep -n node` -g -- sleep 30
#pgrep -n node && sudo perf record -F 99 -p `pgrep -n node` -g -- sleep 30s
# && echo "999999999999" 
#man perf record
#  -g = callgraph
#FREQUENCY=9900
FREQUENCY=990
#pgrep -n node && sudo perf record -F $FREQUENCY -p `pgrep -n node` -g
pgrep -n node && sudo perf record -F $FREQUENCY -p `pgrep -n node` -g -T

ps faux|grep perf

echo "SLEEP 30 finished."
sudo chown sohail:sohail perf.data
ls -alt
perf script > flamegraph.txt
perf report -n --stdio >flamegraph.report
ls -alt

#./FlameGraph/flamegraph.pl --help
cd FlameGraph
./stackcollapse-perf.pl < ../flamegraph.txt | ./flamegraph.pl --fontsize 9 --width 20000 > ../flamegraph.svg
gnome-open ../flamegraph.svg



# ps axl | awk '$10 ~ /T/'
# pstree -p 1489
# pgrep dockerd


# sudo kill -CONT 4587 4552 4538 1959 1489
# sudo kill -STOP 4587 4552 4538 1959 1489


