The simple-profiling Module

This module provides an easy to use interface for measuring application performance.

Simple Profiling

timing Statement Macro

Returns the time, in seconds and microseconds, spent executing the body of code it is wrapped around.

Macro Call

timing () [ *body* ] end [ timing ]

Parameters
  • body – A Dylan body bnf

Values
Discussion

Returns the time, in seconds and microseconds, spent executing the body of code it is wrapped around.

The first value returned is the number of whole seconds spent in body. The second value returned is the number of microseconds spent in body in addition to seconds.

Example
timing ()
  for (i from 0 to 200)
    format-to-string("%d %d", i, i + 1)
  end
end;
=> 1 671000
profiling Macro

Gives access to the CPU time, in seconds and microseconds, as well as some memory allocation statistics, spent executing the body of code it is wrapped around.

Macro Call

profiling ([*profiling-type*, ...])
  *body*
results
  *results*
end

Parameters
  • profiling-type – Any of cpu-time-seconds, cpu-time-microseconds, allocation and allocation-stats.

  • body – A Dylan body bnf

  • results – A Dylan body bnf

Discussion

This macro takes a set of profiling-type parameters, performs the body of code and then executes the results. Within the results block, there will be bindings with the names of the profiling types which have the corresponding value.

Note

Using allocation-stats is more involved and not as flexible as one might hope. This needs further documentation and perhaps an improved implementation.

Note

The memory allocation statistics may not work on all run-times and platforms.

Example
profiling (cpu-time-seconds, cpu-time-microseconds, allocation)
  execute-command(command)
results
  message(context, "Command took %d.%s seconds, and allocated %d bytes",
          cpu-time-seconds,
          integer-to-string(floor/(cpu-time-microseconds, 1000), size: 3),
          allocation)
end

Internals

These functions don’t typically need to be called directly but may be useful in some scenarios.

<profiling-state> Type
Equivalent

<object-table>

<cpu-profiling-type> Type
Equivalent

one-of(#"cpu-time-seconds", #"cpu-time-microseconds")

profiling-type-result Open Generic function
Signature

profiling-type-result (state keyword #key #all-keys) => (value)

Parameters
Values
profiling-type-result(<profiling-state>, <cpu-profiling-type>) Method
profiling-type-result(<profiling-state>, singleton(#"allocation")) Method
profiling-type-result(<profiling-state>, singleton(#"allocation-stats")) Method
start-profiling Function
Signature

start-profiling (profiling-types) => (state)

Parameters
  • profiling-types – A sequence of any of #"cpu-time-seconds", #"cpu-time-microseconds", #"allocation# and #"allocation-stats#.

Values

This is useful for when direct control over profiling is needed rather than using the profiling macro.

start-profiling-type Open Generic function
Signature

start-profiling-type (state keyword) => ()

Parameters
start-profiling-type(<profiling-state>, <cpu-profiling-type>) Method
start-profiling-type(<profiling-state>, singleton(#"allocation")) Method
start-profiling-type(<profiling-state>, singleton(#"allocation-stats")) Method
stop-profiling Function
Signature

stop-profiling (state profiling-types) => ()

Parameters
stop-profiling-type Open Generic function
Signature

stop-profiling-type (state keyword) => ()

Parameters
stop-profiling-type(<profiling-state>, <cpu-profiling-type>) Method
stop-profiling-type(<profiling-state>, singleton(#"allocation")) Method
stop-profiling-type(<profiling-state>, singleton(#"allocation-stats")) Method