Skip to content

Commit

Permalink
request #16544: mac port for XHProf (Svilen Spasov)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.php.net/repository/pecl/xhprof/trunk@281444 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
kannan committed May 30, 2009
1 parent 13b4dfa commit b7b4ad7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
31 changes: 25 additions & 6 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,33 @@
# include <sys/resource.h>
# include <sys/cpuset.h>
# define cpu_set_t cpuset_t
# define SET_AFFINITY(pid, size, mask) \
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask)
# define GET_AFFINITY(pid, size, mask) \
cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask)
# define SET_AFFINITY(pid, size, mask) \
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask)
# define GET_AFFINITY(pid, size, mask) \
cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask)
# else
# error "This version of FreeBSD does not support cpusets"
# endif /* __FreeBSD_version */
#elif __APPLE__
/*
* Patch for compiling in Mac OS X Leopard
* @author Svilen Spasov <s.spasov@gmail.com>
*/
# include <mach/mach_init.h>
# include <mach/thread_policy.h>
# define cpu_set_t thread_affinity_policy_data_t
# define CPU_SET(cpu_id, new_mask) \
(*(new_mask)).affinity_tag = (cpu_id + 1)
# define CPU_ZERO(new_mask) \
(*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL
# define SET_AFFINITY(pid, size, mask) \
thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, mask, \
THREAD_AFFINITY_POLICY_COUNT)
#else
/* For sched_getaffinity, sched_setaffinity */
# include <sched.h>
# define SET_AFFINITY(pid, size, mask) sched_setaffinity(0, size, mask)
# define GET_AFFINITY(pid, size, mask) sched_getaffinity(0, size, mask)
# define SET_AFFINITY(pid, size, mask) sched_setaffinity(0, size, mask)
# define GET_AFFINITY(pid, size, mask) sched_getaffinity(0, size, mask)
#endif /* __FreeBSD__ */


Expand Down Expand Up @@ -400,10 +415,14 @@ PHP_MINIT_FUNCTION(xhprof) {
hp_globals.cpu_num = sysconf(_SC_NPROCESSORS_CONF);

/* Get the cpu affinity mask. */
#ifndef __APPLE__
if (GET_AFFINITY(0, sizeof(cpu_set_t), &hp_globals.prev_mask) < 0) {
perror("getaffinity");
return FAILURE;
}
#else
CPU_ZERO(&(hp_globals.prev_mask));
#endif

/* Initialize cpu_frequencies and cur_cpu_id. */
hp_globals.cpu_frequencies = NULL;
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ XHProf is a function-level hierarchical profiler for PHP and has a simple HTML b
</stability>
<license uri="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0</license>
<notes>
-- Request #16544: Mac port for XHProf (svilen spasov)
-- fix #16574: require/require_once not special cased like include/include_once (kannan)
-- add a sanity test for sampling mode in xhprof (kannan)
-- add support to ignore functions (such as call_user_func) during profiling (mike paleczny)
Expand Down
11 changes: 10 additions & 1 deletion xhprof_html/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ <h3>XHProf Documentation (Draft)</h3>
<ul><hr>

<p><b>Note:</b> A windows port hasn't been implemented yet. We have
tested <code>xhprof</code> on Linux/FreeBSD so far.
tested <code>xhprof</code> on <b>Linux/FreeBSD</b> so far.

<p>Version 0.9.2 and above of XHProf is also expected to work on <b>Mac
OS</b>. [We have tested on Mac OS 10.5.]

<p><b>Note:</b> XHProf uses the RDTSC instruction (time stamp counter)
to implement a really low overhead timer for elapsed time. So at the
Expand All @@ -270,6 +273,12 @@ <h3>XHProf Documentation (Draft)</h3>
<code>xhprof</code> binds the program to a single CPU during the
profiling period.

<p>XHProf's RDTSC based timer functionality doesn't work correctly if
<b>SpeedStep</b> technology is turned on. This technology is available on
some Intel processors. [Note: Mac desktops and laptops typically have
SpeedStep turned on by default. To use XHProf, you'll need to disable
SpeedStep.]

<hr></ul>

<p> The steps
Expand Down

0 comments on commit b7b4ad7

Please sign in to comment.