]> git.donarmstrong.com Git - lilypond.git/commitdiff
further memory trace polish.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 18 Jan 2007 12:12:45 +0000 (13:12 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 18 Jan 2007 12:12:45 +0000 (13:12 +0100)
scm/memory-trace.scm

index 0bcf5bd19c3afd01e39238eec04c43920f7c97b4..f5a19e8e4b688210dce8ccf897344fdb25545895 100644 (file)
@@ -1,4 +1,6 @@
 (define-module (scm memory-trace))
+(use-modules (lily)
+            (ice-9 format))
 
 (define-public (mtrace:start-trace freq)
   (set! usecond-interval (inexact->exact (/ 1000000 freq)))
@@ -15,6 +17,8 @@
 (define continue-tracing #t)
 (define busy-tracing #f)
 (define trace-thread #f)
+(define start-time 0)
+(define start-memory 0)
 
 (define trace-count 0)
 (define usecond-interval 100000)
@@ -23,7 +27,7 @@
           (pair? (cdr args))
           (pair? (cadr args)))
       (caadr args) #f))
-
+(define last-count 0)
 (define (record-stack key continuation . args)
   (if (eq? (current-thread) trace-thread)
       #t ;; do nothing.
        (trap-disable 'enter-frame)
 
        (set! trace-count (1+ trace-count))
-
+       (ly:progress "<~a: ~a>\n"
+                    trace-count
+                    (- (cdr (assoc 'total-cells-allocated (gc-stats))) last-count))
+       (set! last-count (cdr (assoc 'total-cells-allocated (gc-stats))))
        (set! trace-points
              (cons (list
                     (assoc 'total-cells-allocated (gc-stats))
 
 (define (start-install-tracepoint)
   (set! trace-thread (current-thread))
+  (set! trace-points '())
+  (set! continue-tracing #t)
+  (set! trace-count 0)
+  (set! start-memory (cdr (assoc 'total-cells-allocated (gc-stats))))
+  (set! start-time (tms:utime (times)))
+  
   (install-tracepoint))
 
 (define (install-tracepoint)
       (install-tracepoint)))
 
 (define-public (mtrace:dump-results base)
-  (define out-graph (open-output-file (format #f "~a.graph" base)))
-  (define stacks-out (open-output-file (format #f "~a.stacks" base)))
-  (define i 0)
-  (define last-mem 0)
-  
-  (format out-graph "# memory trace with ~a points\n" (length trace-points))
-  
-  (for-each
-   (lambda (r)
-     (let*
-        ((mem (cdr (assoc 'total-cells-allocated r)))
-         (proc (cdr (assoc 'proc r)))
-         (stack (cdr (assoc 'stack r)))
-         (time (cdr (assoc 'time r))))
-       
-       (format out-graph "~a ~a\n" time mem)
-       (if stack
-          (begin
-            (format stacks-out "~15a - delta-mem: ~15a - ~a \n" i
-                    (- mem last-mem) proc)
-            (do
-                ((j 0 (1+ j))
-                 (stack (cdr (assoc 'stack r)) stack))
-                ((>= j (vector-length stack)))
-              
-              (format stacks-out "\t~a\n"
-                      (vector-ref stack j)))))
-       
-       (set! i (1+ i))
-       (set! last-mem mem)
-       ))
-   (reverse trace-points)))
-
+  (let*
+      ((stacks-name (format #f "~a.stacks" base))
+       (graph-name (format #f "~a.graph" base))
+       (graph-out (open-output-file graph-name))
+       (stacks-out (open-output-file stacks-name))
+       (i 0)
+       (last-mem 0)
+       )
+
+    (ly:progress "Memory statistics to ~a and ~a..."
+                stacks-name graph-name)
+    (format graph-out "# memory trace with ~a points\n" (length trace-points))
+    (for-each
+     (lambda (r)
+       (let*
+          ((mem (- (cdr (assoc 'total-cells-allocated r)) start-memory))
+           (proc (cdr (assoc 'proc r)))
+           (stack (cdr (assoc 'stack r)))
+           (time (- (cdr (assoc 'time r)) start-time)))
+        
+        (format graph-out "~a ~a\n" time mem)
+        (if stack
+            (begin
+              (format stacks-out "~5a t = ~5a - delta-mem: ~15a - ~a \n" i
+                      time
+                      (- mem last-mem) proc)
+              (do
+                  ((j 0 (1+ j))
+                   (stack (cdr (assoc 'stack r)) stack))
+                  ((>= j (vector-length stack)))
+                
+                (format stacks-out "\t~a\n"
+                        (vector-ref stack j)))))
+        
+        (set! i (1+ i))
+        (set! last-mem mem)
+        ))
+     (reverse trace-points))))
 
 
 (define (test-graph . rest)