例子:

malPro.acc文件:

#include <stdlib.h>
size_t totalMemoryAllocated;
int totalAllocationFuncCalled;
int totalFreeFuncCalled;

void initProfiler() {
totalMemoryAllocated = 0;
totalAllocationFuncCalled = 0;
totalFreeFuncCalled = 0;
}

void printProfiler() {
printf("total memory allocated = %d bytes\n", totalMemoryAllocated );
printf("total memory allocation function called = %d \n", totalAllocationFuncCalled);
printf("total memory free function called = %d\n", totalFreeFuncCalled);
}

before(): execution(int main()) {
initProfiler();
}
after(): execution(int main()) {
printProfiler();
}

before(size_t s): call($ malloc(...)) && args(s) {
totalMemoryAllocated += s;
totalAllocationFuncCalled ++;
}
before(size_t n, size_t s): call($ calloc(...)) && args(n, s) {
totalMemoryAllocated += n * s;
totalAllocationFuncCalled ++;
}

before(size_t s): call($ realloc(...)) && args(void *, s) {
totalMemoryAllocated += s;
totalAllocationFuncCalled ++;
}

before() : call(void free(void *)) {
totalFreeFuncCalled++;
}

mal.c文件:

#include <stdio.h>
#include <malloc.h>
void t1()
{
int *x ;
printf(" core code:hehe ! \n");
x = (int *)malloc(sizeof(int) * 4);
printf(" core code:hehe ! ! \n");
}
int main()
{
t1();
int *x ;
printf(" core code:hehe ! ! \n");
x = (int *)malloc(sizeof(int) * 4);
printf(" core code:hehe ! ! \n");
return 0;
}

A Reusable Aspect for Memory Profiling的更多相关文章

  1. A Reusable Aspect for Memory Allocation Checking

    The checking logic would be refactored into an aspect file, as follows: after(void * s) : (call($ ma ...

  2. .NET Memory Allocation Profiling with Visual Studio 2012

    .NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...

  3. Reducing and Profiling GPU Memory Usage in Keras with TensorFlow Backend

    keras 自适应分配显存 & 清理不用的变量释放 GPU 显存 Intro Are you running out of GPU memory when using keras or ten ...

  4. 32 Profiling Go Programs 分析go语言项目

    Profiling Go Programs  分析go语言项目 24 June 2011 At Scala Days 2011, Robert Hundt presented a paper titl ...

  5. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  6. Android APP性能分析方法及工具

    近期读到<Speed up your app>一文.这是一篇关于Android APP性能分析.优化的文章.在这篇文章中,作者介绍他的APP分析优化规则.使用的工具和方法.我觉得值得大家借 ...

  7. XHProf中文手册

    目录 导言 XHProf 概况 安装XHProf扩展 使用XHProf进行性能分析 设置XHProf用户界面 在生产环境中使用XHProf注意事项 轻量级采样模式 附加功能 信赖 鸣谢 导言 XHPr ...

  8. Chrome开发者工具之JavaScript内存分析

    阅读目录 对象大小(Object sizes) 对象的占用总内存树 支配对象(Dominators) V8介绍 Chrome 任务管理器 通过DevTools Timeline来定位内存问题 内存回收 ...

  9. [转载]JavaScript内存分析

    https://github.com/CN-Chrome-DevTools/CN-Chrome-DevTools/blob/master/md/Performance-Profiling/javasc ...

随机推荐

  1. [系统]no such partition

    电脑系统是win8.1+ubuntu14.2,为了卸载ubuntu,安装CentOS,于是在win8.1下把ubuntu的分区给删除了,重启,出现no such partition grub resc ...

  2. 使用whIle循环语句和变量打印九九乘法表

    -设置i变量declare @i int --设置j变量declare @j int --设置乘法表变量declare @chengfabiao varchar(1000)--给i,j,@chengf ...

  3. Js配置资料下载

    1.使用windows.loaction.href链接下载: 此种下载在本页打开,eg:windows.location.href = http://www.xxx.xx/aa.apk; 2.使用wi ...

  4. JS监听事件错误:Uncaught TypeError: xx(函数名)is not a function at HTMLInputElement.onclick

    事件监听一直出错,提示已定义的函数名不是一个函数,折腾了好久才想到,原来是函数名和JS内部关键字重名造成的. 以前也遇到过这种情况,但因为发生的概率比较小,就没太在意,但是这次感觉这方面确实需要注意, ...

  5. CWnd* pParent

    Dlg(CWnd* pParent = NULL)的意思是:构造函数.创建对象时第一个调用的地方.CWnd* pParent=NULL是构造的参数,可以不传入,默认为NULL 构造函数(constru ...

  6. -bash:whois:command not found

    在centOS 下,如果出现-bash:whois:command not found的问题, 则yum install 安装whois软件 yum install -y jwhois 包名是jwho ...

  7. 从0开始复习JS---1、函数复习

    1. 写一个函数,实现对数字数组的排序. function get_order(array){ for(var i = 0; i <array.length-1; i++){ for(var j ...

  8. Codeforces Round #467 Div.2题解

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. mysql命令整理

    MySQL大小写通用. 一.常见用的mysql指令 1.show databases; #查看当前所有库 2.show tables; #查看所在库中的所有表 3.use 库名; #进入该库 4.sh ...

  10. Serial Fluent UDF on Windows

    test test Table of Contents 1. Serial UDF on Windows OS 1 Serial UDF on Windows OS Note: Udf has to ...