File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -16,13 +16,14 @@ defmodule ExProf.Macro do
16
16
"""
17
17
defmacro profile ( do: code ) do
18
18
quote do
19
- pid = spawn_link ( ExProf.Macro , :execute_profile , [ fn -> unquote ( code ) end ] )
19
+ ref = make_ref ( )
20
+ pid = spawn_link ( ExProf.Macro , :execute_profile , [ fn -> unquote ( code ) end , ref ] )
20
21
ExProf . start ( pid )
21
- send pid , self ( )
22
+ send pid , { ref , self ( ) }
22
23
23
24
result =
24
25
receive do
25
- result -> result
26
+ { ^ ref , result } -> result
26
27
end
27
28
28
29
ExProf . stop
@@ -35,10 +36,19 @@ defmodule ExProf.Macro do
35
36
@ doc """
36
37
An internal method for initiating profiling.
37
38
"""
38
- def execute_profile ( func ) do
39
+ def execute_profile ( func , ref ) do
39
40
receive do
40
- sender ->
41
- send sender , func . ( )
41
+ { ^ ref , sender } ->
42
+ send sender , { ref , func . ( ) }
43
+ forward_other_messages ( sender )
44
+ end
45
+ end
46
+
47
+ defp forward_other_messages ( sender ) do
48
+ receive do
49
+ message ->
50
+ send sender , message
51
+ forward_other_messages ( sender )
42
52
end
43
53
end
44
54
end
You can’t perform that action at this time.
0 commit comments