@@ -97,13 +97,14 @@ defmodule LiveDebugger.Services.TraceService do
9797 defp existing_traces_start ( table_id , opts ) do
9898 limit = Keyword . get ( opts , :limit , @ default_limit )
9999 functions = Keyword . get ( opts , :functions , [ ] )
100+ execution_times = Keyword . get ( opts , :execution_times , [ ] )
100101 node_id = Keyword . get ( opts , :node_id )
101102
102103 if limit < 1 do
103104 raise ArgumentError , "limit must be >= 1"
104105 end
105106
106- match_spec = match_spec ( node_id , functions )
107+ match_spec = match_spec ( node_id , functions , execution_times )
107108
108109 table_id
109110 |> ets_table! ( )
@@ -118,36 +119,65 @@ defmodule LiveDebugger.Services.TraceService do
118119 :ets . select ( cont )
119120 end
120121
121- defp match_spec ( node_id , functions ) when is_pid ( node_id ) do
122+ defp match_spec ( node_id , functions , execution_times ) when is_pid ( node_id ) do
122123 [
123124 { { :_ , % { function: :"$1" , execution_time: :"$2" , pid: node_id , cid: nil } } ,
124- to_spec ( functions ) , [ :"$_" ] }
125+ to_spec ( functions , execution_times ) , [ :"$_" ] }
125126 ]
126127 end
127128
128- defp match_spec ( % CID { } = node_id , functions ) do
129- [ { { :_ , % { function: :"$1" , execution_time: :"$2" , cid: node_id } } , to_spec ( functions ) , [ :"$_" ] } ]
129+ defp match_spec ( % CID { } = node_id , functions , execution_times ) do
130+ [
131+ { { :_ , % { function: :"$1" , execution_time: :"$2" , cid: node_id } } ,
132+ to_spec ( functions , execution_times ) , [ :"$_" ] }
133+ ]
134+ end
135+
136+ defp match_spec ( nil , functions , execution_times ) do
137+ [
138+ { { :_ , % { function: :"$1" , execution_time: :"$2" } } , to_spec ( functions , execution_times ) ,
139+ [ :"$_" ] }
140+ ]
141+ end
142+
143+ def to_spec ( [ ] , [ ] ) , do: [ { :"/=" , :"$2" , nil } ]
144+
145+ def to_spec ( functions , [ ] ) do
146+ [ { :andalso , List . first ( functions_to_spec ( functions ) ) , { :"/=" , :"$2" , nil } } ]
130147 end
131148
132- defp match_spec ( nil , functions ) do
133- [ { { :_ , % { function: :"$1 ", execution_time: : "$2"} } , to_spec ( functions ) , [ :"$_" ] } ]
149+ def to_spec ( [ ] , execution_times ) do
150+ [ { :andalso , List . first ( execution_times_to_spec ( execution_times ) ) , { :"/= ", : "$2", nil } } ]
134151 end
135152
136- def to_spec ( [ ] ) , do: [ { :"/=" , :"$2" , nil } ]
153+ def to_spec ( functions , execution_times ) do
154+ [
155+ { :andalso ,
156+ { :andalso , List . first ( functions_to_spec ( functions ) ) ,
157+ List . first ( execution_times_to_spec ( execution_times ) ) } , { :"/=" , :"$2" , nil } }
158+ ]
159+ end
137160
138- def to_spec ( [ single ] ) , do: [ { :andalso , { : "=:=", :"$1" , single } , { :"/=" , :"$2" , nil } } ]
161+ def functions_to_spec ( [ single ] ) , do: [ { :"=:=" , :"$1" , single } ]
139162
140- def to_spec ( [ first , second | rest ] ) do
141- initial_orelse = { :orelse , List . first ( to_spec ( [ first ] ) ) , List . first ( to_spec ( [ second ] ) ) }
163+ def functions_to_spec ( [ first , second | rest ] ) do
164+ initial_orelse =
165+ { :orelse , List . first ( functions_to_spec ( [ first ] ) ) , List . first ( functions_to_spec ( [ second ] ) ) }
142166
143167 result =
144168 Enum . reduce ( rest , initial_orelse , fn x , acc ->
145- { :orelse , acc , List . first ( to_spec ( [ x ] ) ) }
169+ { :orelse , acc , List . first ( functions_to_spec ( [ x ] ) ) }
146170 end )
147171
148172 [ { :andalso , result , { :"/=" , :"$2" , nil } } ]
149173 end
150174
175+ def execution_times_to_spec ( execution_times ) do
176+ min_time = Keyword . get ( execution_times , :exec_time_min , 0 )
177+ max_time = Keyword . get ( execution_times , :exec_time_max , :infinity )
178+ [ { :andalso , { :>= , :"$2" , min_time } , { :"=<" , :"$2" , max_time } } ]
179+ end
180+
151181 @ spec ets_table! ( pid :: ets_table_id ( ) ) :: :ets . table ( )
152182 defp ets_table! ( pid ) when is_pid ( pid ) do
153183 EtsTableServer . table! ( pid )
0 commit comments