The Pedigree Project  0.1
memlog.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _MEMLOG_H
21 #define _MEMLOG_H
22 
23 #ifdef MEMORY_LOGGING_ENABLED
24 
25 #ifndef _MACHINE_H
26 #define MACHINE_FORWARD_DECL_ONLY
27 #include "pedigree/kernel/machine/Machine.h"
28 #include "pedigree/kernel/machine/Serial.h"
29 #endif
30 
31 #define DUMP_MEM_INFO \
32  do \
33  { \
34  extern size_t g_FreePages; \
35  extern size_t g_AllocedPages; \
36  Serial *pSerial = Machine::instance().getSerial(1); \
37  NormalStaticString str; \
38  str += "Heap: "; \
39  str += (reinterpret_cast<uintptr_t>( \
40  VirtualAddressSpace::getKernelAddressSpace().m_HeapEnd) - \
41  0xC0000000) / \
42  1024; \
43  str += "K\tPages: "; \
44  str += (g_AllocedPages * 4096) / 1024; \
45  str += "K\t Free: "; \
46  str += (g_FreePages * 4096) / 1024; \
47  str += "K\n"; \
48  pSerial->write(str); \
49  } while (0)
50 
51 #else
52 
53 #define DUMP_MEM_INFO
54 
55 #endif
56 
57 #endif