Examine (examine v0.3.0) View Source

Examine enhances inspect debugging by printing additional compile-time and runtime information, include file code and execution times.

Global configuration

  • :environments - The environments in which the Examine.inspect/2 macro will be expanded -- in all other environments it will compile to a noop. The value is a list of atoms. Defaults to [:dev].

    For an instance of Examine.inspect/2, the :ignore_env option can be used to expand the macro regardles of the environment.

  • :color - The foreground color used when printing. It must be a atom value and one of the default colors defined in IO.ANSI. Defaults to :white.

  • :bg_color - The background color used when printing. It must be a atom value and one of the default colors defined in IO.ANSI. Defaults to :cyan.

  • :time_unit - The time unit used for measuring execution time. It must be one of units defined in the System.time_unit/0 type. Defaults to :millisecond.

Local option value for :color, :bg_color, and :time_unit will override global config.

Example configuration in a config.exs file:

config :examine,
  environments: [:dev, :staging],
  color: :yellow,
  bg_color: :black,
  time_unit: :second

Link to this section Summary

Functions

Prints code representation, its result, and its execution time. If used with the :inspect_pipeline option, it will print the results and times next to the file code, for each step in the pipeline preceding the call.

Link to this section Functions

Link to this macro

inspect(expression, opts \\ [])

View Source (macro)

Prints code representation, its result, and its execution time. If used with the :inspect_pipeline option, it will print the results and times next to the file code, for each step in the pipeline preceding the call.

Examples

> require Examine
> Examine.inspect(1 + 2)

iex:2

  1 + 2 #=> [0ms] 3

In a file:

start = 1
increment = 1

start
|> Kernel.+(increment)
|> Kernel.+(increment)
|> Examine.inspect(inspect_pipeline: true, show_vars: true)

Prints:

./file_name.ex:10
  increment = 1
  start = 1

  start
  |> Kernel.+(increment) #=> [0ms] 2
  |> Kernel.+(increment) #=> [0ms] 3

  Total Duration: 0ms

Options

  • :show_vars - Optional. Prints the bindings for the given context below the filename. Defaults to false.

  • :label - Optional. Will display a text label on the top line of the block, above the filename.

  • :color - Optional. The text color, which must be one of the <:color>/0 functions in IO.ANSI. Defaults to :white.

  • :bg_color - Optional. The background color, which must be one of the <:bg_color>_background/0 functions in IO.ANSI. Defaults to :cyan.

  • :inspect_pipeline - Optional. Inspect the returned values for each preceding step in the pipeline.

  • :measure - Optional. Display execution time. If used in conjunction with inspect_pipeline, it will measure the execution time for each preceding step in the pipeline. If there are multiple execution steps, it will also display the total duration below the code. Defaults to true.

  • :time_unit - Optional. The time unit used for measuring execution time. The value can be any of the unit options in Elixir's System.time_unit/0 type. Defaults to :millisecond.

  • :ignore_env - Optional. Ignore the global :environments config for this instance so that the macro will be expanded at compile time regardless of the environment. Defaults to false.

  • :io_inspect - Pass in IO.inspect/2 options as a keyword list and they will be passed through to inspected results.