wince linux 性能,wince remote call profiler(性能分析)

如何使用

1 建立工程,CPU类型必须于目标机型一致如ARMV4I,所以选择WCE Application,然后选择empty project

new1.jpg

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)[@more@]

prof1.jpg

6 在EVC窗口上按CTRL+F5,下载运行Profilee

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

8 选择菜单上Top X View,选择刚才编译出来的profilee.exe(需要从中导入Debug信息,这也是我们要编译Debug版本的原因,否则看不到函数名等信息,只能看到函数偏移地址).可以看到,最耗时的函数列表

prof3.jpg

到这一步,不知道大家有没有一个疑问,是不是我们的目标机器在编译镜像的时候必须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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值