参考:http://msdn.microsoft.com/en-us/library/windows/desktop/ms679291(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms680181(v=vs.85).aspx

http://sleepy.sourceforge.net/

http://www.codersnotes.com/sleepy

Very Sleepy是一个比较好用的Profiler工具(是对Sleepy的改进版本),开源,代码也很简洁。

那么Sleepy的原理是什么呢?

Sleepy程序作为主进程,启动子进程,或者Attach到目标进程上,从而获取到目标进程的第一个线程。

Sleepy每隔很短的一段时间就调用一次sample取样操作

void CALLBACK sprof_callback(UINT wTimerID, UINT msg,

                        DWORD dwUser, DWORD dw1, DWORD dw2)

{

    ProfilerThread* thread = (ProfilerThread*)dwUser;

 

    thread->sample();

 

}

然后将目标线程暂停,并且查看目标线程正在执行的eip地址

void Profiler::sampleTarget()

{

    // An open question is whther or not this routine can be called

    // reentrantly by the multi-media timer support.

 

    HRESULT result = SuspendThread(target_thread);

 

    if(result == 0xffffffff)

        throw ProfilerExcep("SuspendThread failed.");

 

    CONTEXT threadcontext;

    threadcontext.ContextFlags = CONTEXT_i386 | CONTEXT_CONTROL;

    result = GetThreadContext(target_thread, &threadcontext);

    if(!result)

        throw ProfilerExcep("GetThreadContext failed.");

 

    PROFILER_ADDR addr = threadcontext.Eip;

 

    //std::cout << "addr: " << addr << std::endl;

 

    result = ResumeThread(target_thread);

    if(!result)

        throw ProfilerExcep("ResumeThread failed.");

 

    //NOTE: this has to go after ResumeThread.  Otherwise mem allocation needed by std::map

    //may hit a lock held by the suspended thread.

    counts[addr]++;

}

并且将维护一张map,记录各个被取样到的ip地址被调用到的次数。

最后再通过DbgHlp的Sym功能,将ip地址映射成具体的函数名称。

Very Sleepy加入了Call Graph的feature,可以统计Include/Exclude方式下的某个函数被调用的计数。

估计是使用了DbgHelp的StackWalk64函数。

基于对pin的学习,这个功能很容易地用pintool重新改写。

但是,pintool的好处在哪呢?

Sleepy与DbgHlp库学习的更多相关文章

  1. python 操作exls学习之路1-openpyxl库学习

    这篇要讲到的就是如何利用Python与openpyxl结合来处理xlsx表格数据.Python处理表格的库有很多,这里的openpyxl就是其中之一,但是它是处理excel2007/2010的格式,也 ...

  2. dlib库学习之一

    dlib库学习之一 1.介绍 跨平台 C++ 通用库 Dlib 发布 ,带来了一些新特性,包括概率 CKY 解析器,使用批量同步并行计算模型来创建应用的工具,新增两个聚合算法:中国低语 (Chines ...

  3. python_库学习_01

    一.python的库学习之 财经数据接口包 1.安装ThShare 直接pip install tushare 可能会出现缺少依赖库的情况,依次安装,大概有lxml,pandas,bs4,reques ...

  4. numpy, matplotlib库学习笔记

    Numpy库学习笔记: 1.array()   创建数组或者转化数组 例如,把列表转化为数组 >>>Np.array([1,2,3,4,5]) Array([1,2,3,4,5]) ...

  5. python爬虫解析库学习

    一.xpath库使用: 1.基本规则: 2.将文件转为HTML对象: html = etree.parse('./test.html', etree.HTMLParser()) result = et ...

  6. 【mmall】Guava库学习Collections

    参考链接 Guava库学习:学习Collections(三)Sets

  7. muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor

    目录 muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor Connector 系统函数connect 处理非阻塞connect的步骤: Connetor时序图 Accep ...

  8. muduo网络库学习笔记(四) 通过eventfd实现的事件通知机制

    目录 muduo网络库学习笔记(四) 通过eventfd实现的事件通知机制 eventfd的使用 eventfd系统函数 使用示例 EventLoop对eventfd的封装 工作时序 runInLoo ...

  9. muduo网络库学习笔记(三)TimerQueue定时器队列

    目录 muduo网络库学习笔记(三)TimerQueue定时器队列 Linux中的时间函数 timerfd简单使用介绍 timerfd示例 muduo中对timerfd的封装 TimerQueue的结 ...

随机推荐

  1. python re模块常用的正则表达式

    '.'     默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^'     匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r&qu ...

  2. C++ Compiling… Error spawning cl.exe

    转自VC错误:http://www.vcerror.com/?p=500 解决方法: 方法(一): 启动VC时不要用图形界面,通过在命令提示符下输入:Msdev /useenv运行(注意啦/前面有个空 ...

  3. 关于radio选中或者反选

      关注点:一.attr()和prop()的区别 <!DOCTYPE html> <html> <head> <title>JavaScript对文字按 ...

  4. os模块方法

    OS 对象方法: 提供了处理文件及目录的一系列方法 os.rename(current_file_name, new_file_name) 重命名 os.remove(file_name) 删除文件 ...

  5. jquery hover中嵌套mouseenter,mouseenter函数执行多次的问题解决方案

    已知晓在jq中hover的API就是把mouseenter和mouseleave组合在一起来用的,在jq中实现`hover:function(fnOver,fnOut){return this.mou ...

  6. wrong mechandise category

    Issue: cannot open masterdata for this two UPCs since the error below is displayed, but I checked an ...

  7. shell变量替换扩展 变量测试

  8. makefile自动编译

    1.格式:  目标:依赖 规则    规则前有一个tab键 ,缺少tab键出错,使用空格替代也不可以 (1). 例子: 编写makefile 编译 main.c ,fun.c , fun.h test ...

  9. KiCAD实用操作

    KiCAD实用操作之一:自动编辑线宽 今天偶然间发现的一个比较实用的功能,算是KiCAD的一个优点吧(或许是在AD上面没发现):当整个PCB布完线或者在布线过程中,我们有可能需要对某个线的宽度进行调整 ...

  10. idea 右键没有class文件的问题,,

    修改文件夹的  属性  蓝色即为java代码,,绿色为test,,等等