zoukankan      html  css  js  c++  java
  • 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 ", totalMemoryAllocated );
    printf("total memory allocation function called = %d ", totalAllocationFuncCalled);
    printf("total memory free function called = %d ", 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 ! ");
    x = (int *)malloc(sizeof(int) * 4);
    printf(" core code:hehe ! ! ");
    }
    int main()
    {
    t1();
    int *x ;
    printf(" core code:hehe ! ! ");
    x = (int *)malloc(sizeof(int) * 4);
    printf(" core code:hehe ! ! ");
    return 0;
    }

  • 相关阅读:
    noip2007 tg day1t1 统计数字
    洛谷1123 取数游戏
    洛谷1123 取数游戏
    素数筛
    bzoj 1297 [SCOI2009]迷路
    bzoj 2115 [Wc2011] Xor——路径和环的转化
    poj 2154 Color——带优化的置换
    bzoj 1407 [Noi2002]Savage
    poj 1286 Necklace of Beads
    bzoj 4031 [HEOI2015]小Z的房间
  • 原文地址:https://www.cnblogs.com/xiaohuihui123/p/4565443.html
Copyright © 2011-2022 走看看