Android 常用指令

adb shell /system/bin/screencap -p /sdcard/screenshot.png // 截圖
adb shell ps 得到進程號
adb shell am dumpheap 進程號  /storage/sdcard0/mem.hprof   //倒出hprof文件
adb reboot bootloader//重啟進入fastboot模式
fastboot flash system system.img
make snod//產生一個新的系統映像system.img
make ramdisk//編譯ramdisk
make userdateimage//編譯userdata
make systeyimage//編譯system
make bootimage//編譯kernel
adb shell top -m 8//查看前8個CPU使用最高的進程
adb shell top -t -m 8//查看前8個CPU使用最高的線程
adb logcat -v time //輸出時間信息 LOG
adb logcat -v time -b events //輸出帶有時間event信息 LOG
adb logcat -v time -s SurfaceFlinger//輸出有時間信息並且TAG是SurfaceFlingerLOG
adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq//查看CPU頻率
adb shell "echo 0 > /proc/sys/kernel/kptr_restrict sysctl" 在/proc/kallsyms輸出的地址都為0時,可以導出符合表
應用打開debug模式:<application ...... android:debuggable="true">
禁止GC的方式:
VMRuntime localVMRuntime;
localVMRuntime = VMRuntime.getRuntime();
localVMRuntime.disableGcForExternalAlloc(true);
localVMRuntime.disableGcForExternalAlloc(false);

填滿手機內置U盤空間

adb shell dd if=/dev/zero of=/mnt/sdcard/bigfile
adb shell getevent -lt /dev/input/eventXXX
adb shell showmap PID
adb shell showslab
adb shell procrank
native memory leak:
adb shell mv /system/lib/libc.so /system/lib/libc_original.so
adb shell mv /system/lib/libc_dubug.so /system/lib/libc.so
adb shell setprop persist.libc.debug.malloc 1
adb shell reboot

打印堆棧:

Log.d(TAG,Log.getStackTraceString(new Throwable()));
  • 得到Client端的uid跟package name:
int uid = Binder.getCallingUid();
String as[] = ((PackageManagerService)ServiceManager.getService("package")).getPackagesForUid(uid);
if(as != null && as[0] != null)
  • 編譯內核模塊:
make -C ~/src/jb_rel-M8974AAAAANLYA31050148/out/target/product/msm8974/obj/KERNEL_OBJ M=`pwd`  ARCH=arm
  CROSS_COMPILE=/opt2/oujunli/src/jb_rel-M8974AAAAANLYA31050148/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/  CFLAGS_MODULE=-fno-pic modules
adb forward tcp:8080 tcp:8080
adb shell am dumpheap 9800  /storage/sdcard0/123.hprof


adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/pwrnap"

adb shell "echo 0 > /sys/class/kgsl/kgsl-3d0/pwrnap"
adb shell "echo performance > sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor" GPU為performance
adb shell "echo ondemand > /sys/class/kgsl/kgsl-3d0/pwrscale/trustzone/governor"
  • 在/system/build.prop裡面添加
debug.mdpcomp.mixedmode.disable=1
debug.mdpcomp.logs=1
耗時的函數在mdss_mdp_overlay_kickoff 裡面。
adb shell stop thermald
adb shell stop mpdecision
adb shell "echo 1 > /sys/devices/system/cpu/cpu0/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu1/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu2/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu3/online"
adb shell "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
adb shell cat /sys/kernel/debug/tracing/available_events

adb shell cat /sys/kernel/debug/tracing/available_events | grep kgsl
mount -rw -o remount /system

adb shell "cat /sys/kernel/debug/clk/bimc_clk/rate"

