A Reusable Aspect for Memory Profiling
2015-06-10 10:56
465 查看
例子:
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;
}
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;
}
相关文章推荐
- ASP NET MVC OutputCache
- Asp.Net Url重写页面中Session无效
- KafkaSpout分析:配置
- 不支持union select 时的asp手工注入方法
- Aspose.Word 操作word复杂表格 拆分单元格 复制行 插入行 文字颜色
- Aspose.Word 操作word复杂表格 拆分单元格 复制行 插入行
- Asp的两个内置对象request和response
- C#语法糖之Cookies操作类 asp.net
- Metasploit渗透学习日记
- OSX10.10 Yosemite安装Metasploit
- 使用ASP.Net WebAPI构建REST服务——客户端
- 使用CLK.AspNet.Identity提供以角色为基础的访问控制(RBAC)
- C#语法糖之 session操作类 asp.net
- Aspose.Word 操作word表格的行 插入行 添加行
- Aspose.Word 操作word表格的行 插入行 添加行
- ASP.NET中使用Excel导入数据到数据库
- Aspose.Words.Tables.Row类操作word表格行
- Aspose.Words.Tables.Row类操作word表格行
- asp.net 使用UrlRewritingNet.UrlRewriter组件URL重写,伪静态详解
- ASP.NET forms凭据设置和跳转的几种方法