Hello Sven,

I confirm that it is a very good way to profile ...

Here are some tricks we are using:

1)  You can profile only some parts of your code with

============================
(include "valgrind/callgrind.h")

(define (start-profile)
  (pragma::void "CALLGRIND_START_INSTRUMENTATION;")
  #t)

(define (end-profile)
  (pragma::void "CALLGRIND_STOP_INSTRUMENTATION; CALLGRIND_DUMP_STATS;")
  #t)
============================

Then launch your app with  valgrind --tool=callgrind --instr-atstart=no


2) References to Scheme code

When profiling,  we use the -rm Bigloo option to keep C code.
In kcachegrind when clicking at  "Source code" it goes in the C code where 
there is, in comments, Line numbers of your scheme code.
It is particulary helpful when you arrive to "anonymous" functions ....


3) Demangle valgrind output: 

We also use this little function in order to demangle valgrind output:

============================
(define (prof-demangle filename)
  (let ((temp-filename (format "~a.demangle" filename)))    
    (with-output-to-file temp-filename
      (lambda ()
        (with-input-from-file filename
          (lambda ()
            (let loop ((line (read-line (current-input-port))))
              (if (not (eof-object? line))
                  (let ((func       (pregexp-match "BG[lL]_[\\w_]+z\\w\\d$" 
line))
                        (func-quote (pregexp-match "BG[lL]_[\\w_]+z\\w\\d'2$" 
line)))
                    (cond
                     (func (let* ((bigloo-func      (bigloo-demangle (car 
func))))
                             (print (pregexp-replace "BG[lL]_[\\w_]+z\\w\\d$"
                                                     line
                                                     bigloo-func))))
                     (func-quote (let* ((bigloo-func      (bigloo-demangle 
(substring (car func-quote) 0 (- (string-length (car func-quote)) 2)))))
                                   (print (pregexp-replace 
"BG[lL]_[\\w_]+z\\w\\d'2$"
                                                           line
                                                           (format "~a'2" 
bigloo-func)))))
                     (else (print line)))
                    (loop (read-line (current-input-port))))))))))))
============================

Have a nice profiling session !

( Thanks to Kevin in hour team that suggest kcachegrind and made the demangling 
function! )

BR,
Pierre-Francois




-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of 
Sven Hartrumpf
Sent: Monday, February 3, 2020 12:40 PM
To: [email protected]
Subject: [bigloo] Using valgrind for profiling bigloo-compiled binaries

Hi Bigloo users.

I just want to share a positive experience with valgrind (version 3.15) for 
profiling bigloo-compiled binaries. Here is a step-by-step guide:

1 Compile your binary with debug options (-g2); my binary name is foo.
2 Run your binary; you can stop it when you collected enough data:
  valgrind --tool=callgrind foo <foo-option1> ...
3 Browse the profile results:
  kcachegrind callgrind.out.*

Advantages over bglprof:
- The bigloo installation need not be configured for profiling.
- No special compilation of your binary needed (except for -g2).
- Accurate statistics (With bglprof, I sometimes see attributions
  to wrong functions - which might be my fault.)
- The host where you run your profiled binary needs no matching
  bigloo installation, if the binary is linked statically.

Disadvantages:
- Your binary will run 10-100 times slower than normal.
- Names of Scheme functions are mangled.

Ciao
Sven

Reply via email to