Added support for compiling and running on Mac OS X.
Excludes support for setting the scheduler and malloc options which are put behind macros for Mac.
Tested on
* Mac OS X 10.9.2 x86_64
* Ubuntu 12.04 x86_64
Signed-off-by: Phil Preston <philippreston@...>
---
.../src/testtools/performance/c/mamaconsumerc_v2.c | 27 +++++++++++++
.../src/testtools/performance/c/mamaproducerc_v2.c | 45 +++++++++++++++++-----
2 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/mama/c_cpp/src/testtools/performance/c/mamaconsumerc_v2.c b/mama/c_cpp/src/testtools/performance/c/mamaconsumerc_v2.c
index a322fd4..2e33000 100644
--- a/mama/c_cpp/src/testtools/performance/c/mamaconsumerc_v2.c
+++ b/mama/c_cpp/src/testtools/performance/c/mamaconsumerc_v2.c
@@ -29,7 +29,12 @@
#include <signal.h>
#include <math.h>
#include <sys/mman.h> /* Needed for mlockall() */
+#ifndef __APPLE__
#include <malloc.h>
+#else
+#include <malloc/malloc.h>
+#include <sys/sysctl.h>
+#endif
#include <limits.h>
#include <sys/time.h> /* needed for getrusage */
#include <sys/resource.h> /* needed for getrusage */
@@ -83,6 +88,8 @@
#define SEQ_NUM_FID 10
+#define HZ_TO_MHZ 1000000
+
typedef struct {
char* mTopic;
const char* mSource;
@@ -701,6 +708,7 @@ static int gSched = 0;
static int gLock = 0;
static int gPriority = 40;
+#ifndef __APPLE__
static void setprio(int prio, int sched)
{
struct sched_param param;
@@ -718,6 +726,7 @@ static void configure_malloc_behavior(void)
mallopt(M_MMAP_MAX, 0);
}
+#endif
static void
show_new_pagefault_count(const char* logtext,
@@ -898,12 +907,14 @@ int main (int argc, const char** argv)
gUsecStatInterval = (uint64_t)(1.0 * 1000000);
}
+#ifndef __APPLE__
/*
* Real time priorities
*/
if (gLock)
{
configure_malloc_behavior();
+
reserve_process_memory(PRE_ALLOCATION_SIZE);
}
@@ -930,6 +941,7 @@ int main (int argc, const char** argv)
}
setprio(gPriority,gSched);
}
+#endif
if (gStatsFile || gCollectStats || gDataStats || gIntervalStats || gCountInitials || gSD || gCB)
{
@@ -3306,6 +3318,20 @@ static void signalCatcher
static double getClock(void)
{
+
+#ifdef __APPLE__
+ int mib[2];
+ unsigned int freq;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_CPU_FREQ;
+ len = sizeof(freq);
+ if(0 == sysctl(mib, 2, &freq, &len, NULL, 0))
+ {
+ return (double)(freq / HZ_TO_MHZ);
+ }
+#else
FILE *cpuInfo;
if ((cpuInfo = fopen ("/proc/cpuinfo", "rb"))!=NULL)
{
@@ -3326,6 +3352,7 @@ static double getClock(void)
fclose(cpuInfo);
return atof (freq);
}
+#endif
PRINT_ERROR("Could not get CPU Frequency");
exit (1);
}
diff --git a/mama/c_cpp/src/testtools/performance/c/mamaproducerc_v2.c b/mama/c_cpp/src/testtools/performance/c/mamaproducerc_v2.c
index 8839500..3ceb244 100644
--- a/mama/c_cpp/src/testtools/performance/c/mamaproducerc_v2.c
+++ b/mama/c_cpp/src/testtools/performance/c/mamaproducerc_v2.c
@@ -26,7 +26,12 @@
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h> /* Needed for mlockall() */
+#ifndef __APPLE__
#include <malloc.h>
+#else
+#include <malloc/malloc.h>
+#include <sys/sysctl.h>
+#endif
#include <limits.h>
#include <sys/time.h> /* needed for getrusage */
#include <sys/resource.h> /* needed for getrusage */
@@ -91,6 +96,8 @@
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_HIGHRES
#endif
+#define HZ_TO_MHZ 1000000
+
typedef struct {
uint32_t mMsgNum;
mamaPublisher mMamaPublisher;
@@ -443,6 +450,7 @@ static int gSched = 0;
static int gLock = 0;
static int gPriority = 40;
+#ifndef __APPLE__
static void setprio(int prio, int sched)
{
struct sched_param param;
@@ -451,6 +459,17 @@ static void setprio(int prio, int sched)
perror("sched_setscheduler");
}
+static void configure_malloc_behavior(void)
+{
+ if (mlockall(MCL_CURRENT | MCL_FUTURE))
+ perror("mlockall failed:");
+
+ mallopt(M_TRIM_THRESHOLD, -1);
+
+ mallopt(M_MMAP_MAX, 0);
+}
+#endif
+
static void
show_new_pagefault_count(const char* logtext,
const char* allowed_maj,
@@ -470,16 +489,6 @@ show_new_pagefault_count(const char* logtext,
last_minflt = usage.ru_minflt;
}
-static void configure_malloc_behavior(void)
-{
- if (mlockall(MCL_CURRENT | MCL_FUTURE))
- perror("mlockall failed:");
-
- mallopt(M_TRIM_THRESHOLD, -1);
-
- mallopt(M_MMAP_MAX, 0);
-}
-
static void reserve_process_memory(int size)
{
int i;
@@ -587,6 +596,7 @@ int main (int argc, const char **argv)
&msgSize,
&msgVar);
+#ifndef __APPLE__
/*
* Real time priorities
*/
@@ -617,6 +627,7 @@ int main (int argc, const char **argv)
}
setprio(gPriority,gSched);
}
+#endif
initializeMama (middleware,
transportName);
@@ -1082,6 +1093,19 @@ static void producerShutdown
static double getClock()
{
+#ifdef __APPLE__
+ int mib[2];
+ unsigned int freq;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_CPU_FREQ;
+ len = sizeof(freq);
+ if(0 == sysctl(mib, 2, &freq, &len, NULL, 0))
+ {
+ return (double)(freq / HZ_TO_MHZ);
+ }
+#else
FILE *cpuInfo;
if ((cpuInfo = fopen ("/proc/cpuinfo", "rb"))!=NULL)
{
@@ -1102,6 +1126,7 @@ static double getClock()
fclose(cpuInfo);
return atof (freq);
}
+#endif
PRINT_ERROR("Could not get CPU Frequency");
exit (1);
}
--
1.8.5.2 (Apple Git-48)