天天看點

wince remote call profiler(性能分析)

如何使用

1 建立工程,CPU類型必須于目标機型一緻如ARMV4I,是以選擇WCE Application,然後選擇empty project

wince remote call profiler(性能分析)

2 project settings 中,link頁,Object/library modules中添加 cecap.lib(前面有空格),Ingore libraries中添加,libc.lib(前面有逗号).C/C++頁Project Options最後添加 /callcap(前面有空格)

cecap.lib 在C:Program FilesCommon FilesMicrosoft SharedWindows CE ToolsPlatmansdkwce500lib 下(wce500是目标機器平台)

3 添加檔案main.cpp,(文檔中要求必須include檔案cecap.h,實際上可以不包含該檔案)

4 編譯(確定Active Configuration是ARMV4I Debug)

5 運作Remote Call Profiler,連接配接到目标機器,如圖,選擇Start等待profilee運作(也可以拷貝profilee到目标機器,然後Launch)

[@[email protected]]

wince remote call profiler(性能分析)

6 在EVC視窗上按CTRL+F5,下載下傳運作Profilee

7 回到Remote Call Profiler,可以看到Profile Data不再是No Data,點選Finish

8 選擇菜單上Top X View,選擇剛才編譯出來的profilee.exe(需要從中導入Debug資訊,這也是我們要編譯Debug版本的原因,否則看不到函數名等資訊,隻能看到函數偏移位址).可以看到,最耗時的函數清單

wince remote call profiler(性能分析)

到這一步,不知道大家有沒有一個疑問,是不是我們的目标機器在編譯鏡像的時候必須Enable Profiling.如果這樣,Remote Call Profiler的用途就受到了很大限制,比如很多機器我們沒有BSP或者Enable Profiling會導緻應用的運作環境與最終産品有大的差異.所幸Enable Profiling不是必須的,看下面的原理:

原理及其進一步的應用用IDA反彙編profilee.exe,找到函數WinMain

.text:00011068 LDR R0, =WinMain

.text:0001106C BL _CAP_Enter_Function

.text:0001106C

.text:00011070 LDR R0, =s_Profilee

.text:00011074 BL NKDbgPrintfW

.text:00011074

.text:00011078 BL DoWork1

.text:00011078

.text:0001107C LDR R0, =s_End

.text:00011080 BL NKDbgPrintfW

.text:00011080

.text:00011084 LDR R0, =WinMain

.text:00011088 BL _CAP_Exit_Function

該處的源碼是

NKDbgPrintfW (L"========== Profilee ==========rn");

DoWork1();

NKDbgPrintfW (L"========== END ==========rn");

可以看到,函數的開始處調用了_CAP_Enter_Function,結束處調用了_CAP_Exit_Function,顯然這是由于添加了編譯選項/callcap的緣故.而庫cecap.lib提供了這兩個函數的實作.實際上我們工程裡的每一個函數都同WinMain類似,可以想象,_CAP_XXX函數可以得到函數的運作資訊,并通過Remote Call Profiler以不同方式顯示出來.

如果你覺得Remote Call Profiler不夠爽,自己實作_CAP_XXX好了,在裡面做任何你想做的事情

fastcap

第2步,編譯選項從callcap改為fastcap,其他不變

同callcap相比,fastcap會計算出調用其他庫函數的時間了(如系統函數Sleep)

反彙編如下

.text:00011070 LDR R1, =NKDbgPrintfW

.text:00011074 LDR R0, =WinMain

.text:00011078 BL _CAP_Start_Profiling

.text:00011078

.text:0001107C LDR R0, =s_Profilee

.text:00011080 BL NKDbgPrintfW

.text:00011080

.text:00011084 LDR R0, =WinMain

.text:00011088 BL _CAP_End_Profiling

.text:00011088

.text:0001108C LDR R1, =DoWork1

.text:00011090 LDR R0, =WinMain

.text:00011094 BL _CAP_Start_Profiling

.text:00011094

.text:00011098 BL DoWork1

.text:00011098

.text:0001109C LDR R0, =WinMain

.text:000110A0 BL _CAP_End_Profiling

.text:000110A0

.text:000110A4 LDR R1, =NKDbgPrintfW

.text:000110A8 LDR R0, =WinMain

.text:000110AC BL _CAP_Start_Profiling

.text:000110AC

.text:000110B0 LDR R0, =s_End

.text:000110B4 BL NKDbgPrintfW

.text:000110B4

.text:000110B8 LDR R0, =WinMain

.text:000110BC BL _CAP_End_Profiling

EVC測試工程下載下傳

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/116625/viewspace-1005857/,如需轉載,請注明出處,否則将追究法律責任。

轉載于:http://blog.itpub.net/116625/viewspace-1005857/