Skip to content

Commit e781332

Browse files
authored
Merge pull request phacility#35 from cmb69/cmb/win32
Add basic Windows support
2 parents 22ffa46 + 617885b commit e781332

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

extension/config.w32

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG_ENABLE("xhprof", "xhprof support", "no");
2+
3+
if (PHP_XHPROF == "yes") {
4+
EXTENSION("xhprof", "xhprof.c", null, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
5+
AC_DEFINE("HAVE_PCRE", 1, "have pcre headers");
6+
}

extension/xhprof.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
#include "ext/standard/info.h"
2525
#include "php_xhprof.h"
2626
#include "zend_extensions.h"
27-
#include <sys/time.h>
28-
#include <sys/resource.h>
27+
#ifndef ZEND_WIN32
28+
# include <sys/time.h>
29+
# include <sys/resource.h>
30+
# include <unistd.h>
31+
#else
32+
# include "win32/time.h"
33+
# include "win32/getrusage.h"
34+
# include "win32/unistd.h"
35+
#endif
2936
#include <stdlib.h>
30-
#include <unistd.h>
3137

3238
#if HAVE_PCRE
3339
#include "ext/pcre/php_pcre.h"
@@ -38,6 +44,10 @@
3844
#include <mach/mach_time.h>
3945
#endif
4046

47+
#ifdef ZEND_WIN32
48+
LARGE_INTEGER performance_frequency;
49+
#endif
50+
4151
ZEND_DECLARE_MODULE_GLOBALS(xhprof)
4252

4353
/**
@@ -268,6 +278,10 @@ PHP_MINIT_FUNCTION(xhprof)
268278
/* To make it random number generator repeatable to ease testing. */
269279
srand(0);
270280
#endif
281+
282+
#ifdef ZEND_WIN32
283+
QueryPerformanceFrequency(&performance_frequency);
284+
#endif
271285
return SUCCESS;
272286
}
273287

@@ -853,6 +867,12 @@ static inline uint64 cycle_timer()
853867
{
854868
#if defined(__APPLE__) && defined(__MACH__)
855869
return mach_absolute_time() / XHPROF_G(timebase_conversion);
870+
#elif defined(ZEND_WIN32)
871+
LARGE_INTEGER lt = {0};
872+
QueryPerformanceCounter(&lt);
873+
lt.QuadPart *= 1000000;
874+
lt.QuadPart /= performance_frequency.QuadPart;
875+
return lt.QuadPart;
856876
#else
857877
struct timespec s;
858878
clock_gettime(CLOCK_MONOTONIC, &s);

0 commit comments

Comments
 (0)