summaryrefslogtreecommitdiff
path: root/module/statprof.scm
AgeCommit message (Collapse)AuthorFilesLines
2024-05-06Fix typos throughout codebase.Morgan Smith1-1/+1
* NEWS: * doc/ref/api-control.texi: * doc/ref/api-data.texi: * doc/ref/api-debug.texi: * doc/ref/api-deprecated.texi: * doc/ref/api-evaluation.texi: * doc/ref/api-foreign.texi: * doc/ref/api-i18n.texi: * doc/ref/api-io.texi: * doc/ref/api-languages.texi: * doc/ref/api-macros.texi: * doc/ref/api-memory.texi: * doc/ref/api-modules.texi: * doc/ref/api-options.texi: * doc/ref/api-peg.texi: * doc/ref/api-procedures.texi: * doc/ref/api-scheduling.texi: * doc/ref/api-undocumented.texi: * doc/ref/api-utility.texi: * doc/ref/expect.texi: * doc/ref/goops.texi: * doc/ref/misc-modules.texi: * doc/ref/posix.texi: * doc/ref/repl-modules.texi: * doc/ref/scheme-ideas.texi: * doc/ref/scheme-scripts.texi: * doc/ref/srfi-modules.texi: * gc-benchmarks/larceny/dynamic.sch: * gc-benchmarks/larceny/twobit-input-long.sch: * gc-benchmarks/larceny/twobit.sch: * libguile/gc.h: * libguile/ioext.c: * libguile/list.c: * libguile/options.c: * libguile/posix.c: * libguile/threads.c: * module/ice-9/boot-9.scm: * module/ice-9/optargs.scm: * module/ice-9/ports.scm: * module/ice-9/pretty-print.scm: * module/ice-9/psyntax.scm: * module/language/elisp/parser.scm: * module/language/tree-il/compile-bytecode.scm: * module/srfi/srfi-37.scm: * module/srfi/srfi-43.scm: * module/statprof.scm: * module/texinfo/reflection.scm: * test-suite/tests/eval.test: * test-suite/tests/fluids.test: Fix typos. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2020-06-04Statprof reports primitive namesAndy Wingo1-9/+1
* module/statprof.scm (program-debug-info-printable): Remove unused function. (addr->printable): If the addr is a primitive, extract its name.
2020-01-23statprof: Ensure 'call-thunk' is not inlined.Ludovic Courtès1-1/+5
Previously, 'make-stack' calls with the inner and outer cuts arguments would always return #f because 'call-thunk' wouldn't appear on the stack. * module/statprof.scm <top level>: Add self-assignment to 'call-thunk'.
2018-09-14VM manages hook sets itselfAndy Wingo1-2/+2
* libguile/vm.h (SCM_VM_ABORT_HOOK): Rename from SCM_VM_ABORT_CONTINUATION_HOOK. * libguile/vm-engine.c (ABORT_HOOK): * libguile/vm.c (invoke_abort_hook): Adapt to SCM_VM_ABORT_HOOK name change. (reset_vm_hook_enabled): New helper. (VM_ADD_HOOK, VM_REMOVE_HOOK): New helper macros, replacing VM_DEFINE_HOOK. (scm_vm_add_abort_hook_x, scm_vm_remove_abort_hook_x) (scm_vm_add_apply_hook_x, scm_vm_remove_apply_hook_x) (scm_vm_add_return_hook_x, scm_vm_remove_return_hook_x) (scm_vm_add_next_hook_x, scm_vm_remove_next_hook_x): New functions, replacing direct access to the hooks. Allows us to know in a more fine-grained way when to enable hooks. (scm_set_vm_trace_level_x): Use reset_vm_hook_enabled to update the individual hook_enabled flags. * module/statprof.scm: * module/system/vm/coverage.scm: * module/system/vm/traps.scm: * module/system/vm/vm.scm: Adapt VM hook users to the new API.
2018-08-06Minor updates for Scheme runtime (statprof, backtraces)Andy Wingo1-5/+1
* module/system/vm/frame.scm: Add a comment about a case that we need to handle in the future. * module/statprof.scm (statprof-proc-call-data): Always use the program code as the key, even for primitives.
2018-07-29Rewrite subr implementationAndy Wingo1-42/+15
* libguile/gsubr.c: Reimplement to store subr names and procedures in a side table, and to allocate fresh vcode for each subr. This allows JIT of subrs, moves to a uniform all-code-starts-with-instrument-entry regime, and also allows statprof to distinguish between subrs based on IP. * libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_NAME): Call out to functions, now that these are in a side table. (scm_subr_function, scm_subr_name): New exports. (scm_i_primitive_name): New internal function, for looking up a primitive name based on IP. (scm_apply_subr): Take the subr index. * libguile/vm-engine.c (subr-call): * libguile/jit.c (compile_subr_call): Adapt to take index as arg. * module/statprof.scm (sample-stack-procs, count-call): (stack-samples->procedure-data): Update to always record IP in stack samples and call counts. * module/system/vm/frame.scm (frame-procedure-name): Simplify. (frame-instruction-pointer-or-primitive-procedure-name): Removed. * libguile/programs.h: * libguile/programs.c (scm_primitive_code_name): New function. * module/system/vm/program.scm (primitive-code-name): New export.
2017-05-22Remove all deprecated codeAndy Wingo1-49/+0
* module/ice-9/debug.scm: * module/ice-9/mapping.scm: * module/ice-9/syncase.scm: Delete these deprecated files. * module/Makefile.am: Remove deleted files. * libguile/deprecated.c: * libguile/deprecated.h: * libguile/backtrace.c: * libguile/goops.c: * libguile/numbers.c: * libguile/socket.c: * libguile/srfi-13.c: * module/ice-9/deprecated.scm: * module/ice-9/format.scm: * module/oop/goops.scm: * module/statprof.scm: * module/texinfo/reflection.scm: * module/web/client.scm: * module/web/uri.scm: Remove deprecated code.
2017-04-19Fixed bug: statprof flat display wasn't writing summary lines to portFreja Nordsiek1-2/+2
* module/statprof.scm (statprof-display/flat): fixed bug where summary lines were written to (current-output-port) instead of the provided port.
2017-03-09Adapt gcprof to preemptive interruptsAndy Wingo1-4/+4
* module/statprof.scm (gcprof): Remove handle-interrupts trampoline from captured stacks.
2017-03-09Adapt statprof to new preemptive interruptsAndy Wingo1-2/+4
* module/statprof.scm (profile-signal-handler): Cut an additional stack frame, corresponding to the handle-interrupts trampoline added recently.
2017-03-09statprof: 'with-statprof' honors #:display-style.Ludovic Courtès1-1/+5
* module/statprof.scm (with-statprof): Pass #:display-style to 'statprof'.
2016-02-01Update statprof documentation; deprecate `with-statprof'Andy Wingo1-114/+47
* module/statprof.scm: Remove most of the commentary, as it was duplicated in the manual and was getting out of date. (stats): Remove self-secs-per-call and cum-secs-per-call fields as they can be computed from the other fields. (statprof-call-data->stats): Adapt. (statprof-stats-self-secs-per-call): (statprof-stats-cum-secs-per-call): New functions. (statprof-display/flat): Don't print the seconds-per-call fields, as we are no longer stopping the clock around call counters. Anyway these times were quite misleading. (with-statprof): Deprecate. It took its keyword arguments at the beginning; very complicated! Better to use the `statprof' function. (`statprof' was introduced after `with-statprof' and then `with-statprof' was adapted to use it.) * doc/ref/statprof.texi (Statprof): Port this documentation away from the automatically generated text and update it for the new interfaces like #:display-style. * module/system/base/syntax.scm (record-case): Remove comment that referenced with-statprof. Add comment indicating that record-case should be replaced. * doc/ref/scheme-using.texi (Profile Commands): Update to mention keyword arguments and to link to the statprof documentation.
2016-02-01Better call-counting profiles in statprofAndy Wingo1-32/+39
* module/statprof.scm: Update commentary. (count-call): Don't bother stopping and starting the timer. The overhead of call counting perturbs timing too much already, and somewhat paradoxically stopping and starting the timer takes too much time. (skip-count-call): New function. (stack-samples->procedure-data, stack-samples->callee-lists): If we are counting calls, skip any part of the stack that is inside count-call.
2016-01-31Remove frame-local-ref, frame-local-set!Andy Wingo1-11/+3
* libguile/frames.h (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x): Remove. As long as we are changing the interface in a backward-incompatible way, we might as well remove these. * libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x, scm_init_frames_builtins, scm_init_frames): Arrange to make frame-local-ref et al private to frames.scm. * module/system/vm/frame.scm: Load scm_init_frames_builtins extensions. (frame-instruction-pointer-or-primitive-procedure-name): New public function. (frame-binding-ref, frame-binding-set!): Allow binding objects as vars. * module/system/repl/debug.scm (print-locals): Pass binding directly to frame-binding-ref. * module/statprof.scm (sample-stack-procs, count-call): Use new frame-instruction-pointer-or-primitive-procedure-name function.
2016-01-11statprof: Better tree-format profilesAndy Wingo1-19/+29
* module/statprof.scm (statprof-fetch-call-tree): Add #:precise? keyword argument, defaulting to false. Search for cycles after computing printable source locations instead of doing so over addresses -- it could be that two addresses map to the same source location, and from the user's perspective they are then indistinguishable in the printout.
2016-01-11statprof: Add tree #:display-style.Andy Wingo1-32/+119
* module/statprof.scm (statprof-display/flat): Rename from statprof-display. Use real format; we have it. (statprof-display-anomalies): Likewise use real format. (procedure=?): Remove unused function. (collect-cycles): New helper. (statprof-fetch-call-tree): Fix to root the trees correctly -- it was interpreting them in the wrong order. Detect cycles so that it's not so terrible. Use precise locations for source locations. Probably need to add an option to go back to the per-function behavior. (statprof-display/tree): New helper, uses statprof-fetch-call-tree to display a profile in a nested tree. (statprof-display): Add #:style argument, which can be `flat', `anomalies', or `tree'. (statprof): Add #:display-style argument, proxying to #:style, defaulting to 'flat.
2015-12-01Remove primitive?, add primitive-code?Andy Wingo1-14/+19
We need to be able to identify frames that are primitive applications without assuming that slot 0 in a frame is an SCM value and without assuming that value is the procedure being applied. * libguile/gsubr.c (scm_i_primitive_code_p): New helper. (scm_i_primitive_arity): Use the new helper. * libguile/gsubr.h: Declare the new helper. * libguile/programs.h: * libguile/programs.c (scm_program_code_p): New function, replacing scm_primitive_p. (scm_primitive_call_ip): Fix FUNC_NAME definition. * module/statprof.scm (sample-stack-procs, count-call): Identify primitive frames from the IP, not the frame-procedure. Avoids the assumption that slot 0 in a frame is a SCM value. (statprof-proc-call-data): Adapt to primitive-code? change. * module/system/vm/frame.scm (frame-call-representation): Identify primitive frames from the IP, not the closure. Still more work to do here to avoid assuming slot 0 is a procedure. * module/system/vm/program.scm: Export primitive-code? instead of primitive?. (program-arguments-alist, program-arguments-alists): Identify primitives from the code instead of the flags on the program. Not sure this is a great change, but it does avoid having to define a primitive? predicate in Scheme.
2015-01-22Merge commit 'cdcba5b2f6270de808e51b3b933374170611b91d'Andy Wingo1-9/+11
Conflicts: module/statprof.scm
2015-01-11statprof: 'statprof' and 'with-statprof' return the code's return values.Ludovic Courtès1-11/+12
* module/statprof.scm (statprof): Return the return values of THUNK. (with-statprof): Adjust docstring accordingly. * test-suite/tests/statprof.test ("return values"): New test. * doc/ref/statprof.texi (Statprof): Adjust accordingly.
2014-05-01Fix inner and outer stack cuts to match on procedure codeAndy Wingo1-2/+4
* doc/ref/api-debug.texi (Stack Capture): Update make-stack docs. * libguile/programs.h: * libguile/programs.c (scm_program_address_range): New internal procedure. * libguile/stacks.c (narrow_stack): Interpret a pair of integers as an address range. If a cut is a procedure, attempt to resolve it to an address range. (scm_make_stack): Update docstring. * module/system/vm/program.scm (program-address-range): New exported procedure. * module/statprof.scm (statprof, gcprof): Use program-address-range to get the outer-cut, for efficiency.
2014-04-16Fix statprof for optimizationsAndy Wingo1-21/+28
* module/statprof.scm (profile-signal-handler): Bind in a letrec. Otherwise the compiler may see the closure slot as dead, and the inner stack cut won't work.
2014-04-14statprof avoids mucking with VM trace levels when not counting callsAndy Wingo1-5/+5
* module/statprof.scm (statprof-start, statprof-stop): Don't futz the vm trace level when we aren't counting calls. With this change, statprof now imposes no overhead on the measured program.
2014-04-14Better state handling in statprofAndy Wingo1-16/+20
* module/statprof.scm (statprof-fold-call-data) (statprof-proc-call-data): Add optional state arg. (gcprof): Add optional port arg, and pass state arg explicitly. (statprof-display-anomalies, statprof-display) (statprof-call-data->stats): Pass state explicitly.
2014-03-01,profile, statprof, gcprof have an outer stack cutAndy Wingo1-22/+28
* module/statprof.scm (<state>): Add outer-cut member. (fresh-profiler-state): Add outer-cut kwarg. (sample-stack-procs): Stop when the stack-length is zero, which will be before the frames run out if there is an outer cut. (profile-signal-handler): Use the outer cut when capturing the stack. (call-thunk): New helper, for use as an outer cut. (statprof, gcprof): Call the thunk within call-thunk, and use call-thunk as an outer cut.
2014-03-01Statprof commentingsAndy Wingo1-17/+87
* module/statprof.scm: Add a big ol' comment. (sample-stack-procs): If slot 0 isn't a primitive, use the IP to mark. In the future we will see more non-procedures in slot 0 as we start to use call-label and tail-call-label.
2014-03-01statprof-display prints source locationsAndy Wingo1-17/+31
* module/statprof.scm (call-data): Source is after printable. (addr->printable): Just produce a name, without source. Anonymous printables get "anon " prefixed. (stack-samples->procedure-data): Adapt to call-data change. (stats): Add "proc-source" element. (statprof-call-data->stats): Give a source to the call-data. (statprof-display): Print source also.
2014-02-28Refactorings: call-data has source, stats is a recordAndy Wingo1-31/+31
* module/statprof.scm (call-data): Add source member. (stack-samples->procedure-data): Populate source member (stats): Convert to record from vector. (statprof-call-data->stats): Adapt to produce a record.
2014-02-28Statprof uses stack trace buffer to always provide full stacksAndy Wingo1-61/+62
* module/statprof.scm (<state>): Remove record-full-stacks? and stacks members. The stack trace buffer is sufficient. (fresh-profiler-state): Adapt. (sample-stack-procs): Don't save stacks. (statprof-reset): Deprecate the full-stacks? argument. (stack-samples->procedure-data): Remove a needless vector-ref. (stack-samples->callee-lists): New helper. (statprof-fetch-stacks): Use stack-samples->callee-lists. (statprof-fetch-call-tree): Use stack-samples->callee-lists, and implement our own callee->string helper. (statprof, with-statprof, gcprof): Deprecate full-stacks? argument.
2014-02-28Statprof always stores full stack tracesAndy Wingo1-113/+192
* module/statprof.scm (<state>): Instead of a boolean count-calls?, treat the presence of a call-counts hash table as indicating a need to count calls. That hash table maps callees to call counts. A "callee" is either the IP of the entry of a program, the symbolic name of a primitive, or the identity of a non-program. New members "buffer" and "buffer-pos" replace "procedure-data". We try to avoid analyzing things at runtime, instead just recording the stack traces into a buffer. This will let us do smarter things when post-processing. (fresh-buffer, expand-buffer): New helpers. (fresh-profiler-state): Adapt to <state> changes. (sample-stack-procs): Instead of updating the procedure-data table (which no longer exists), instead trace the stack into the buffer. (count-call): Update to update the call-counts table instead of the procedure-data table. (statprof-start, statprof-start): Adapt to call-counts change. (call-data): Move lower in the file. Add "name" and "printable" members, and no longer store a proc. (source->string, program-debug-info-printable, addr->pdi) (addr->printable): New helpers. (stack-samples->procedure-data): New procedure to process stack trace buffer into a hash table of the same format as the old procedure-data table. (statprof-fold-call-data, statprof-proc-call-data): Use stack-samples->procedure-data instead of procedure-data. (statprof-call-data->stats): Adapt to count-calls change. (statprof-display, statprof-display-anomalies): Adapt.
2014-02-28Update statprof commentaryAndy Wingo1-9/+6
* module/statprof.scm: Update commentary.
2014-02-28More state-related refactors in statprofAndy Wingo1-14/+12
* module/statprof.scm (statprof-start, statprof-stop): Take optional state arg. (statprof-reset): Return no values. (statprof): Take port keyword arg. Since statprof-reset is now the same as parameterizing profiler-state, there's no need to call statprof-reset. Pass the state argument explicitly to statprof-start, statprof-stop, and statprof-display.
2014-02-28Statprof restores previous sigprof handler when stoppingAndy Wingo1-11/+15
* module/statprof.scm (<state>): Add field for the previous SIGPROF handler. (statprof-start, statprof-stop, statprof-reset): Instead of setting the SIGPROF handler in statprof-reset, set it when the profiler becomes active, and actually restore it when the profiler becomes inactive.
2014-02-28More statprof refactorsAndy Wingo1-23/+21
* module/statprof.scm (statprof-display, statprof-display-anomalies) (statprof-accumulated-time, statprof-sample-count) (statprof-fetch-stacks, statprof-fetch-call-tree): Take optional state argument. (statprof-display-anomolies): Deprecate this mis-spelling. (statprof): Just compute usecs for the period.
2014-02-28Slight gcprof refactorAndy Wingo1-25/+12
* module/statprof.scm (gcprof): Refactor a bit.
2014-02-28statprof uses new setitimer magical usecs abilityAndy Wingo1-5/+3
* module/statprof.scm (sample-stack-procs): Take advantage of setitimer allowing usecs >= 1e6.
2014-02-25gcprof tweaksAndy Wingo1-15/+1
* module/statprof.scm (gcprof): No need to reset in gcprof; the fresh profiler state and the parameterize handle that. Fix mistaken set-vm-trace-level! as well.
2014-02-25Refactor representation of sampling periods in statprofAndy Wingo1-24/+21
* module/statprof.scm (<state>): The sampling frequency is actually a period; label it as such, and express in microseconds instead of as a pair. Likewise for remaining-prof-time. (fresh-profiler-state): Adapt. (reset-sigprof-timer): New helper. (profile-signal-handler): Use the new helper. (statprof-start): Use the new helper. (statprof-stop): Here too. (statprof-reset): Adapt to <state> change. (gcprof): Set remaining prof time to 0.
2014-02-25statprof and gcprof procedures use a fresh statprof stateAndy Wingo1-83/+82
* module/statprof.scm (statprof, gcprof): Create a fresh statprof state.
2014-02-22simplify profile-signal-handlerAndy Wingo1-20/+7
* module/statprof.scm (profile-signal-handler): Don't bother detecting if we were in a count-call call or not; it doesn't matter, and we should accumulate time in any case.
2014-02-22statprof: accumulated-time is in jiffiesAndy Wingo1-8/+8
* module/statprof.scm (fresh-profiler-state): accumulated-time and gc-time-taken are in jiffies, not seconds, so they are exact. (statprof-accumulated-time): Divide by 1.0 so that we get a flonum. Also refactor use of assq to get the gc-time-taken.
2014-02-22Pass state around statprof in more placesAndy Wingo1-11/+11
* module/statprof.scm (get-call-data, sample-stack-procs): Take the state as an argument. (profile-signal-handler, count-call, statprof-proc-call-data) (gcprof): Adapt.
2014-02-22statprof: call-data is a record typeAndy Wingo1-11/+11
* module/statprof.scm (call-data): Reimplement as a record type.
2014-02-22statprof: when/unless instead of if.Andy Wingo1-108/+101
* module/statprof.scm: Use when or unless instead of if, where appropriate.
2014-02-21add a statprof fixmeAndy Wingo1-0/+5
* module/statprof.scm: Add a fixme.
2014-02-21statprof-active? instead of checking profile levelAndy Wingo1-19/+12
* module/statprof.scm (statprof-reset, statprof-fold-call-data): (statprof-proc-call-data, statprof-accumulated-time): (statprof-sample-count): Refactor some things to use statprof-active? instead of checking the profile level manually.
2014-02-21statprof-reset creates a new stateAndy Wingo1-16/+16
* module/statprof.scm (fresh-profiler-state): New helper. (ensure-profiler-state): Use it. (accumulate-time): No need to add 0.0 here. (statprof-reset): Create a new state instead of mutating the existing one.
2014-02-21More statprof state refactoringsAndy Wingo1-14/+18
* module/statprof.scm (existing-profiler-state): New helper, gets the profiler state or fails if there is no state. (sample-stack-procs, profile-signal-handler, count-call) (statprof-fold-call-data, statprof-proc-call-data) (statprof-call-data->stats, statprof-display) (statprof-display-anomolies, statprof-accumulated-time) (statprof-sample-count, statprof-fetch-stacks) (statprof-fetch-call-tree): Use the new helper. (statprof-active?): Don't create a state if there isn't one already.
2014-02-21inside-profiler? to parameter instead of global variableAndy Wingo1-11/+11
* module/statprof.scm (<state>): Add inside-profiler? member. Move mutations of inside-profiler? here.
2014-02-21Beginnings of statprof threadsafetyAndy Wingo1-108/+155
* module/statprof.scm (<state>, profiler-state, ensure-profiler-state): A mostly-mechanical refactor to encapsulate profiler state in a parameter and a record instead of global variables.
2014-02-21reform statprof commentaryAndy Wingo1-100/+89
* module/statprof.scm: Reformat the commentary.