Skip to content

Commit cf6130d

Browse files
committed
Enable memory_info on Windows
Updated the output based on Microsoft's documentation and added a unit test (we don't otherwise use this code within CBMC at the moment).
1 parent e6ce264 commit cf6130d

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/util/memory_info.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,15 @@ void memory_info(std::ostream &out)
4545
out << " space available in freed fastbin blocks: " << m.fsmblks << "\n";
4646
out << " total allocated space: " << m.uordblks << "\n";
4747
out << " total free space: " << m.fordblks << "\n";
48-
#endif
49-
50-
#ifdef _WIN32
51-
(void)out; // unused parameter
52-
#if 0
48+
#elif defined(_WIN32)
5349
PROCESS_MEMORY_COUNTERS pmc;
5450
if(GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
5551
{
56-
out << " PeakWorkingSetSize: " << pmc.PeakWorkingSetSize << "\n";
57-
out << " WorkingSetSize: " << pmc.WorkingSetSize << "\n";
52+
out << " peak working set size [bytes]: " << pmc.PeakWorkingSetSize
53+
<< "\n";
54+
out << " current working set size [bytes]: " << pmc.WorkingSetSize << "\n";
5855
}
59-
#endif
60-
#endif
61-
62-
#ifdef __APPLE__
56+
#elif defined(__APPLE__)
6357
// NOLINTNEXTLINE(readability/identifiers)
6458
struct task_basic_info t_info;
6559
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SRC += analyses/ai/ai.cpp \
4949
util/graph.cpp \
5050
util/irep.cpp \
5151
util/irep_sharing.cpp \
52+
util/memory_info.cpp \
5253
util/message.cpp \
5354
util/optional.cpp \
5455
util/optional_utils.cpp \

unit/util/memory_info.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for memory_info.h
4+
5+
Author: Michael Tautschnig
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
11+
#include <util/memory_info.h>
12+
13+
#include <sstream>
14+
15+
TEST_CASE("memory_info returns some output", "[core][util][memory_info]")
16+
{
17+
std::ostringstring oss;
18+
memory_info(oss);
19+
20+
REQUIRE(!oss.str().empty());
21+
}

0 commit comments

Comments
 (0)