# Help with implementing a macro

**URL:** <https://forum.elixirforum.com/t/help-with-implementing-a-macro/4087>\
**Category:** Questions\
**Tags:** macros, how-to-question\
**Created:** [March 11, 2017, 12:28am UTC](https://forum.elixirforum.com/t/help-with-implementing-a-macro/4087 "2017-03-11T00:28:09Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![wfgilman](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/32/12467_2.png) [@wfgilman](https://forum.elixirforum.com/u/wfgilman)\
**Post date:** [March 12, 2017, 12:06am UTC](https://forum.elixirforum.com/t/help-with-implementing-a-macro/4087/5 "2017-03-12T00:06:02Z")

</div>

Okay, I can see that I have no business writing macros at my level of understanding since I can’t even follow these responses 😂. I was trying to write a module for testing that simulates the `instrument/3` macro in `Phoenix.Endpoint.Instrument` so I can test my instrumenters. The macro should produce the following code:

```
  def instrument(:my_event, compile, runtime, fun) do
    result = MyModule.my_event(:start, compile, runtime)
 
    start = :erlang.monotonic_time()
    try do
      fun.()
    after
      diff = :erlang.monotonic_time() - start
      MyModule.my_event(:stop, diff, result)
    end
  end

```

---

_[View the full topic](https://forum.elixirforum.com/t/help-with-implementing-a-macro/4087)._
