source: XIOS/dev/dev_ym/XIOS_COUPLING/src/memtrack.hpp @ 2335

Last change on this file since 2335 was 2212, checked in by ymipsl, 3 years ago

Revisiting Memory tracking :

  • MemTrack? has been improved
    • Not need anymore to use private external libaddr2line, fork addr2line process internaly and use bidrectionnale pipe to send stack adress et get in return the demangle stack name
    • Can use cxa_demangle in backup
  • Block memory leak report is output in separate file (xios_xxx.mem),memory block are ordonned in decreasing size.
  • Possibility to output only the n bigest bloc with : "memtrack_blocs" xios parameters
  • Possibility to output only bloc over a given size with : "memtrack_size" xios parameters
  • Implement new method to retrieve the memory consumed in a time interval very similarely to xios timer :

CMemTracker("xios").resume()
CMemTracker("xios").suspend() ;
etc....

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 2.9 KB
RevLine 
[401]1#ifdef XIOS_MEMTRACK
2/*
3Copyright (c) 2002, 2008 Curtis Bartley
4All rights reserved.
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
9- Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
12- Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the
15distribution.
16
17- Neither the name of Curtis Bartley nor the names of any other
18contributors may be used to endorse or promote products derived
19from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32OF THE POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#ifndef MemTrack_H_
36#define MemTrack_H_
37
38#include <typeinfo>
39#include <cstring>
[2212]40#include <fstream>
[401]41
42namespace MemTrack
43{
44    /* ---------------------------------------- class MemStamp */
45
46    class MemStamp
47    {
48        public:        // member variables
49            char const * const filename;
50            int const lineNum;
51        public:        // construction/destruction
52            MemStamp(char const *filename, int lineNum)
53                : filename(filename), lineNum(lineNum) { }
54            ~MemStamp() { }
55    };
56
57    /* ---------------------------------------- memory allocation and stamping prototypes */
58
59    void *TrackMalloc(size_t size);
60    void TrackFree(void *p);
61    void TrackStamp(void *p, const MemStamp &stamp, char const *typeName);
[2212]62    void TrackDumpBlocks(std::ofstream& memReport, size_t memtrack_blocks, size_t memtrack_size);
[401]63    void TrackListMemoryUsage();
[1158]64    size_t getCurrentMemorySize(void) ;
65    size_t getMaxMemorySize(void) ;
[401]66    /* ---------------------------------------- operator * (MemStamp, ptr) */
67
68    template <class T> inline T *operator*(const MemStamp &stamp, T *p)
69    {
70        TrackStamp(p, stamp, typeid(T).name());
71        return p;
72    }
73
74}    // namespace MemTrack
75
76/* ---------------------------------------- new macro */
77
78#define MEMTRACK_NEW MemTrack::MemStamp(__FILE__, __LINE__) * new
79#define new MEMTRACK_NEW
80
81#endif    // MemTrack_H_
82
83#endif
Note: See TracBrowser for help on using the repository browser.