Command Line

9. Debugging

2019-03-27 08:00 CST
2020-03-23 11:32 CST
[![Creative Commons License](https://i.creativecommons.org/l/by-nc/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc/4.0/)

System

stress -c # brew install stress
# Log
ls /var/log # Log file
cat /var/log/system.log | lnav # brew install lnav
log show # macos
log show --last 1m
logger "Hello Logs"
# 查询系统调用
sudo strace ls -l > /dev/null # dtrace for macos
# static analysis
writegood notes.md # brew install write-good
# time
time curl https://google.com
# perf
sudo perf stat stress -c 1
sudo perf record stress -c 1
sudo perf report
# computer status
top
htop
du # disk usage
ncdu
lsof # list open files
# benchmark
hyperfine --warmup 3 'fd -e jpg' 'find . -iname "*.jpg"

C

time

#include <time.h>
usleep(ms)

gdb

gdb --args sleep 20 # gdb with binary
lldb -- sleep 20 # lldb

profile

valgrind

Python

static analysis

pyflakes test.py
mypy test.py

pdb

python -m ipdb test.py # pip install ipdb
# in ipdb
l #list
s #step
restart #restrat
p value #print
p locals()
c #continue
q #quit debugger
b 6 #breakpoint

profiles

Trace profiles

python -m cProfile -s tottime test.py
python -m memory\_profiler test.py # pip install memory\_profiler

Line profiles: add @profile before function

kernprof -l -v urls.py # pip install line\_profiler