source: XIOS/trunk/src/memtrack.hpp @ 1137

Last change on this file since 1137 was 1137, checked in by ymipsl, 5 years ago

Add "light" memory tracking which must be activated at compile time : make_xios --memtrack light

  • report at info level 10 : max memory consumption and the current memory consumption at the end of exection
  • info at info level 50 : at each timestep, the current memory consumption is printed

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.8 KB
Line 
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>
40
41namespace MemTrack
42{
43    /* ---------------------------------------- class MemStamp */
44
45    class MemStamp
46    {
47        public:        // member variables
48            char const * const filename;
49            int const lineNum;
50        public:        // construction/destruction
51            MemStamp(char const *filename, int lineNum)
52                : filename(filename), lineNum(lineNum) { }
53            ~MemStamp() { }
54    };
55
56    /* ---------------------------------------- memory allocation and stamping prototypes */
57
58    void *TrackMalloc(size_t size);
59    void TrackFree(void *p);
60    void TrackStamp(void *p, const MemStamp &stamp, char const *typeName);
61    void TrackDumpBlocks();
62    void TrackListMemoryUsage();
63    size_t getCurrentMemorySize(void) ;
64    size_t getMaxMemorySize(void) ;
65    /* ---------------------------------------- operator * (MemStamp, ptr) */
66
67    template <class T> inline T *operator*(const MemStamp &stamp, T *p)
68    {
69        TrackStamp(p, stamp, typeid(T).name());
70        return p;
71    }
72
73}    // namespace MemTrack
74
75/* ---------------------------------------- new macro */
76
77#define MEMTRACK_NEW MemTrack::MemStamp(__FILE__, __LINE__) * new
78#define new MEMTRACK_NEW
79
80#endif    // MemTrack_H_
81
82#endif
Note: See TracBrowser for help on using the repository browser.