一、常用命令
1. find查找
(1) 跳过单个目录查找:
$ find ./ -path "./base" -prune -o -name '*.c' //在当前目录下跳过base目录查找.c文件 $ find ./ \( -path "./arch" \) -prune -o -name '*locking*' $ find ./ -path "./base" -prune -o -name '*.c' | xargs grep cpufreq //跳过当前目录下的base目录grep cpufreq
(2) 跳过多个目录查找:
$ find ./ \( -path "./arch" -o -path "./Documentation" -o -path "./samples" -o -path "./tools" \) -prune -o -name '*.c' | xargs grep trace_sched_cpu_capacity_tp
2. 文本编辑
(1) 用sed命令删除行尾的"^M"
# sed -i 's/\r//g' <文件名>
(2) 用删除行尾空格
vim打开,输入 :%s/\s*$//g 回车,:wq 保存
(3) 显示指定行,从第10行开始,显示20行。即显示10~30行
cat Makefile | tail -n +10 | head -n 20
(5) 一键修改code style(Linux内核)
sudo apt-get install -y indent ./scripts/Lindent ./sched/fair.c
3. 服务器变更后服务器间拷贝资料
scp -r ~/{.ssh,.netrc,.gitconfig} <your_name_or_number>@11.22.33.44:/work/ scp ~/.bashrc ~/.profile <your_name_or_number>@11.22.33.44:/work/ source ~/.bashrc source ~/.profile
4. 根据Gerrit拉单个仓库
http://gerrit.<your_server>:8080/#/c/13835640/ Project <project_name> Branch <branch_name> git clone ssh://<your_name>@gerrit.<your_server>:29418/<project_name> -b <branch_name>
5. 查看刷新率
while(true) ; do dumpsys SurfaceFlinger | grep refresh-rate; sleep 1; done
6. 查看场景和Activity
#看场景 while true; do dumpsys window | grep mCurrentFocus; sleep 0.5; done dumpsys window | grep mCurrentFocus #查看前台包名和运行的activity #查看前台包名,实时显示 am monitor #查看子activity dumpsys activity | grep mResumedActivity: #查看前台Activity dumpsys activity activities | grep mResume
二、常用脚本
1. trace相关
(1) 抓trace
P=/sys/kernel/tracing; echo sched_switch > $P/set_event; echo notrace_printk > $P/trace_options; echo nomarkers > $P/trace_options; > $P/trace; echo 1 > $P/tracing_on; cat $P/trace_pipe
(2) 使能sched系统的所有trace
for i in `find /sys/kernel/tracing/events -name "enable" | grep sched_`; do echo 1 > $i; done //使能 for i in `find /sys/kernel/tracing/events -name "enable" | grep sched_`; do cat $i; done //查看
2. logcat中查找
getprop persist.sys.assert.panic; logcat --buffer-size=125M; logcat | grep -i xxx #用这个去找,xxx不区分大小写的
3. 进程相关信息
(1) 常用打印
# 打印一个进程的任务的信息 P=14029; for p in `ls /proc/$P/task`; do echo $p; cat /proc/$P/task/$p/comm; cat /proc/$P/task/$p/sched | grep prio; cat /proc/$P/task/$p/status | grep Cpus_allowed:; done #打印一个cgroup分组任务的信息 for p in `cat /dev/cpuset/top-app/tasks`; do echo $p; cat /proc/$p/comm; cat /proc/$p/status | grep Cpus_allowed; done #打印一个cgroup分组任务的进程的各任务的信息 for P in `cat /dev/cpuset/top-app/cgroup.procs`; do echo $P; cat /proc/$P/comm; echo "--------"; for T in `ls /proc/$P/task`; do cat /proc/$P/task/$T/comm; done; echo; done;
(2) 进程名(模糊)匹配
P=5117 for T in `ls /proc/$P/task` do C=`cat /proc/$P/task/$T/comm` if [[ $C == binder:* ]]; then chrt -f -p $T 1 #RT prio: 99-1=98 cat /proc/$P/task/$T/comm; cat /proc/$P/task/$T/sched | grep prio; fi done; # 写为1行 P=5117; for T in `ls /proc/$P/task`; do C=`cat /proc/$P/task/$T/comm`; if [[ $C == binder:* ]]; then cat /proc/$P/task/$T/comm; cat /proc/$P/task/$T/sched | grep prio; fi done;
(3) 查看所有以 kworker 开头的线程的优先级
for P in `ps -elf | grep -v grep | grep kworker | awk '{print $2}'` do echo $P; cat /proc/$P/comm; cat /proc/$P/sched | grep prio; done; #写为1行 for P in `ps -elf | grep -v grep | grep kworker | awk '{print $2}'`; do echo $P; cat /proc/$P/comm; cat /proc/$P/sched | grep prio; done;
4. 测试进程与设置命令
while true; do let i=i+1; done & let i=0; while true; do let i=i+1; done & let i=0; while true; do if [ i -lt 100 ]; then let i=i+1; else let i=0; sleep 0.1; fi; done & taskset -p 0f <pid> renice -n 2 -p <pid> chrt -f -p <pid> 15 #将自己绑到指定核上运行 let i=0; while [ i -lt 200000 ]; do if [ i -lt 1 ]; then taskset -p 20 $$; fi; let i=i+1; done
5. cat系统文件
#cat一个目录下所有的文件 P=/sys/devices/system/cpu/cpu0/core_ctl; for F in `ls $P`; do echo "cat $P/$F"; cat $P/$F; echo; done; #循环打印文件内容 while true; do cat /proc/sys/kernel/sched_rt_period_us; sleep 0.1; done
6. cat一类目录下的某个文件
#cat thermal 的 type 节点 F=policy; P=/sys/class/thermal; for T in `ls $P`; do if [[ $T == thermal_* ]]; then echo "cat $P/$T/$F"; cat "$P/$T/$F"; fi done; #cat thermal 的 type 和 temp 节点 F1=type; F2=temp; P=/sys/class/thermal; for T in `ls $P`; do if [[ $T == thermal_* ]]; then echo "cat $P/$T/$F1"; cat "$P/$T/$F1"; echo "cat $P/$T/$F2"; cat "$P/$T/$F2"; fi done;
7. CPU相关信息
#看CPU限频和限核信息 P=/sys/devices/system/cpu; for i in 0 4 7; do cat $P/cpu$i/cpufreq/scaling_max_freq; cat $P/cpu$i/cpufreq/scaling_min_freq; cat $P/cpu$i/core_ctl/enable; cat $P/cpu$i/core_ctl/global_state | head -5; echo "-----"; done; #看5s内各cluster在各频点驻留时间 for i in 0 4 7; do echo 1 > /sys/devices/system/cpu/cpufreq/policy$i/stats/reset; done; sleep 5; for i in 0 4 7; do echo "----freq-$i----"; cat /sys/devices/system/cpu/cpufreq/policy$i/stats/time_in_state; done; #定频 //设为只读 P=/sys/devices/system/cpu/cpufreq; C=policy0; echo 2000000 > $P/$C/scaling_max_freq; echo 2000000 > $P/$C/scaling_min_freq; chmod 444 $P/$C/scaling_max_freq; chmod 444 $P/$C/scaling_min_freq; //cat P=/sys/devices/system/cpu/cpufreq; C=policy0; cat $P/$C/scaling_max_freq; cat $P/$C/scaling_min_freq; //执行完恢复 P=/sys/devices/system/cpu/cpufreq; C=policy0; chmod 666 $P/$C/scaling_max_freq; chmod 666 $P/$C/scaling_min_freq; # 关核后开核 P=/sys/devices/system/cpu; for i in 0 1 2 3 4 5 6 7; do echo 0 > $P/cpu$i/online; sleep 0.2; echo 1 > $P/cpu$i/online; done; cat $P/online; #使能MTK打印谁设置频点的 echo 1 > /sys/devices/system/cpu/perf/enable
8. bpftrace相关
(1) 查看文件接口参数和返回值
bpftrace -e 'kprobe:proc_test_write { printf("pid=%d, tid=%d, comm=%s, str=%s ", pid, tid, comm, str(uptr(arg1))); } kretprobe:proc_test_write { printf("ret=%d\n", retval);}' bpftrace -e 'kprobe:online_store { printf("pid=%d, comm=%s, str=%s ", pid, comm, str(arg2)); } kretprobe:online_store { printf("ret=%d\n", retval);}'
标签:脚本,do,常用,grep,echo,done,cat,proc From: https://www.cnblogs.com/hellokitty2/p/17131707.html