Revision: 1011
Author: tim.bunce
Date: Wed Jan 6 13:44:43 2010
Log: Added high-resolution (100ns) timer for Mac OS X thanks to Markus
Peter.
http://code.google.com/p/perl-devel-nytprof/source/detail?r=1011
Modified:
/trunk/Changes
/trunk/Makefile.PL
/trunk/NYTProf.xs
=======================================
--- /trunk/Changes Tue Jan 5 10:08:20 2010
+++ /trunk/Changes Wed Jan 6 13:44:43 2010
@@ -15,6 +15,9 @@
=head2 Changes in Devel::NYTProf 3.02
+ Added high-resolution (100ns) timer for Mac OS X
+ thanks to Markus Peter.
+
Changed subroutine profiler to be slightly more efficient.
Changed some tests to be more informative on failure.
=======================================
--- /trunk/Makefile.PL Sun Dec 20 12:22:26 2009
+++ /trunk/Makefile.PL Wed Jan 6 13:44:43 2010
@@ -67,7 +67,7 @@
my @h_dirs;
push @h_dirs, split /:/, $ENV{INCLUDE} if $ENV{INCLUDE};
push @h_dirs, split ' ', $Config{libsdirs};
-push @h_dirs, qw(/include /usr/include /usr/local/include);
+push @h_dirs, qw(/include /usr/include /usr/local/include
/usr/include/mach);
@h_dirs = grep { -d $_ } @h_dirs;
$h_files = find_h_files(@h_dirs);
@@ -82,11 +82,17 @@
) {
my ($header, $regexp, $define, $libs) = @$_;
if (my $result = search_h_file($header, $regexp)) {
- print "Found $result in $header\n";
- push @libs, $libs;
- $mm_opts{DEFINE} .= " $define";
+ print "Found $result in $header\n";
+ push @libs, $libs;
+ $mm_opts{DEFINE} .= " $define";
}
}
+
+if( $^O eq 'darwin' and search_h_file('mach_time.h',
qr/(mach_absolute_time)\s*\(/)) {
+ print "Found mach_absolute_time in mach/mach_time.h.h\n";
+ $mm_opts{DEFINE} .= " -DHAS_MACH_TIME";
+}
+
if ($opt_assert or (not defined $opt_assert and $is_developer)) {
warn "Assertion testing enabled\n";
$mm_opts{DEFINE} .= " -DUSE_HARD_ASSERT";
=======================================
--- /trunk/NYTProf.xs Tue Jan 5 10:08:20 2010
+++ /trunk/NYTProf.xs Wed Jan 6 13:44:43 2010
@@ -267,6 +267,7 @@
/* time tracking */
static struct tms start_ctime, end_ctime;
+
#ifdef HAS_CLOCK_GETTIME
/* http://www.freebsd.org/cgi/man.cgi?query=clock_gettime
* http://webnews.giga.net.tw/article//mailing.freebsd.performance/710
@@ -285,6 +286,24 @@
#else /* !HAS_CLOCK_GETTIME */
+#ifdef HAS_MACH_TIME
+
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
+mach_timebase_info_data_t our_timebase;
+typedef uint64_t time_of_day_t;
+
+# define CLOCKS_PER_TICK 10000000 /* 10 million - 100ns */
+# define get_time_of_day(into) if(!profile_zero) into =
mach_absolute_time()
+# define get_ticks_between(s, e, ticks, overflow) STMT_START { \
+ overflow = 0; \
+ if( our_timebase.denom == 0 ) mach_timebase_info(&our_timebase); \
+ ticks = (e-s) * our_timebase.numer / our_timebase.denom / 100; \
+} STMT_END
+
+#else /* !HAS_MACH_TIME */
+
#ifdef HAS_GETTIMEOFDAY
typedef struct timeval time_of_day_t;
# define CLOCKS_PER_TICK 1000000 /* 1 million */
@@ -304,6 +323,8 @@
} STMT_END
#endif
#endif
+#endif
+
static time_of_day_t start_time;
static time_of_day_t end_time;
--
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.
Group hosted at: http://groups.google.com/group/develnytprof-dev
Project hosted at: http://perl-devel-nytprof.googlecode.com
CPAN distribution: http://search.cpan.org/dist/Devel-NYTProf
To post, email: [email protected]
To unsubscribe, email: [email protected]