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#include <config.h>
23
24#if MEMORY_LOGGING_ENABLED
25
26#include "pedigree/kernel/TargetInfo.h"
27
28#ifndef _MACHINE_H
29#define MACHINE_FORWARD_DECL_ONLY
30#include "pedigree/kernel/machine/Machine.h"
31#include "pedigree/kernel/machine/Serial.h"
32#endif
33
34#define DUMP_MEM_INFO \
35 do { \
36 extern size_t g_FreePages; \
37 extern size_t g_AllocedPages; \
38 Serial* pSerial = Machine::instance().getSerial(1); \
39 NormalStaticString str; \
40 str += "Heap: "; \
41 str += (reinterpret_cast<uintptr_t>(VirtualAddressSpace::getKernelAddressSpace().m_HeapEnd) - \
42 0xC0000000) / \
43 1024; \
44 str += "K\tPages: "; \
45 str += (g_AllocedPages * TargetInfo::getPageSize()) / 1024; \
46 str += "K\t Free: "; \
47 str += (g_FreePages * TargetInfo::getPageSize()) / 1024; \
48 str += "K\n"; \
49 pSerial->write(str); \
50 } while (0)
51
52#else
53
54#define DUMP_MEM_INFO
55
56#endif
57
58#endif