Last active
September 4, 2025 04:17
-
-
Save ckampfe/3163210fbfd3f9a6bef3ae2aceef3c74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule PrintDecorator do | |
| use Decorator.Define, print: 1 | |
| def print(trace_name, body, _context) do | |
| quote do | |
| IO.puts("trace_name: #{unquote(trace_name)}") | |
| unquote(body) | |
| end | |
| end | |
| end | |
| defmodule Deftrace do | |
| defmacro __using__(_opts) do | |
| quote do | |
| require Deftrace | |
| import Deftrace | |
| end | |
| end | |
| defmacro deftrace(head, do: body) do | |
| {fun_name, _meta, args} = head | |
| trace_name = "#{inspect(__CALLER__.module)}.#{fun_name}/#{Enum.count(args)}" | |
| quote do | |
| use PrintDecorator | |
| @decorate print(unquote(trace_name)) | |
| def unquote(head) do | |
| unquote(body) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule M do | |
| use Deftrace | |
| deftrace bar(a, b, c) do | |
| a + b + c | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
produces this: