source profiler.lsp
Module: Profiler
Author: Jeff Ober
Version: 1.0
Location: http://static.artfulcode.net/newlisp/profiler.lsp
Profiles applications to help identify bottlenecks.
Version history
1.2 • added percentage of total time to report • added ability to sort report by column 1.1 • updated report to dynamically calculate column lengths • updated profile-context to accept multiple contexts 1.0 • initial release example:(define (fib:fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) (define (fib-memo:fib-memo n) (or (context 'fib-memo (string n)) (if (< n 2) 1 (context 'fib-memo (string n) (+ (fib-memo (- n 1)) (fib-memo (- n 2))))))) (Profiler:profile-context fib fib-memo) (dotimes (i 25) (println "Fib " i ": " (fib i)) (fib-memo i)) (println) (Profiler:report 'calls) => Fib 0: 1 Fib 1: 1 Fib 2: 2 Fib 3: 3 Fib 4: 5 Fib 5: 8 Fib 6: 13 Fib 7: 21 Fib 8: 34 Fib 9: 55 Fib 10: 89 Fib 11: 144 Fib 12: 233 Fib 13: 377 Fib 14: 610 Fib 15: 987 Fib 16: 1597 Fib 17: 2584 Fib 18: 4181 Fib 19: 6765 Fib 20: 10946 Fib 21: 17711 Fib 22: 28657 Fib 23: 46368 Fib 24: 75025 function | calls | total ms | ms/call | % time -------------------+------------+------------+--------------+----------- fib:fib | 392809 | 4450 | 0.011329 | 100.00 fib-memo:fib-memo | 71 | 0 | 0.000000 | 0.00- § - Profiler:reset-functions
syntax: (Profiler:reset-functions)
Resets functions to their values prior to being adapted for profiling. This function is automatically called when a profiler report is printed.
- § - Profiler:reset-statistics
syntax: (Profiler:reset-statistics)
Resets profiler statistics. This function is automatically called when a profiler report is printed.
- § - Profiler:report
syntax: (Profiler:report sort-by)
parameter: column - to sort by (descending order); default is 'calls.
Prints statistics for functions profiled. sort-by may be 'times, 'calls, 'per-call, or 'percentage. Sorts by number of calls by default.
- § - Profiler:profiled-function
syntax: (Profiler:profiled-function func)
parameter: func - function to profile
Returns a modified function to use with the profiler.
- § - Profiler:profile-functions
syntax: (Profiler:profile-functions list-functions)
parameter: list-functions - list of functions to profile
Sets functions listed in list-functions to have statistics collected while they run. Protected and built-in functions cannot be profiled.
example:(define (foo x y) (+ x y)) (define (bar x y) (foo x y)) (Profiler:profile-functions '(foo bar)) => '(foo bar)- § - Profiler:profile-context
syntax: (Profiler:profile-context ctx [ctx-2 ...])
parameter: ctx - context to profile
Updates all functions in context ctx to be profiled.
example:(define (foo:foo x y) (+ x y)) (define (foo:bar x y) (foo x y)) (Profiler:profile-context foo) => '(foo:bar foo:foo)- ∂ -
Artful Code
generated with newLISP and newLISPdoc