Skip to content

Commit 1be19d8

Browse files
committed
Fix compilation on windows
Windows has no getrusage(), so use GetProcessMemoryInfo() on Windows instead.
1 parent df662cc commit 1be19d8

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

Makefile.am

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ fptree_SOURCES = \
1010
src/parser.hh \
1111
src/parser.cc \
1212
src/fptree.hh \
13-
src/fptree.cc
13+
src/fptree.cc \
14+
src/meminfo.hh \
15+
src/meminfo.cc
1416

1517
fptree_CXXFLAGS = -std=c++0x
1618
fptree_CPPFLAGS = -I$(top_srcdir)/src
19+
if WINDOWS
20+
fptree_LDADD = -lpsapi
21+
endif

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
AC_INIT([fptree], [0.1], [[email protected]])
55
AC_CONFIG_SRCDIR([src/transactions.hh])
6+
AC_CANONICAL_HOST
67

78
AM_INIT_AUTOMAKE([foreign dist-zip])
89

@@ -12,5 +13,12 @@ AC_PROG_CXX
1213

1314
AC_TYPE_SIZE_T
1415

16+
case $host_os in
17+
*mingw32*|*cygwin*)
18+
is_windows=yes;
19+
esac
20+
21+
AM_CONDITIONAL([WINDOWS], [test "$is_windows" = "yes"])
22+
1523
AC_CONFIG_FILES([Makefile])
1624
AC_OUTPUT

src/main.cc

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#include <iostream>
44
#include <fstream>
55
#include <chrono>
6-
#include <sys/time.h>
7-
#include <sys/resource.h>
86

97
#include <itemset.hh>
108
#include <transactions.hh>
119
#include <types.hh>
1210
#include <parser.hh>
1311
#include <fptree.hh>
12+
#include <meminfo.hh>
1413

1514
int main (int argc, char **argv)
1615
{
@@ -39,20 +38,17 @@ int main (int argc, char **argv)
3938

4039
std::string dump_filename = filename + ".fptree";
4140

42-
rusage res_usage;
43-
getrusage (RUSAGE_SELF, &res_usage);
44-
45-
std::cout << "File: " << filename << std::endl
46-
<< "FPtree dump file: " << dump_filename << std::endl
47-
<< "Threshold: " << min_support << std::endl
48-
<< "Number of nodes: " << stats.size << std::endl
49-
<< "Number of leaves: " << stats.n_leaves << std::endl
50-
<< "Height: " << stats.height << std::endl
51-
<< "Minimum fanout: " << stats.min_fanout << std::endl
52-
<< "Average fanout: " << stats.average_fanout << std::endl
53-
<< "Maximum fanout: " << stats.max_fanout << std::endl
54-
<< "Runtime: " << duration << "s" << std::endl
55-
<< "Max. memory: " << res_usage.ru_maxrss << "kB"
41+
std::cout << "File: " << filename << std::endl
42+
<< "FPtree dump file: " << dump_filename << std::endl
43+
<< "Threshold: " << min_support << std::endl
44+
<< "Number of nodes: " << stats.size << std::endl
45+
<< "Number of leaves: " << stats.n_leaves << std::endl
46+
<< "Height: " << stats.height << std::endl
47+
<< "Minimum fanout: " << stats.min_fanout << std::endl
48+
<< "Average fanout: " << stats.average_fanout << std::endl
49+
<< "Maximum fanout: " << stats.max_fanout << std::endl
50+
<< "Runtime: " << duration << "s" << std::endl
51+
<< "Max. memory: " << fpt::get_peakmem_kb () << "kB"
5652
<< std::endl;
5753

5854
{

src/meminfo.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <meminfo.hh>
2+
3+
#ifdef __WIN32__
4+
# define PSAPI_VERSION 1
5+
# include <windows.h>
6+
# include <psapi.h>
7+
8+
long fpt::get_peakmem_kb ()
9+
{
10+
PROCESS_MEMORY_COUNTERS pmc;
11+
12+
GetProcessMemoryInfo (GetCurrentProcess (), &pmc, sizeof (pmc));
13+
14+
return pmc.PeakWorkingSetSize / 1024;
15+
}
16+
17+
#else
18+
# include <sys/time.h>
19+
# include <sys/resource.h>
20+
21+
long fpt::get_peakmem_kb ()
22+
{
23+
rusage res_usage;
24+
getrusage (RUSAGE_SELF, &res_usage);
25+
26+
return res_usage.ru_maxrss;
27+
}
28+
29+
#endif

src/meminfo.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef MEMINFO_HH
2+
#define MEMINFO_HH
3+
4+
namespace fpt
5+
{
6+
long get_peakmem_kb ();
7+
}
8+
9+
#endif // MEMINFO_HH

0 commit comments

Comments
 (0)