A convenience function for profiling multiple threads, combining start-profiling and stop-profiling.
hcl
do-profiling &key initialize processes profile-waiting ignore-in-foreign sleep function arguments func-and-args print stream
| initialize⇩ |
A boolean. |
| processes⇩ |
One of :current, :all, a mp:process or a list of mp:process objects. |
| profile-waiting⇩ |
A boolean. |
| ignore-in-foreign⇩ |
A boolean. |
| sleep⇩ |
A non-negative number, or nil. |
| function⇩ |
A function designator. |
| arguments⇩ |
Arguments passed to function. |
| func-and-args⇩ |
A function designator or a list (function-designator . args). |
| print⇩ |
A generalized boolean. |
| stream⇩ |
An output stream. |
The function do-profiling is a convenience function for profiling multiple threads, combining start-profiling and stop-profiling.
The behavior of do-profiling with no arguments is the same as:
(progn (start-profiling :processes :all :time t) (sleep 6) (stop-profiling))
The arguments initialize, processes, profile-waiting and ignore-in-foreign are passed to start-profiling. They have the same default values as for start-profiling, except processes which defaults to :all.
The arguments print and stream are passed to stop-profiling. They have the same default values as in stop-profiling. print is also passed as the value of time in the call to start-profiling. print defaults to t.
sleep is the time to sleep in seconds. If sleep is nil or 0 then do-profiling does not sleep. Also, if sleep is not supplied and either function or func-and-args are passed, it does not sleep.
func-and-args, and function together with arguments, can both be used for calling a function you supply. func-and-args is either a list of the form (function-designator . args), in which case function-designator is applied to the args, or it is a function designator which is called without arguments. function is applied to arguments.
The order of execution is first func-and-args (if this is non-nil), then function together with arguments if function is non-nil, and then sleep if sleep was passed explicitly or both function and func-and-args are nil.
On exit, do-profiling always stops the profiler rather than suspending it, that is the call to stop-profiling is with :suspend nil.
To profile whatever happens in the next 6 seconds:
(hcl:do-profiling)
To profile whatever happens in the next 10 minutes:
(hcl:do-profiling :sleep 600)
To run 4 processes in parallel with the same function and profile until they all die:
(defun check-all-processes-died (processes)
(dolist (p processes t)
(when (mp:process-alive-p p)
(return nil))))
(let ((processes
(loop for x below 4
collect
(mp:process-run-function
(format nil "my process ~a" x)
() 'my-function))))
(hcl:do-profiling
:func-and-args
(list 'mp:process-wait
"Waiting for processes to finish"
'check-all-process-died
processes)))
LispWorks® User Guide and Reference Manual - 18 Feb 2025 15:32:21