unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Tommi Höynälänmaa" <tommi.hoynalanmaa@gmail.com>
To: guile-devel@gnu.org
Subject: Re: Corrected cumulative time measuring support
Date: Sat, 30 Jan 2021 08:50:09 +0200	[thread overview]
Message-ID: <ed6960f8-4b1e-6abf-41bb-30c2173e6650@gmail.com> (raw)
In-Reply-To: <5f91eb67-438a-6091-9dcb-83992815f576@gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 469 bytes --]

Hi

Here is a properly formatted version of the patch.

      - Tommi Höynälänmaa


Tommi Höynälänmaa kirjoitti 26.1.2021 klo 13.27:
> Hi
>
> I made an enhanced version of Guile statprof that computes the 
> cumulative time spent in procedures correctly (so that recursive 
> invocations of the same procedure are counted only once). The patch is 
> attached. Please inform me if you find any bugs.
>
>      - Tommi Höynälänmaa
>
>


[-- Attachment #1.1.2: 0008-improve-statprof.patch --]
[-- Type: text/x-patch, Size: 5817 bytes --]

Description: Implement corrected cumulative execution time in statprof
Author: Tommi Höynälänmaa <tommi.hoynalanmaa@iki.fi>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/module/statprof.scm
+++ b/module/statprof.scm
@@ -355,13 +355,16 @@
 
 (define-record-type call-data
   (make-call-data name printable source
-                  call-count cum-sample-count self-sample-count)
+                  call-count cum-sample-count corr-cum-sample-count
+		  self-sample-count)
   call-data?
   (name call-data-name)
   (printable call-data-printable)
   (source call-data-source)
   (call-count call-data-call-count set-call-data-call-count!)
   (cum-sample-count call-data-cum-sample-count set-call-data-cum-sample-count!)
+  (corr-cum-sample-count call-data-corr-cum-sample-count
+			 set-call-data-corr-cum-sample-count!)
   (self-sample-count call-data-self-sample-count set-call-data-self-sample-count!))
 
 (define (source->string source)
@@ -387,6 +390,10 @@
   (set-call-data-cum-sample-count! cd (1+ (call-data-cum-sample-count cd))))
 (define (inc-call-data-self-sample-count! cd)
   (set-call-data-self-sample-count! cd (1+ (call-data-self-sample-count cd))))
+(define (inc-call-data-corr-cum-sample-count! cd)
+  (set-call-data-corr-cum-sample-count!
+   cd
+   (1+ (call-data-corr-cum-sample-count cd))))
 
 (define (skip-count-call buffer start len)
   ;; If we are counting all procedure calls, count-call might be on the
@@ -424,7 +431,8 @@
                                         (and call-counts
                                              (hashv-ref call-counts entry))
                                         0
-                                        0)))
+                                        0
+					0)))
               (hashv-set! table entry data)
               data))))
 
@@ -443,12 +451,16 @@
                         pos)))
           (inc-call-data-self-sample-count!
            (addr->call-data (vector-ref buffer pos)))
-          (let visit-stack ((pos pos))
+          (let visit-stack ((pos pos)
+			    (visited-data '()))
             (cond
              ((vector-ref buffer pos)
               => (lambda (ip)
-                   (inc-call-data-cum-sample-count! (addr->call-data ip))
-                   (visit-stack (1+ pos))))
+		   (let ((cur-data (addr->call-data ip)))
+		     (inc-call-data-cum-sample-count! cur-data)
+		     (if (not (memv cur-data visited-data))
+			 (inc-call-data-corr-cum-sample-count! cur-data))
+		     (visit-stack (1+ pos) (cons cur-data visited-data)))))
              (else
               (visit-stacks (1+ pos)))))))
        (else table)))))
@@ -502,13 +514,15 @@
 
 (define-record-type stats
   (make-stats proc-name proc-source
-              %-time-in-proc cum-secs-in-proc self-secs-in-proc
+              %-time-in-proc cum-secs-in-proc corr-cum-secs-in-proc
+	      self-secs-in-proc
               calls)
   stats?
   (proc-name statprof-stats-proc-name)
   (proc-source statprof-stats-proc-source)
   (%-time-in-proc statprof-stats-%-time-in-proc)
   (cum-secs-in-proc statprof-stats-cum-secs-in-proc)
+  (corr-cum-secs-in-proc statprof-stats-corr-cum-secs-in-proc)
   (self-secs-in-proc statprof-stats-self-secs-in-proc)
   (calls statprof-stats-calls))
 
@@ -534,6 +548,7 @@
          (proc-source (and=> (call-data-source call-data) source->string))
          (self-samples (call-data-self-sample-count call-data))
          (cum-samples (call-data-cum-sample-count call-data))
+         (corr-cum-samples (call-data-corr-cum-sample-count call-data))
          (all-samples (statprof-sample-count state))
          (secs-per-sample (/ (statprof-accumulated-time state)
                              (statprof-sample-count state)))
@@ -547,6 +562,7 @@
                 proc-source
                 (* (/ self-samples all-samples) 100.0)
                 (* cum-samples secs-per-sample 1.0)
+                (* corr-cum-samples secs-per-sample 1.0)
                 (* self-samples secs-per-sample 1.0)
                 num-calls)))
 
@@ -577,9 +593,10 @@
            (sorted-stats (sort stats-list stats-sorter)))
 
       (define (display-stats-line stats)
-        (format port "~6,2f ~9,2f ~9,2f"
+        (format port "~6,2f  ~9,2f  ~9,2f ~9,2f"
                 (statprof-stats-%-time-in-proc stats)
                 (statprof-stats-cum-secs-in-proc stats)
+                (statprof-stats-corr-cum-secs-in-proc stats)
                 (statprof-stats-self-secs-in-proc stats))
         (if (call-counts state)
             (if (statprof-stats-calls stats)
@@ -599,15 +616,15 @@
     
       (if (call-counts state)
           (begin
-            (format  port "~5a ~10a   ~7a  ~8a\n"
-                     "%  " "cumulative" "self" "")
-            (format  port "~5a  ~9a  ~8a  ~7a ~a\n"
-                     "time" "seconds" "seconds" "calls" "procedure"))
+            (format  port "~5a  ~10a ~10a  ~7a  ~8a\n"
+                     "%  " "cumulative" "corr. cum." "self" "")
+            (format  port "~5a  ~10a ~10a  ~8a  ~7a ~a\n"
+                     "time" "seconds" "seconds" "seconds" "calls" "procedure"))
           (begin
-            (format  port "~5a ~10a   ~7a  ~8a\n"
-                     "%" "cumulative" "self" "")
-            (format  port "~5a  ~10a  ~7a  ~a\n"
-                     "time" "seconds" "seconds" "procedure")))
+            (format  port "~5a  ~10a ~10a  ~7a  ~8a\n"
+                     "%" "cumulative" "corr. cum." "self" "")
+            (format  port "~5a  ~10a ~10a  ~7a   ~a\n"
+                     "time" "seconds" "seconds" "seconds" "procedure")))
 
       (for-each display-stats-line sorted-stats)
 

[-- Attachment #1.1.3: OpenPGP_0xBB861FDE40460F83.asc --]
[-- Type: application/pgp-keys, Size: 3199 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

      reply	other threads:[~2021-01-30  6:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 11:27 Corrected cumulative time measuring support Tommi Höynälänmaa
2021-01-30  6:50 ` Tommi Höynälänmaa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed6960f8-4b1e-6abf-41bb-30c2173e6650@gmail.com \
    --to=tommi.hoynalanmaa@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).