Skip to content

Instantly share code, notes, and snippets.

@tokafish
Created June 3, 2016 16:08
Show Gist options
  • Save tokafish/75f1a5dabdad81253a642bdaf2ad4a75 to your computer and use it in GitHub Desktop.
Save tokafish/75f1a5dabdad81253a642bdaf2ad4a75 to your computer and use it in GitHub Desktop.
Pass instrumented result to stop
for {event, instrumenters} <- app_instrumenters do
start_callbacks = Phoenix.Endpoint.Instrument.compile_start_callbacks(event, instrumenters)
stop_callbacks = Phoenix.Endpoint.Instrument.compile_stop_callbacks(event, instrumenters)
def instrument(unquote(event), var!(compile), var!(runtime), fun)
when is_map(var!(compile)) and is_map(var!(runtime)) and is_function(fun, 0) do
unquote(start_callbacks)
start = :erlang.monotonic_time
try do
fun.()
rescue
error ->
var!(instrumented_result) = error
var!(diff) = :erlang.monotonic_time - start
unquote(stop_callbacks)
raise error
else
var!(instrumented_result) ->
var!(diff) = :erlang.monotonic_time - start
unquote(stop_callbacks)
var!(instrumented_result)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment