/* Profiler implementation.
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2012-2013 Free Software Foundation, Inc.
This file is part of GNU Emacs.
/* The profiler timer and whether it was properly initialized, if
POSIX timers are available. */
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
static timer_t profiler_timer;
static bool profiler_timer_ok;
#endif
else
{
Lisp_Object oquit;
+ bool saved_pending_signals;
EMACS_INT count = 1;
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
if (profiler_timer_ok)
{
int overruns = timer_getoverrun (profiler_timer);
uses QUIT, which can call malloc, which can cause disaster in
a signal handler. So inhibit QUIT. */
oquit = Vinhibit_quit;
+ saved_pending_signals = pending_signals;
Vinhibit_quit = Qt;
+ pending_signals = 0;
eassert (HASH_TABLE_P (cpu_log));
record_backtrace (XHASH_TABLE (cpu_log), count);
Vinhibit_quit = oquit;
+ pending_signals = saved_pending_signals;
}
}
emacs_sigaction_init (&action, deliver_profiler_signal);
sigaction (SIGPROF, &action, 0);
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
if (! profiler_timer_ok)
{
/* System clocks to try, in decreasing order of desirability. */
{
struct itimerspec ispec;
ispec.it_value = ispec.it_interval = interval;
- timer_settime (profiler_timer, 0, &ispec, 0);
- return TIMER_SETTIME_RUNNING;
+ if (timer_settime (profiler_timer, 0, &ispec, 0) == 0)
+ return TIMER_SETTIME_RUNNING;
}
#endif
+#ifdef HAVE_SETITIMER
timer.it_value = timer.it_interval = make_timeval (interval);
- setitimer (ITIMER_PROF, &timer, 0);
- return SETITIMER_RUNNING;
+ if (setitimer (ITIMER_PROF, &timer, 0) == 0)
+ return SETITIMER_RUNNING;
+#endif
+
+ return NOT_RUNNING;
}
DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start,
case NOT_RUNNING:
return Qnil;
-#ifdef HAVE_TIMER_SETTIME
+#ifdef HAVE_ITIMERSPEC
case TIMER_SETTIME_RUNNING:
{
struct itimerspec disable;
break;
#endif
+#ifdef HAVE_SETITIMER
case SETITIMER_RUNNING:
{
struct itimerval disable;
setitimer (ITIMER_PROF, &disable, 0);
}
break;
+#endif
}
signal (SIGPROF, SIG_IGN);