Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

FMemStats.h 2.33 KB
Newer Older
1 2 3 4 5
#ifndef FMEMSTATS_H
#define FMEMSTATS_H


#include <stdlib.h>
6
#include <cstring>
7 8

#ifdef SCALFMM_USE_MEM_STATS
9 10 11
#include <new>
#include <stdexcept>
#warning use meme stats
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    void* operator new(std::size_t n) throw(std::bad_alloc);
    void* operator new(size_t n, std::nothrow_t const&) throw();
    void* operator new[](size_t n) throw(std::bad_alloc);
    void* operator new[](size_t n, std::nothrow_t const&) throw();
    void operator delete(void* p) throw();
    void operator delete(void* p, std::nothrow_t const&) throw();
    void operator delete[](void* p) throw();
    void operator delete[](void* p, std::nothrow_t const&) throw();
#endif

class FMemStats {
private:
    unsigned long long maxAllocated;
    unsigned long long totalAllocated;
    std::size_t currentAllocated;

    FMemStats()
        : maxAllocated(0), totalAllocated(0), currentAllocated(0) {
    }

    void allocate(const std::size_t size){
        currentAllocated += size;
        totalAllocated += size;

        if(maxAllocated < currentAllocated){
            maxAllocated = currentAllocated;
        }
    }

    void deallocate(const std::size_t size){
        currentAllocated -= size;
    }

45
#ifdef SCALFMM_USE_MEM_STATS
46 47 48 49 50 51 52 53
    friend void* operator new(std::size_t n) throw(std::bad_alloc);
    friend void* operator new(size_t n, std::nothrow_t const&) throw();
    friend void* operator new[](size_t n) throw(std::bad_alloc);
    friend void* operator new[](size_t n, std::nothrow_t const&) throw();
    friend void operator delete(void* p) throw();
    friend void operator delete(void* p, std::nothrow_t const&) throw();
    friend void operator delete[](void* p) throw();
    friend void operator delete[](void* p, std::nothrow_t const&) throw();
54
#endif
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

public:
    static FMemStats controler;

    unsigned long long getMaxAllocated() const{
        return maxAllocated;
    }

    unsigned long long getTotalAllocated() const{
        return totalAllocated;
    }

    std::size_t getCurrentAllocated() const{
        return currentAllocated;
    }
70 71 72 73 74 75 76 77 78 79 80 81

    float getMaxAllocatedMB() const{
        return float(getMaxAllocated()) / 1024 / 1024;
    }

    float getTotalAllocatedMB() const{
        return float(getTotalAllocated()) / 1024 / 1024;
    }

    float getCurrentAllocatedMB() const{
        return float(getCurrentAllocated()) / 1024 / 1024;
    }
82 83 84 85
};


#endif // FMEMSTATS_H