]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/lily.scm
Merge with master
[lilypond.git] / scm / lily.scm
index d4e05a4af1a9b1c20c08a32428b1e7baa3eaef2b..f455829be69924bc8456c847c1ea80a4e9487fe7 100644 (file)
 ;; Abbrv-PWR!
 (defmacro-public _i (x) x)
 
-(define (define-scheme-options)
-  (for-each (lambda (x)
-             (ly:add-option (car x) (cadr x) (caddr x)))
-         
-           `(
+(read-enable 'positions)
+(debug-enable 'debug)
+
+
 
-             ;; NAMING: either
+(define scheme-options-definitions
+  `(
 
-             ;; - [subject-]object-object-verb +"ing"
-             ;; - [subject-]-verb-object-object
+    ;; NAMING: either
 
-             (anti-alias-factor 1 "render at higher resolution and scale down result\nto prevent jaggies in PNG")
-             (check-internal-types #f "check every property assignment for types")
-             (clip-systems #f "Generate cut-out snippets of a score")
-             (debug-gc #f "dump memory debugging statistics")
-             (debug-gc-assert-parsed-dead #f "for memory debugging:
+    ;; - [subject-]object-object-verb +"ing"
+    ;; - [subject-]-verb-object-object
+
+    (anti-alias-factor 1 "render at higher resolution and scale down result\nto prevent jaggies in PNG")
+    (check-internal-types #f "check every property assignment for types")
+    (clip-systems #f "Generate cut-out snippets of a score")
+    (debug-gc #f "dump memory debugging statistics")
+    (debug-gc-assert-parsed-dead #f "for memory debugging:
 ensure that all refs to parsed objects are dead.  This is an internal option, and is switched on automatically for -ddebug-gc.") 
-             (debug-lexer #f "debug the flex lexer")
-             (debug-midi #f "generate human readable MIDI")
-             (debug-parser #f "debug the bison parser")
-             (debug-skylines #f "debug skylines")
-             (delete-intermediate-files #f
-                                        "delete unusable PostScript files")
-             (dump-profile #f "dump timing information for each file")
-             (dump-signatures #f "dump output signatures of each system.  Used for regression testing.")
-             
-             (eps-box-padding #f "Pad EPS bounding box left edge.  Guarantee alignment between systems in LaTeX.")
-             (gs-load-fonts #f
-                           "load fonts via Ghostscript.")
-             (gui #f "running from gui; redirect stderr to log file")
-
-             (include-book-title-preview #t "include book-titles in preview images.")
-             (include-eps-fonts #t "Include fonts in separate-system EPS files.")
-             (job-count #f "Process in parallel") 
-             (log-file #f "redirect output to log FILE.log")
-
-             (old-relative #f
-                           "relative for simultaneous music works
+    (debug-lexer #f "debug the flex lexer")
+    (debug-parser #f "debug the bison parser")
+    (debug-skylines #f "debug skylines")
+    (delete-intermediate-files #f
+                              "delete unusable PostScript files")
+    (dump-profile #f "dump timing information for each file")
+    (dump-signatures #f "dump output signatures of each system.  Used for regression testing.")
+    
+    (eps-box-padding #f "Pad EPS bounding box left edge.  Guarantee alignment between systems in LaTeX.")
+    (gs-load-fonts #f
+                  "load fonts via Ghostscript.")
+    (gui #f "running from gui; redirect stderr to log file")
+    (help #f "show this help.") 
+    (include-book-title-preview #t "include book-titles in preview images.")
+    (include-eps-fonts #t "Include fonts in separate-system EPS files.")
+    (job-count #f "Process in parallel") 
+    (log-file #f "redirect output to log FILE.log")
+
+    (old-relative #f
+                 "relative for simultaneous music works
 similar to chord syntax")
-             (point-and-click #t "use point & click")
-             (paper-size "a4" "the default paper size")
-             (pixmap-format "png16m" "GS format to use for pixel images")
-             (protected-scheme-parsing #t "continue when finding errors in inline
+    (point-and-click #t "use point & click")
+    (paper-size "a4" "the default paper size")
+    (pixmap-format "png16m" "GS format to use for pixel images")
+    (protected-scheme-parsing #t "continue when finding errors in inline
 scheme are caught in the parser. If off, halt 
 on errors, and print a stack trace.")
-             (profile-property-accesses #f "keep statistics of get_property() calls.")
-             
-             (resolution 101 "resolution for generating PNG bitmaps")
-             (read-file-list #f "Read files to be processed from command line arguments")
-
-             (safe #f "Run safely")
-             (strict-infinity-checking #f "If yes, crash on encountering Inf/NaN.")
-             (separate-log-files #f "Output to FILE.log per file.")
-             (ttf-verbosity 0
-                            "how much verbosity for TTF font embedding?")
-             (show-available-fonts #f
-                                   "List font names available.")
-             (verbose ,(ly:command-line-verbose?) "value for the --verbose flag")
-             )))
-
+    (profile-property-accesses #f "keep statistics of get_property() calls.")
+    
+    (resolution 101 "resolution for generating PNG bitmaps")
+    (read-file-list #f "Read files to be processed from command line arguments")
+
+    (safe #f "Run safely")
+    (strict-infinity-checking #f "If yes, crash on encountering Inf/NaN.")
+    (separate-log-files #f "Output to FILE.log per file.")
+    (trace-memory-frequency #f "Record Scheme cell usage this many times per second, and dump to file.")
+    (trace-scheme-coverage #f "Record coverage of Scheme files") 
+    (ttf-verbosity 0
+                  "how much verbosity for TTF font embedding?")
+    (show-available-fonts #f
+                         "List font names available.")
+    (verbose ,(ly:command-line-verbose?) "value for the --verbose flag")
+    ))
 
 ;; need to do this in the beginning. Other parts of the
 ;; Scheme init depend on these options.
 ;;
-(define-scheme-options)
+(for-each
+ (lambda (x)
+   (ly:add-option (car x) (cadr x) (caddr x)))
+ scheme-options-definitions)
+
+(for-each
+ (lambda (x)
+   (ly:set-option (car x) (cdr x)))
+ (eval-string (ly:command-line-options)))
 
 (debug-set! stack 0)
 
@@ -89,12 +99,15 @@ on errors, and print a stack trace.")
 
 (use-modules (ice-9 regex)
             (ice-9 safe)
+            (ice-9 rdelim)
              (ice-9 optargs)
             (oop goops)
             (srfi srfi-1)
             (srfi srfi-13)
             (srfi srfi-14)
             (scm clip-region)
+            (scm memory-trace)
+            (scm coverage)
             )
 
 ;; my display
@@ -109,13 +122,20 @@ on errors, and print a stack trace.")
 ;;; debugging evaluator is slower.  This should
 ;;; have a more sensible default.
 
-(if (ly:get-option 'verbose)
+(if (or (ly:get-option 'verbose)
+       (ly:get-option 'trace-memory-frequencency)
+       (ly:get-option 'trace-scheme-coverage)
+       )
     (begin
       (ly:set-option 'protected-scheme-parsing #f)
       (debug-enable 'debug)
       (debug-enable 'backtrace)
       (read-enable 'positions)))
 
+
+(if (ly:get-option 'trace-scheme-coverage)
+    (coverage:enable))
+
 (define-public tex-backend?
   (member (ly:output-backend) '("texstr" "tex")))
 
@@ -265,9 +285,10 @@ The syntax is the same as `define*-public'."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; other files.
 
-(for-each ly:load
-         ;; load-from-path
-         '("lily-library.scm"
+
+(define
+  init-scheme-files
+  '("lily-library.scm"
            "file-cache.scm"
            "define-event-classes.scm"
            "define-music-types.scm"
@@ -314,6 +335,9 @@ The syntax is the same as `define*-public'."
            "safe-lily.scm"))
 
 
+(for-each ly:load init-scheme-files)
+
+
 (set! type-p-name-alist
       `(
        (,boolean-or-symbol? . "boolean or symbol")
@@ -385,6 +409,15 @@ The syntax is the same as `define*-public'."
 
 (define gc-dumping #f)
 (define gc-protect-stat-count 0)
+
+(define-public (dump-live-object-stats outfile)
+  (for-each
+   (lambda (x)
+     (format outfile "~a: ~a\n" (car x) (cdr x)))
+   (sort (gc-live-object-stats)
+        (lambda (x y)
+          (string<? (car x) (car y))))))
+
 (define-public (dump-gc-protects)
   (set! gc-protect-stat-count (1+ gc-protect-stat-count))
   (let* ((protects (sort
@@ -433,14 +466,7 @@ The syntax is the same as `define*-public'."
 
          (set! stats (gc-live-object-stats))
          (display "Dumping live object statistics.\n")
-         
-         (for-each
-          (lambda (x)
-            (format outfile "~a: ~a\n" (car x) (cdr x)))
-          (sort (gc-live-object-stats)
-                (lambda (x y)
-                  (string<? (car x) (car y)))))))
-
+         (dump-live-object-stats outfile)))
 
     (newline outfile)
     (let*
@@ -462,6 +488,36 @@ The syntax is the same as `define*-public'."
                           )))
 
     (set! gc-dumping #f)
+    (close-port outfile)
+    
+    ))
+
+
+(define (check-memory)
+  "read /proc/self to check up on memory use." 
+  (define (gulp-file name)
+    (let* ((file (open-input-file name))
+          (text (read-delimited "" file)))
+      (close file)
+      text))
+  (let*
+      ((stat (gulp-file "/proc/self/status"))
+       (lines (string-split stat #\newline))
+       (interesting (filter identity
+                           (map
+                            (lambda (l)
+                              (string-match "^VmData:[ \t]*([0-9]*) kB" l))
+                            lines)))
+       (mem (string->number (match:substring (car interesting) 1)))
+       )
+
+    
+    (display (format  "VMDATA: ~a\n" mem))
+    (display (gc-stats))
+    (if (> mem 100000)
+       (begin
+         (dump-gc-protects)
+         (raise 1)))
     
     ))
 
@@ -482,11 +538,13 @@ The syntax is the same as `define*-public'."
 
 (define-public (lilypond-main files)
   "Entry point for LilyPond."
-  
+
   (define (no-files-handler)
     (ly:usage)
     (exit 2))
 
+  (eval-string (ly:command-line-code))
+  
   (if (ly:get-option 'gui)
       (gui-main files))
 
@@ -561,20 +619,30 @@ The syntax is the same as `define*-public'."
           
   (if (string-or-symbol? (ly:get-option 'log-file))
       (ly:stderr-redirect (format "~a.log" (ly:get-option 'log-file)) "w"))
+
   
   (let ((failed (lilypond-all files)))
+    (if (ly:get-option 'trace-scheme-coverage)
+       (begin
+         (coverage:show-all (lambda (f) (string-contains f "lilypond"))
+                            )))
+         
+    
     (if (pair? failed)
        (begin
          (ly:error (_ "failed files: ~S") (string-join failed))
          (exit 1))
        (begin
+         (ly:do-atexit)
          ;; HACK: be sure to exit with single newline
          (ly:message "")
          (exit 0)))))
 
 (define-public (lilypond-all files)
-
-
+  (if (ly:get-option 'help)
+      (begin
+       (ly:option-usage)
+       (exit 0)))
   (if (ly:get-option 'show-available-fonts)
       (begin
        (ly:font-config-display-fonts)
@@ -599,21 +667,28 @@ The syntax is the same as `define*-public'."
 
         (if separate-logs
             (ly:stderr-redirect (format "~a.log" base) "w"))
-       
+        (if (ly:get-option 'trace-memory-frequency) 
+            (mtrace:start-trace  (ly:get-option 'trace-memory-frequency)))
+        
         (lilypond-file handler x)
         (if start-measurements
             (dump-profile x start-measurements (profile-measurements)))
-       
+
+        (if (ly:get-option 'trace-memory-frequency)
+            (begin
+              (mtrace:stop-trace)
+              (mtrace:dump-results base)))
+                
         (for-each
          (lambda (s)
            (ly:set-option (car s) (cdr s)))
          all-settings)
-        
+
         (ly:clear-anonymous-modules)
         (ly:set-option 'debug-gc-assert-parsed-dead #t)
         (gc)
         (ly:set-option 'debug-gc-assert-parsed-dead #f)
-        
+
         
         (if (ly:get-option 'debug-gc)
             (dump-gc-protects)
@@ -631,7 +706,7 @@ The syntax is the same as `define*-public'."
 
     (if (ly:get-option 'dump-profile)
        (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
-    
+
     failed))
 
 (define (lilypond-file handler file-name)