Skip to content

Commit

Permalink
Merge pull request #13 from orls/basic-osx-support
Browse files Browse the repository at this point in the history
Basic Mac OSX support
  • Loading branch information
NoiseByNorthwest authored Nov 18, 2017
2 parents b6d9ff8 + 80bcf82 commit 945367d
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 7 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ php:
- 7.0
- 7.1
- 7.2
matrix:
include:
# `php: ..` in here is just descriptive/for UI, they don't affect installed ver.
- os: osx
php: "5.6"
language: generic
before_install:
- brew update && brew tap homebrew/php && brew install php56
- os: osx
php: "7.0"
language: generic
before_install:
- brew update && brew tap homebrew/php && brew install php70
- os: osx
php: "7.1"
language: generic
before_install:
- brew update && brew tap homebrew/php && brew install php71
- os: osx
php: "7.2"
language: generic
before_install:
- brew update && brew tap homebrew/php && brew install php72
install:
- phpize
- ./configure
Expand Down
3 changes: 2 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if test "$PHP_SPX" = "yes"; then
src/spx_php.c \
src/spx_stdio.c \
src/spx_config.c \
src/spx_fmt.c,
src/spx_fmt.c \
src/spx_utils.c,
$ext_shared)
fi
6 changes: 3 additions & 3 deletions src/php_spx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "main/php.h"
#include "Zend/zend_extensions.h"

/* linux 2.6+ */
#ifndef linux
# error "Only Linux based OS are supported"
/* linux 2.6+ or OSX */
#if !defined(linux) && !(defined(__APPLE__) && defined(__MACH__))
# error "Only Linux-based OS or Apple MacOS are supported"
#endif

#ifndef __x86_64__
Expand Down
4 changes: 2 additions & 2 deletions src/spx_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct {
typedef struct {
size_t depth;
stack_frame_t frames[STACK_CAPACITY];
} stack_t;
} spx_stack_t;

struct spx_profiler_t {
int finalized;
Expand All @@ -75,7 +75,7 @@ struct spx_profiler_t {
spx_profiler_metric_values_t cum_metric_values;
spx_profiler_metric_values_t max_metric_values;

stack_t stack;
spx_stack_t stack;
func_table_t func_table;
};

Expand Down
1 change: 1 addition & 0 deletions src/spx_reporter_fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "spx_reporter_fp.h"
#include "spx_thread.h"
#include "spx_utils.h"

typedef struct {
spx_profiler_reporter_t base;
Expand Down
42 changes: 42 additions & 0 deletions src/spx_resource_stats-macos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#define _GNU_SOURCE
#include <sys/time.h>
#include <sys/resource.h>

#include "spx_resource_stats.h"
#include "spx_thread.h"

void spx_resource_stats_init(void)
{
}

void spx_resource_stats_shutdown(void)
{
}


size_t spx_resource_stats_wall_time(void)
{
struct timeval tv;
int ret = 0;
ret = gettimeofday(&tv, NULL);
if (ret == 0) {
return tv.tv_sec * 1000 * 1000 + tv.tv_usec;
}
return ret;
}

size_t spx_resource_stats_cpu_time(void)
{
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
return (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec ) * 1000 * 1000 +
(ru.ru_utime.tv_usec + ru.ru_stime.tv_usec);
}

void spx_resource_stats_io(size_t * in, size_t * out)
{
// MacOS doesn't expose any per-process I/O counters equivalent to linux
// procfs.
*in = 0;
*out = 0;
}
2 changes: 2 additions & 0 deletions src/spx_resource_stats.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifdef linux
# include "spx_resource_stats-linux.c"
#elif defined(__APPLE__) && defined(__MACH__)
# include "spx_resource_stats-macos.c"
#else
# error "Your platform is not supported. Please open an issue."
#endif
2 changes: 1 addition & 1 deletion src/spx_stdio.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __unix__
#if !defined(__unix__) && !(defined(__APPLE__) && defined(__MACH__))
# error "Your platform is not supported"
#endif

Expand Down
16 changes: 16 additions & 0 deletions src/spx_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <time.h>
#include <sys/time.h>

#if defined(__APPLE__) && defined(__MACH__) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
int clock_gettime(int clk_id, struct timespec *res)
{
struct timeval tv;
int ret = 0;
ret = gettimeofday(&tv, NULL);
if (ret == 0) {
res->tv_sec = tv.tv_sec;
res->tv_nsec = tv.tv_usec * 1000;
}
return ret;
}
#endif
10 changes: 10 additions & 0 deletions src/spx_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SPX_UTILS_H_DEFINED
#define SPX_UTILS_H_DEFINED

#include <time.h>

#define SPX_UTILS_TOKENIZE_STRING(str, delim, token, size, block) \
do { \
const char * c_ = str; \
Expand All @@ -27,4 +29,12 @@ do { \
} \
} while (0)


#if defined(__APPLE__) && defined(__MACH__) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
#define CLOCK_REALTIME 1
#define CLOCK_REALTIME_COARSE 2
typedef int clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *res);
#endif

#endif /* SPX_UTILS_H_DEFINED */

0 comments on commit 945367d

Please sign in to comment.