A Reusable Aspect for Memory Profiling

例子:

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;
}

时间: 2024-10-09 17:32:45

A Reusable Aspect for Memory Profiling的相关文章

A Reusable Aspect for Memory Allocation Checking

The checking logic would be refactored into an aspect file, as follows: after(void * s) : (call($ malloc(...)) || call($ calloc(...)) || call($ realloc(...))) && result(s) { char * result = (char *)(s); if (result == NULL) { /* routine to handle t

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 tensorflow deep learning models, but only some of the time? Are you curious about exactly how much GPU memory your tensorflow model uses during training? Are

Introduction to C Memory Management and C++ Object-Oriented Programming

C is used when at least one of the following matters: Speed Memory Low-level features(moving the stack pointer, etc.). Level of abstraction Languages Directly manipulate memory Assembly(x86,MIPS) Access to memory C,C++ Memory managed Java,C#,Scheme/L

Java性能提示(全)

http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLists and ArrayLists (and Vectors) (Page last updated May 2001, Added 2001-06-18, Author Jack Shirazi, Publisher OnJava). Tips: ArrayList is faster than

内核 跟踪与统计工具

Tracing and Profiling Contents [hide] 1 Tracing and Profiling in Yocto 1.1 General Setup 2 Overall Architecture of the Linux Tracing and Profiling Tools 3 Basic Usage (with examples) for each of the Yocto Tracing Tools 3.1 perf 3.1.1 Setup 3.1.2 Basi

为你的应用加速 - 安卓优化指南

原文链接 : Speed up your app 原文作者 : UDI COHEN 译文出自 : 开发技术前线 www.devtf.cn.未经允许,不得转载! 译者 :zijianwang90 校对者: 状态 : 完成 几周之前,我在Droidcon NYC上有过一次关于Android性能优化的演讲. 我在这个演讲中花费了大量的时间,因为我想通过真实的例子展现性能问题,以及我是通过什么样的工具去发掘这些问题的.因为时间原因,在演讲中我不得不舍弃一半的内容.在这篇文章中,我会总结在演讲中我所讨论的

JS内存泄漏 和Chrome 内存分析工具简介(摘)

原文地址:http://web.jobbole.com/88463/ JavaScript 中 4 种常见的内存泄露陷阱 原文:Sebastián Peyrott 译文:伯乐在线专栏作者 - ARIGATO 链接:http://web.jobbole.com/88463/ 点击 → 了解如何加入专栏作者 了解 JavaScript 的内存泄露和解决方式! 在这篇文章中我们将要探索客户端 JavaScript 代码中常见的一些内存泄漏的情况,并且学习如何使用 Chrome 的开发工具来发现他们.读

转载-----nodejs内存定位

追踪NodeJS代码中的内存泄漏一直是一个很有挑战的难题.本文讨论如何从一个node写的应用里自动的跟踪到内存泄漏问题,在这里笔者向大家推荐两款追查内存问题的神器 —— memwatch 和 heapdump 首先,我们来看一个简单的内存泄漏 var http = require('http'); var server = http.createServer(function (req, res) { for (var i=0; i<1000; i++) { server.on('request

Java Performance Optimization Tools and Techniques for Turbocharged Apps--reference

Java Performance Optimization by: Pierre-Hugues Charbonneau reference:http://refcardz.dzone.com/refcardz/java-performance-optimization Java is among the most widely used programming languages in the software development world today. Java applications