[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c59c8db98a1: ; Another fix for profiler.c
From: |
Eli Zaretskii |
Subject: |
master c59c8db98a1: ; Another fix for profiler.c |
Date: |
Fri, 27 Oct 2023 13:47:30 -0400 (EDT) |
branch: master
commit c59c8db98a1d031a20ec7850978653657e394baa
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
; Another fix for profiler.c
* src/profiler.c: Reshuffle functions and declarations to compile
also when PROFILER_CPU_SUPPORT is not defined. (Bug#66774)
---
src/profiler.c | 65 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 34 insertions(+), 31 deletions(-)
diff --git a/src/profiler.c b/src/profiler.c
index 199cf368a55..b494ad783dc 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -55,6 +55,8 @@ struct profiler_log {
EMACS_INT discarded; /* Samples evicted during table overflow. */
};
+static Lisp_Object export_log (struct profiler_log *);
+
static struct profiler_log
make_log (void)
{
@@ -213,6 +215,23 @@ record_backtrace (struct profiler_log *plog, EMACS_INT
count)
/* Sampling profiler. */
+/* Signal handler for sampling profiler. */
+
+static void
+add_sample (struct profiler_log *plog, EMACS_INT count)
+{
+ if (EQ (backtrace_top_function (), QAutomatic_GC)) /* bug#60237 */
+ /* Special case the time-count inside GC because the hash-table
+ code is not prepared to be used while the GC is running.
+ More specifically it uses ASIZE at many places where it does
+ not expect the ARRAY_MARK_FLAG to be set. We could try and
+ harden the hash-table code, but it doesn't seem worth the
+ effort. */
+ plog->gc_count = saturated_add (plog->gc_count, count);
+ else
+ record_backtrace (plog, count);
+}
+
#ifdef PROFILER_CPU_SUPPORT
/* The profiler timer and whether it was properly initialized, if
@@ -238,24 +257,6 @@ static struct profiler_log cpu;
/* The current sampling interval in nanoseconds. */
static EMACS_INT current_sampling_interval;
-/* Signal handler for sampling profiler. */
-
-static void
-add_sample (struct profiler_log *plog, EMACS_INT count)
-{
- if (EQ (backtrace_top_function (), QAutomatic_GC)) /* bug#60237 */
- /* Special case the time-count inside GC because the hash-table
- code is not prepared to be used while the GC is running.
- More specifically it uses ASIZE at many places where it does
- not expect the ARRAY_MARK_FLAG to be set. We could try and
- harden the hash-table code, but it doesn't seem worth the
- effort. */
- plog->gc_count = saturated_add (plog->gc_count, count);
- else
- record_backtrace (plog, count);
-}
-
-
static void
handle_profiler_signal (int signal)
{
@@ -418,6 +419,19 @@ DEFUN ("profiler-cpu-running-p",
return profiler_cpu_running ? Qt : Qnil;
}
+DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log,
+ 0, 0, 0,
+ doc: /* Return the current cpu profiler log.
+The log is a hash-table mapping backtraces to counters which represent
+the amount of time spent at those points. Every backtrace is a vector
+of functions, where the last few elements may be nil.
+Before returning, a new log is allocated for future samples. */)
+ (void)
+{
+ return (export_log (&cpu));
+}
+#endif /* PROFILER_CPU_SUPPORT */
+
static Lisp_Object
export_log (struct profiler_log *log)
{
@@ -430,26 +444,15 @@ export_log (struct profiler_log *log)
Fputhash (CALLN (Fvector, QDiscarded_Samples, Qnil),
make_fixnum (log->discarded),
result);
+#ifdef PROFILER_CPU_SUPPORT
/* Here we're making the log visible to Elisp, so it's not safe any
more for our use afterwards since we can't rely on its special
pre-allocated keys anymore. So we have to allocate a new one. */
if (profiler_cpu_running)
*log = make_log ();
+#endif /* PROFILER_CPU_SUPPORT */
return result;
}
-
-DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log,
- 0, 0, 0,
- doc: /* Return the current cpu profiler log.
-The log is a hash-table mapping backtraces to counters which represent
-the amount of time spent at those points. Every backtrace is a vector
-of functions, where the last few elements may be nil.
-Before returning, a new log is allocated for future samples. */)
- (void)
-{
- return (export_log (&cpu));
-}
-#endif /* PROFILER_CPU_SUPPORT */
/* Memory profiler. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master c59c8db98a1: ; Another fix for profiler.c,
Eli Zaretskii <=