Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
Windows support #34
  • Loading branch information
longxinH committed Dec 16, 2019
1 parent c6d439b commit ba1e1b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
24 changes: 10 additions & 14 deletions extension/php_xhprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern zend_module_entry xhprof_module_entry;
*/

/* XHProf version */
#define XHPROF_VERSION "2.1.3"
#define XHPROF_VERSION "2.1.4"

/* Fictitious function name to represent top of the call tree. The paranthesis
* in the name is to ensure we don't conflict with user function names. */
Expand Down Expand Up @@ -72,10 +72,6 @@ extern zend_module_entry xhprof_module_entry;
#define XHPROF_IGNORED_FUNCTION_FILTER_SIZE \
((XHPROF_MAX_IGNORED_FUNCTIONS + 7)/8)

#if !defined(uint64)
typedef unsigned long long uint64;
#endif

#if !defined(uint32)
typedef unsigned int uint32;
#endif
Expand Down Expand Up @@ -154,8 +150,8 @@ do { \
typedef struct hp_entry_t {
char *name_hprof; /* function name */
int rlvl_hprof; /* recursion level for function */
uint64 tsc_start; /* start value for TSC counter */
uint64 cpu_start;
zend_ulong tsc_start; /* start value for TSC counter */
zend_ulong cpu_start;
long int mu_start_hprof; /* memory usage */
long int pmu_start_hprof; /* peak memory usage */
struct hp_entry_t *prev_hprof; /* ptr to prev entry being profiled */
Expand Down Expand Up @@ -203,17 +199,17 @@ ZEND_DLEXPORT zend_op_array* hp_compile_string(zval *source_string, char *filena
*/
static void hp_register_constants(INIT_FUNC_ARGS);

static void hp_begin(long level, long xhprof_flags);
static void hp_begin(zend_long level, zend_long xhprof_flags);
static void hp_stop();
static void hp_end();

static inline uint64 cycle_timer();
static inline zend_ulong cycle_timer();

static void hp_free_the_free_list();
static hp_entry_t *hp_fast_alloc_hprof_entry();
static void hp_fast_free_hprof_entry(hp_entry_t *p);
static inline uint8 hp_inline_hash(char *str);
static void incr_us_interval(struct timeval *start, uint64 incr);
static void incr_us_interval(struct timeval *start, zend_ulong incr);

static void hp_get_ignored_functions_from_arg(zval *args);

Expand Down Expand Up @@ -270,11 +266,11 @@ ZEND_BEGIN_MODULE_GLOBALS(xhprof)

/* Global to track the time of the last sample in time and ticks */
struct timeval last_sample_time;
uint64 last_sample_tsc;
zend_ulong last_sample_tsc;
/* XHPROF_SAMPLING_INTERVAL in ticks */
long sampling_interval;
uint64 sampling_interval_tsc;
long sampling_depth;
zend_long sampling_interval;
zend_ulong sampling_interval_tsc;
zend_long sampling_depth;
/* XHProf flags */
uint32 xhprof_flags;

Expand Down
20 changes: 10 additions & 10 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ PHP_INI_END()
*/
PHP_FUNCTION(xhprof_enable)
{
long xhprof_flags = 0; /* XHProf flags */
zend_long xhprof_flags = 0; /* XHProf flags */
zval *optional_array = NULL; /* optional array arg: for future use */

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lz", &xhprof_flags, &optional_array) == FAILURE) {
Expand Down Expand Up @@ -195,7 +195,7 @@ PHP_FUNCTION(xhprof_disable)
*/
PHP_FUNCTION(xhprof_sample_enable)
{
long xhprof_flags = 0; /* XHProf flags */
zend_long xhprof_flags = 0; /* XHProf flags */
hp_get_ignored_functions_from_arg(NULL);
hp_begin(XHPROF_MODE_SAMPLED, xhprof_flags);
}
Expand Down Expand Up @@ -754,7 +754,7 @@ static void hp_fast_free_hprof_entry(hp_entry_t *p)
* @return void
* @author kannan
*/
void hp_inc_count(zval *counts, char *name, long count)
void hp_inc_count(zval *counts, char *name, zend_long count)
{
HashTable *ht;
zval *data, val;
Expand Down Expand Up @@ -789,9 +789,9 @@ void hp_inc_count(zval *counts, char *name, long count)
* @return void
* @author veeve
*/
void hp_trunc_time(struct timeval *tv, uint64 intr)
void hp_trunc_time(struct timeval *tv, zend_ulong intr)
{
uint64 time_in_micro;
zend_ulong time_in_micro;

/* Convert to microsecs and trunc that first */
time_in_micro = (tv->tv_sec * 1000000) + tv->tv_usec;
Expand All @@ -817,7 +817,7 @@ void hp_sample_stack(hp_entry_t **entries)
char symbol[SCRATCH_BUF_LEN * 1000];

/* Build key */
snprintf(key, sizeof(key), "%d.%06d", XHPROF_G(last_sample_time).tv_sec, XHPROF_G(last_sample_time).tv_usec);
snprintf(key, sizeof(key), "%d.%06d", (uint32) XHPROF_G(last_sample_time).tv_sec, (uint32) XHPROF_G(last_sample_time).tv_usec);

/* Init stats in the global stats_count hashtable */
hp_get_function_stack(*entries, XHPROF_G(sampling_depth), symbol, sizeof(symbol));
Expand Down Expand Up @@ -863,7 +863,7 @@ void hp_sample_check(hp_entry_t **entries)
* ***********************
*/

static inline uint64 cycle_timer()
static inline zend_ulong cycle_timer()
{
#if defined(__APPLE__) && defined(__MACH__)
return mach_absolute_time() / XHPROF_G(timebase_conversion);
Expand All @@ -884,7 +884,7 @@ static inline uint64 cycle_timer()
/**
* Get the current real CPU clock timer
*/
static uint64 cpu_timer()
static zend_ulong cpu_timer()
{
#if defined(CLOCK_PROCESS_CPUTIME_ID)
struct timespec s;
Expand All @@ -902,7 +902,7 @@ static uint64 cpu_timer()
/**
* Incr time with the given microseconds.
*/
static void incr_us_interval(struct timeval *start, uint64 incr)
static void incr_us_interval(struct timeval *start, zend_ulong incr)
{
incr += (start->tv_sec * 1000000 + start->tv_usec);
start->tv_sec = incr / 1000000;
Expand Down Expand Up @@ -1266,7 +1266,7 @@ ZEND_DLEXPORT zend_op_array* hp_compile_string(zval *source_string, char *filena
* It replaces all the functions like zend_execute, zend_execute_internal,
* etc that needs to be instrumented with their corresponding proxies.
*/
static void hp_begin(long level, long xhprof_flags)
static void hp_begin(zend_long level, zend_long xhprof_flags)
{
if (!XHPROF_G(enabled)) {
int hp_profile_flag = 1;
Expand Down
24 changes: 19 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2019-12-10</date>
<time>11:06:00</time>
<date>2019-12-17</date>
<time>01:06:00</time>
<version>
<release>2.1.3</release>
<api>2.1.3</api>
<release>2.1.4</release>
<api>2.1.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0</license>
<notes>
- Fix s390x accuracy loss #15
- Windows support #34
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -113,6 +113,20 @@
<providesextension>xhprof</providesextension>
<extsrcrelease />
<changelog>
<release>
<date>2019-12-17</date>
<version>
<release>2.1.4</release>
<api>2.1.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<notes>
- Windows support #34
</notes>
</release>
<release>
<date>2019-12-10</date>
<version>
Expand Down

0 comments on commit ba1e1b9

Please sign in to comment.