[racket] Profiling mostly macro-generated definitions?

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Tue Aug 28 10:47:58 EDT 2012

What is the proper way to get the statistical profiler to be aware of function definitions that are created by macro expansion (in different splicing-syntax-parameterize'd blocks, if that matters)?

I have a data flow analysis framework that is parameterized by the Might/Van Horn metafunctions from Abstracting Abstract Machines, and some others that are necessary for a real-world analysis (delta axiom approximations, pretty printers, etc). This parameterization is at compile-time, which generates several definitions local to different syntax-parameterizations. At the top level, I have my test suite that I want to now profile, since I'm hitting some performance issues. The profiler finds a few functions that it hides since they don't contribute to much of the running time. Everything else is not profiled, it seems.

Example generator:
(define-syntax (with-basic-k-trunc-analysis stx)
  (syntax-case stx ()
    [(_ (k trunc?) body1 body ...)
     (syntax/loc stx
           ([contour-length (λ (stx) #'k)] ; should be constant
            [truncate-rt? (λ (stx) #'trunc?)] ; should be constant
            [alloc (make-rename-transformer #'base-alloc)]
            [addr-lookup (make-rename-transformer #'base-addr-lookup)]
            [join-stores (make-rename-transformer #'base-join-stores)]
            [compare-σ (make-rename-transformer #'base-compare-σ)]
            [compare-w (make-rename-transformer #'base-compare-w)]
            [step-parameters (make-rename-transformer #'base-step-parameters)]
            [initial-parameters (make-rename-transformer #'base-initial-parameters)]
            [combine-parameters/exit (make-rename-transformer #'base-combine-parameters/exit)]
            [pretty-local (make-rename-transformer #'base-pretty-local)]
            [pretty-wide (make-rename-transformer #'base-pretty-wide)])
           (define (k-contour-add t label) <blah>)
           (define (base-tick s) <blah>)
           (syntax-parameterize ([tick (make-rename-transformer #'base-tick)])
              body1 body ...))))]))

There are several macros like this, all used in the same module as the invocation of the profiler. The top level wrapper is the splicing parameterization:

(define-syntax-rule (with-all-widening body1 body ...)
   ([widening 'all]
    [add-context (make-rename-transformer #'values)]
    [combine-context (make-rename-transformer #'combine-all)]
    [no-state (make-rename-transformer #'no-state-all-widen)])
   body1 body ...))


Posted on the users mailing list.