Grid 0.7.0
MemoryStats.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/MemoryStats.h
6
7 Copyright (C) 2015
8
9Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
10Author: Peter Boyle <paboyle@ph.ed.ac.uk>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26 See the full license in the file "LICENSE" in the top level distribution directory
27*************************************************************************************/
28/* END LEGAL */
29#pragma once
30
31
33
34std::string sizeString(size_t bytes);
35
41
43{
44public:
46 static bool debug;
47};
48
49#define memString(bytes) std::to_string(bytes) + " (" + sizeString(bytes) + ")"
50#define profilerDebugPrint \
51 if (MemoryProfiler::stats) \
52 { \
53 auto s = MemoryProfiler::stats; \
54 std::cout << GridLogDebug << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl; \
55 std::cout << GridLogDebug << "[Memory debug] total : " << memString(s->totalAllocated) \
56 << std::endl; \
57 std::cout << GridLogDebug << "[Memory debug] max : " << memString(s->maxAllocated) \
58 << std::endl; \
59 std::cout << GridLogDebug << "[Memory debug] current: " << memString(s->currentlyAllocated) \
60 << std::endl; \
61 std::cout << GridLogDebug << "[Memory debug] freed : " << memString(s->totalFreed) \
62 << std::endl; \
63 }
64
65#define profilerAllocate(bytes) \
66 if (MemoryProfiler::stats) \
67 { \
68 auto s = MemoryProfiler::stats; \
69 s->totalAllocated += (bytes); \
70 s->currentlyAllocated += (bytes); \
71 s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); \
72 } \
73 if (MemoryProfiler::debug) \
74 { \
75 std::cout << GridLogDebug << "[Memory debug] allocating " << memString(bytes) << std::endl; \
76 profilerDebugPrint; \
77 }
78
79#define profilerFree(bytes) \
80 if (MemoryProfiler::stats) \
81 { \
82 auto s = MemoryProfiler::stats; \
83 s->totalFreed += (bytes); \
84 s->currentlyAllocated -= (bytes); \
85 } \
86 if (MemoryProfiler::debug) \
87 { \
88 std::cout << GridLogDebug << "[Memory debug] freeing " << memString(bytes) << std::endl; \
89 profilerDebugPrint; \
90 }
91
92void check_huge_pages(void *Buf,uint64_t BYTES);
93
95
void check_huge_pages(void *Buf, uint64_t BYTES)
Definition MemoryStats.cc:9
std::string sizeString(size_t bytes)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static MemoryStats * stats
Definition MemoryStats.h:45
static bool debug
Definition MemoryStats.h:46
size_t totalAllocated
Definition MemoryStats.h:38
size_t totalFreed
Definition MemoryStats.h:39
size_t currentlyAllocated
Definition MemoryStats.h:39
size_t maxAllocated
Definition MemoryStats.h:38