]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/profiler.el (profiler-start): Don't prompt for choice when there old-branches/profiler
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 26 Sep 2012 04:02:21 +0000 (00:02 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 26 Sep 2012 04:02:21 +0000 (00:02 -0400)
isn't any.
(profiler-stop): Use new semantics of profiler-*-stop.
(profiler-reset, profiler--report-cpu): Don't signal an error if the
cpu profiler is not available.
* src/profiler.c (Fprofiler_cpu_stop, Fprofiler_memory_stop):
Return whether the profiler was running, instead of signaling an error
if it wasn't.

lisp/ChangeLog
lisp/profiler.el
src/ChangeLog
src/profiler.c

index 64fb7e2ffc799781c16af1c848d9fc6599c7458a..d7304b68ade1b3c1352a18a26d60142b88896faf 100644 (file)
@@ -1,3 +1,11 @@
+2012-09-26  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * profiler.el (profiler-start): Don't prompt for choice when there
+       isn't any.
+       (profiler-stop): Use new semantics of profiler-*-stop.
+       (profiler-reset, profiler--report-cpu): Don't signal an error if the
+       cpu profiler is not available.
+
 2012-09-24  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * profiler.el (profiler-sample-interval): Move before first use.
index fb38b00c2d8ff11f6243a34bedb564a9e3455e7d..91bd744fb355dc86d80297164ab2f9297c12ec75 100644 (file)
@@ -574,9 +574,10 @@ MODE can be one of `cpu', `mem', or `cpu+mem'.
 If MODE is `cpu' or `cpu+mem', time-based profiler will be started.
 Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
   (interactive
-   (list (intern (completing-read "Mode (default cpu): "
-                                  '("cpu" "mem" "cpu+mem")
-                                 nil t nil nil "cpu"))))
+   (list (if (not (fboundp 'profiler-cpu-start)) 'mem
+           (intern (completing-read "Mode (default cpu): "
+                                    '("cpu" "mem" "cpu+mem")
+                                    nil t nil nil "cpu")))))
   (cl-ecase mode
     (cpu
      (profiler-cpu-start profiler-sample-interval)
@@ -592,30 +593,24 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
 (defun profiler-stop ()
   "Stop started profilers.  Profiler logs will be kept."
   (interactive)
-  (cond
-   ((and (profiler-cpu-running-p)
-        (profiler-memory-running-p))
-    (profiler-cpu-stop)
-    (profiler-memory-stop)
-    (message "CPU and memory profiler stopped"))
-   ((profiler-cpu-running-p)
-    (profiler-cpu-stop)
-    (message "CPU profiler stopped"))
-   ((profiler-memory-running-p)
-    (profiler-memory-stop)
-    (message "Memory profiler stopped"))
-   (t
-    (error "No profilers started"))))
+  (let ((cpu (if (fboundp 'profiler-cpu-stop) (profiler-cpu-stop)))
+        (mem (profiler-memory-stop)))
+    (message "%s profiler stopped"
+             (cond ((and mem cpu) "CPU and memory")
+                   (mem "Memory")
+                   (cpu "CPU")
+                   (t "No")))))
 
 (defun profiler-reset ()
   "Reset profiler log."
   (interactive)
-  (ignore (profiler-cpu-log))
+  (when (fboundp 'profiler-cpu-log)
+    (ignore (profiler-cpu-log)))
   (ignore (profiler-memory-log))
   t)
 
 (defun profiler--report-cpu ()
-  (let ((log (profiler-cpu-log)))
+  (let ((log (if (fboundp 'profiler-cpu-log) (profiler-cpu-log))))
     (when log
       (puthash 'type 'cpu log)
       (puthash 'timestamp (current-time) log)
index f540aef3814c07a81841b858f2912ff8310011e7..ce6f56fa8fc31897a9c197b1920a2d373b0d6de0 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-26  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * profiler.c (Fprofiler_cpu_stop, Fprofiler_memory_stop):
+       Return whether the profiler was running, instead of signaling an error
+       if it wasn't.
+
 2012-09-26  Juanma Barranquero  <lekktu@gmail.com>
 
        * makefile.w32-in (OBJ2, GLOBAL_SOURCES): Add profiler.c.
        * w32uniscribe.c (uniscribe_shape): Fix producing gstring
        components for RTL text (Bug#11860).  Adjust X-OFFSET of each
        non-base glyph for the width of the base character, according to
-       what x_draw_composite_glyph_string_foreground expects.  Generate
-       WADJUST value according to composition_gstring_width's
+       what x_draw_composite_glyph_string_foreground expects.
+       Generate WADJUST value according to composition_gstring_width's
        expectations, to produce correct width of the composed character.
        Reverse the sign of the DU offset produced by ScriptPlace.
 
index 8573d13b554add75216844013e25650d023197f0..e7593a6a0e06b98f2c383982504e87507dd16e37 100644 (file)
@@ -257,19 +257,20 @@ See also `profiler-log-size' and `profiler-max-stack-depth'.  */)
   timer.it_value = timer.it_interval;
   setitimer (ITIMER_PROF, &timer, 0);
 
-  profiler_cpu_running = 1;
+  profiler_cpu_running = true;
 
   return Qt;
 }
 
 DEFUN ("profiler-cpu-stop", Fprofiler_cpu_stop, Sprofiler_cpu_stop,
        0, 0, 0,
-       doc: /* Stop the cpu profiler.  The profiler log is not affected.  */)
+       doc: /* Stop the cpu profiler.  The profiler log is not affected.
+Return non-nil if the profiler was running.  */)
   (void)
 {
   if (!profiler_cpu_running)
-    error ("Sample profiler is not running");
-  profiler_cpu_running = 0;
+    return Qnil;
+  profiler_cpu_running = false;
 
   setitimer (ITIMER_PROF, 0, 0);
 
@@ -332,7 +333,7 @@ See also `profiler-log-size' and `profiler-max-stack-depth'.  */)
     memory_log = make_log (profiler_log_size,
                           profiler_max_stack_depth);
 
-  profiler_memory_running = 1;
+  profiler_memory_running = true;
 
   return Qt;
 }
@@ -340,13 +341,13 @@ See also `profiler-log-size' and `profiler-max-stack-depth'.  */)
 DEFUN ("profiler-memory-stop",
        Fprofiler_memory_stop, Sprofiler_memory_stop,
        0, 0, 0,
-       doc: /* Stop the memory profiler.  The profiler log is not affected.  */)
+       doc: /* Stop the memory profiler.  The profiler log is not affected.
+Return non-nil if the profiler was running.  */)
   (void)
 {
   if (!profiler_memory_running)
-    error ("Memory profiler is not running");
-  profiler_memory_running = 0;
-
+    return Qnil;
+  profiler_memory_running = false;
   return Qt;
 }
 
@@ -403,6 +404,7 @@ to make room for new entries.  */);
   profiler_log_size = 10000;
 
 #ifdef PROFILER_CPU_SUPPORT
+  profiler_cpu_running = false;
   cpu_log = Qnil;
   staticpro (&cpu_log);
   defsubr (&Sprofiler_cpu_start);
@@ -410,6 +412,7 @@ to make room for new entries.  */);
   defsubr (&Sprofiler_cpu_running_p);
   defsubr (&Sprofiler_cpu_log);
 #endif
+  profiler_memory_running = false;
   memory_log = Qnil;
   staticpro (&memory_log);
   defsubr (&Sprofiler_memory_start);