find ./* -name ".svn" | xargs -exec rm -rif {}

man -k dtrace
sudo dtrace  -s py_calldist.d -c  sdk/platform-tools/systrace/systrace.py
sudo dtrace -s py_cputime.d  -c "python sdk/platform-tools/systrace/systrace.py"


find . -name "*.java" | xargs grep -rni "sdcard"  |tee  ~/logcat

adb shell am profile com.example.android start  /sdcard/example.trace
adb shell am   profile com.example.android stop
adb pull /sdcard/example.trace,再用eclipse打開
python systrace.py  --app=com.taobao.taobao gfx view am wm res dalvik hal webview  -o ojl.html
adb shell strace  -f -t -p 21627
adb shell debuggerd -b <pid>
adb shell cat /proc/<pid>/status
adb shell cat /data/system/packages.xml

In your DDMS configuration file (e.g. ~/.android/ddms.cfg on Linux), add "native=true". This enables the Native Heap tab.
Next, enable native heap allocation tracking on the device, and restart the app framework:
% adb shell setprop libc.debug.malloc 1
% adb shell stop
% adb shell start
Trace.beginSection("ContentView");
Log.d("ojl", "trace");
setContentView(R.layout.cart3);
Trace.endSection();


adb shell "tcpdump -n -s 0 -w - | nc -l -p 12345"

import android.os.Debug;
Log.d(TAG, "start method tracing");
Debug.startMethodTracing("cool", 20*1024*1024);


Log.d(TAG, "stop methond tracing");
Debug.stopMethodTracing();

Log.d("ojl", "ItemDownloader before priority = " + Process.getThreadPriority(Process.myTid()));
//Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND-4);
//Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND-10);
//Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT+1);
//Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT
//+(Process.THREAD_PRIORITY_BACKGROUND - Process.THREAD_PRIORITY_DEFAULT)/2);
//Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND+Process.THREAD_PRIORITY_MORE_FAVORABLE);

import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
private WakeLock wakeLock;
private LocationManager locationManager;


PowerManager pm = (PowerManager) getSystemService(this.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getCanonicalName());
wakeLock.acquire();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  • 編譯gator.ko
make -C kernelpath  M=`pwd` ARCH=arm
adb forward tcp:8080 tcp:8080
adb shell setenforce 0

<7>[ 855.028505] SELinux: initialized (dev gatorfs, type gatorfs), not configured for labeling

<5>[ 855.029024] type=1400 audit(1406342819.348:241): avc: denied { mount } for pid=2347 comm="gatord-main" name="/" dev="gatorfs" ino=13742 scontext=u:r:shell:s0 tcontext=u:object_r:unlabeled:s0 tclass=filesystem setenforce 0

new Thread() {
    public void run() {
        try {
            sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Log.d("myException","xxxxxxxxxxxxxxxxxx");
        throw new RuntimeException("xxxxxxxxxxxxxxxxx");
    }
}.start();

Linux相關:

awk ‘{print $5}‘ |awk ‘{sum += $5};END{print sum}‘ test 計算某一列的和
du -h --max-depth=1 ./ 計算文件夾及文件的大小
知道指定後綴名的文件總個數命令:
find . -name "*.cpp" | wc -l
知道一個目錄下代碼總行數以及單個文件行數:
find . -name "*.h" | xargs wc -l
find . -name "*.c" | xargs grep ‘^.‘ | wc -l    //不包括空白行
find <要查找的路徑> -name .svn |xargs rm -rf
sudo find / -name "*opencv*" -exec rm -i {} \;
ssh oujunli@192.168.2.3
scp oujunli@192.168.2.3:/home/ojl/tmpfile  ./
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/9.1-RELEASE/src.txz
sudo apt-get build-dep gedit ,這樣基本上你開發gtk+的庫都會被安裝上.
provider:
dtrace -l|grep -v "PROVIDER"|awk ‘{print $2}‘|sort -u
dtrace -l -P provider
provider:module
dtrace -ln ‘fbt:::‘ | awk ‘{ print $2":"$3 }‘ | sort -u
sudo dtrace -n ‘syscall:::entry { @[stack(), ustack()] = count(); }‘ -c ‘./ls1 .‘
sudo dtrace -Fn ‘syscall::: { }‘ -c ‘./shell1‘
rsync --delete-before -a -H -v --progress --stats /tmp src/
sudo stap -p2 -e ‘probe kernel.function("*") {}‘ 2>&1 | grep ^kernel.fun
echo `cat /proc/slabinfo|awk ‘BEGIN{sum=0}{sum=sum+$3*$4;}END{print sum/1024/1024}‘` MB
find . -name ‘*.cpp‘ -print0 | xargs -0 perl -pi -e ‘s/ALOGV/ALOGD/g‘
find . -name "*.c" -print0 | xargs -0 sed -i ‘s/ALOGV/ALOGD/g
ls |xargs realpath |tee ../basic.name
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all  ./test-sdk
valgrind --tool=memcheck --leak-check=full --error-limit=no  --show-leak-kinds=all --dsymutil=yes  --log-file=logcat.txt --gen-suppressions=no -v ./Test
解:
jar xvf rt.jar
壓:
jar cvf rt.jar rt
mvn dependency:tree
mvn eclipse:eclipse
git log -p --author="悟嗔"

adb shell "echo function > /sys/kernel/debug/tracing/current_tracer"
adb shell "echo 1846 > /sys/kernel/debug/tracing/set_ftrace_pid"
adb shell "echo 1 > /sys/kernel/debug/tracing/tracing_enabled"
adb shell cat /sys/kernel/debug/tracing/trace
adb shell "echo nop > /sys/kernel/debug/tracing/current_tracer"
adb shell "echo 0 > /sys/kernel/debug/tracing/tracing_enabled"
adb shell "echo 1 > /proc/sys/kernel/ftrace_dump_on_oops"
grep CONFIG_UPROBES /boot/config-`uname -r`
If uprobes is integrated, the output of this command is as follows:
CONFIG_UPROBES=y
If you are running a kernel prior to version 3.5, SystemTap automatically builds the uprobes module. However, you also need the utrace kernel extensions required by the SystemTap user-space probing to track various user-space events. More details about the utrace infrastructure are available at http://sourceware.org/systemtap/wiki/utrace. To determine whether the currently running Linux kernel provides the needed utrace support, type the following at a shell prompt:
grep CONFIG_UTRACE /boot/config-`uname -r`
If the Linux kernel supports user-space probing, the command produces the following output:
CONFIG_UTRACE=y

openindiana相關:
pkg serache -pr package // 查找包
pkg install package //安裝包
pkgin -y update   //更新數據
pkg -y install pacage //安裝包

VIM相關:

1、刪除文本中的^M
問題描述:對於換行,window下用回車換行(0A0D)來表示,Linux下是回車(0A)來表示。這樣,將window上的文件拷到Unix上用時,總會有個^M.請寫個用在unix下的過濾windows文件的換行符(0D)的shell或c程序。
· 使用命令:cat filename1 | tr -d "^V^M" > newfile;
· 使用命令:sed -e "s/^V^M//" filename > outputfilename。需要注意的是在12兩種方法中,^V和^M指的是Ctrl+V和Ctrl+M。你必須要手工進行輸入,而不是粘貼。
· 在vi中處理:首先使用vi打開文件,然後按ESC鍵,接著輸入命令:%s/^V^M//。
· :%s/^M$//g
如果上述方法無用,則正確的解決辦法是:
· tr -d "\r" < src >dest
· tr -d "\015" dest
· strings A>B

""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = ‘/usr/bin/ctags‘
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_Right_Window = 1
"let Tlist_Use_Left_Window = 1
let Tlist_Sort_Type = ‘name‘
let Tlist_Show_Menu = 1
let Tlist_Auto_Open = 1
nmap <silent> <F8> :TlistToggle<CR><CR>
2、生成cscope和ctags
  find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.java" -o -name "*.S" > cscope.files && cscope -Rbqk -i cscope.files&&ctags -R
  find . -path "./framework/*" -a -prune -o除去framework目錄。
自動加載cscope文件,在.vimrc中添加:
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif

如果你是Python程序員,推薦http://t.cn/z84bJPg 。大名鼎鼎的移動支付公司 Square,最近將他們技術團隊使用的 Vim 配置文件 Maximum Awesome 開源了,Vim 黨們可以關注下。http://t.cn/z8UQPFW GitHub 地址:http://t.cn/z84w8ht