Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

request #16544: mac port for XHProf (Svilen Spasov)

git-svn-id: https://svn.php.net/repository/pecl/xhprof/trunk@281444 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit b7b4ad7d1b72803fa8235e988d6cbf93d80ed59d 1 parent 13b4dfa
kannan authored
Showing with 36 additions and 7 deletions.
  1. +25 −6 extension/xhprof.c
  2. +1 −0  package.xml
  3. +10 −1 xhprof_html/docs/index.html
View
31 extension/xhprof.c
@@ -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__ */
@@ -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;
View
1  package.xml
@@ -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)
View
11 xhprof_html/docs/index.html
@@ -261,7 +261,10 @@
<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
@@ -270,6 +273,12 @@
<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
Please sign in to comment.
Something went wrong with that request. Please try again.