@@ -5,10 +5,9 @@ defmodule LiveDebugger.API.TracesStorage do
55 """
66
77 alias LiveDebugger.Structs.Trace
8- alias LiveDebugger.Structs.DiffTrace
98 alias LiveDebugger.CommonTypes
109
11- @ type trace ( ) :: Trace . t ( ) | DiffTrace . t ( )
10+ import Trace , only: [ is_trace: 1 , is_trace_id: 1 ]
1211
1312 @ typedoc """
1413 Pid is used to store mapping to table references.
@@ -21,8 +20,8 @@ defmodule LiveDebugger.API.TracesStorage do
2120
2221 @ callback init ( ) :: :ok
2322 @ callback insert ( Trace . t ( ) ) :: true
24- @ callback insert! ( table_ref :: reference ( ) , trace ( ) ) :: true
25- @ callback get_by_id! ( table_identifier ( ) , trace_id :: integer ( ) ) :: Trace . t ( ) | nil
23+ @ callback insert! ( table_ref :: reference ( ) , Trace . t ( ) ) :: true
24+ @ callback get_by_id! ( table_identifier ( ) , trace_id :: Trace . id ( ) ) :: Trace . t ( ) | nil
2625 @ callback get! ( table_identifier ( ) , opts :: keyword ( ) ) ::
2726 { [ Trace . t ( ) ] , continuation ( ) } | :end_of_table
2827 @ callback clear! ( table_identifier ( ) , node_id :: pid ( ) | CommonTypes . cid ( ) | nil ) :: true
@@ -33,7 +32,6 @@ defmodule LiveDebugger.API.TracesStorage do
3332 @ callback table_size ( table_identifier ( ) ) :: non_neg_integer ( )
3433
3534 defguard is_table_identifier ( id ) when is_pid ( id ) or is_reference ( id )
36- defguard is_trace ( trace ) when is_struct ( trace , Trace ) or is_struct ( trace , DiffTrace )
3735
3836 @ doc """
3937 Initializes ets table.
@@ -45,9 +43,9 @@ defmodule LiveDebugger.API.TracesStorage do
4543 @ doc """
4644 Inserts a new trace into the storage.
4745 It has worse performance then `insert/2` as it has to perform lookup for reference.
48- It stores the trace in table associated with `pid` given in `Trace` struct.
46+ It stores the trace in table associated with `pid` given in trace struct.
4947 """
50- @ spec insert ( trace ( ) ) :: true
48+ @ spec insert ( Trace . t ( ) ) :: true
5149 def insert ( trace ) when is_trace ( trace ) do
5250 impl ( ) . insert ( trace )
5351 end
@@ -57,7 +55,7 @@ defmodule LiveDebugger.API.TracesStorage do
5755 It has better performance then `insert/1` as it does not perform lookup for reference.
5856 In order to use it properly you have to store the reference returned by `get_table/1`.
5957 """
60- @ spec insert! ( table_ref :: reference ( ) , trace ( ) ) :: true
58+ @ spec insert! ( table_ref :: reference ( ) , Trace . t ( ) ) :: true
6159 def insert! ( table_ref , trace ) when is_reference ( table_ref ) and is_trace ( trace ) do
6260 impl ( ) . insert! ( table_ref , trace )
6361 end
@@ -68,9 +66,9 @@ defmodule LiveDebugger.API.TracesStorage do
6866 * `table_id` - PID or reference to an existing table. Using reference increases performance as it skips lookup step.
6967 * `trace_id` - Id of a trace stored in a table.
7068 """
71- @ spec get_by_id! ( table_identifier ( ) , trace_id :: integer ( ) ) :: trace ( ) | nil
69+ @ spec get_by_id! ( table_identifier ( ) , trace_id :: Trace . id ( ) ) :: Trace . t ( ) | nil
7270 def get_by_id! ( table_id , trace_id )
73- when is_table_identifier ( table_id ) and is_integer ( trace_id ) do
71+ when is_table_identifier ( table_id ) and is_trace_id ( trace_id ) do
7472 impl ( ) . get_by_id! ( table_id , trace_id )
7573 end
7674
@@ -90,7 +88,7 @@ defmodule LiveDebugger.API.TracesStorage do
9088 * `:trace_diffs` - Boolean flag to include DiffTrace structs in results
9189 """
9290 @ spec get! ( table_identifier ( ) , opts :: keyword ( ) ) ::
93- { [ trace ( ) ] , continuation ( ) } | :end_of_table
91+ { [ Trace . t ( ) ] , continuation ( ) } | :end_of_table
9492 def get! ( table_id , opts \\ [ ] ) when is_table_identifier ( table_id ) and is_list ( opts ) do
9593 impl ( ) . get! ( table_id , opts )
9694 end
@@ -168,7 +166,7 @@ defmodule LiveDebugger.API.TracesStorage do
168166 @ traces_table_name :lvdbg_traces
169167 @ processes_table_name :lvdbg_traces_processes
170168
171- @ type ets_elem ( ) :: { integer ( ) , TracesStorage . trace ( ) }
169+ @ type ets_elem ( ) :: { integer ( ) , Trace . t ( ) }
172170 @ type continuation ( ) :: TracesStorage . continuation ( )
173171 @ type ets_table_id ( ) :: TracesStorage . ets_table_id ( )
174172 @ type table_identifier ( ) :: TracesStorage . table_identifier ( )
@@ -348,10 +346,10 @@ defmodule LiveDebugger.API.TracesStorage do
348346
349347 # Applies simple case-sensitive substring search on entire struct
350348 @ spec filter_by_search (
351- { [ TracesStorage . trace ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table ,
349+ { [ Trace . t ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table ,
352350 String . t ( )
353351 ) ::
354- { [ TracesStorage . trace ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table
352+ { [ Trace . t ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table
355353 defp filter_by_search ( :end_of_table , _phrase ) , do: :end_of_table
356354 defp filter_by_search ( { traces , cont } , "" ) , do: { traces , cont }
357355
@@ -380,19 +378,19 @@ defmodule LiveDebugger.API.TracesStorage do
380378
381379 # Formats the continuation token and handles end-of-table marker.
382380 @ spec format_response (
383- { [ TracesStorage . trace ( ) ] , continuation ( ) | :searched_without_limit }
381+ { [ Trace . t ( ) ] , continuation ( ) | :searched_without_limit }
384382 | :end_of_table
385383 ) ::
386- { [ TracesStorage . trace ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table
384+ { [ Trace . t ( ) ] , continuation ( ) | :searched_without_limit } | :end_of_table
387385 defp format_response ( :end_of_table ) , do: :end_of_table
388386 defp format_response ( { traces , :"$end_of_table" } ) , do: { traces , :end_of_table }
389387 defp format_response ( { traces , cont } ) , do: { traces , cont }
390388
391389 @ spec limit_response (
392- { [ TracesStorage . trace ( ) ] , :searched_without_limit } | :end_of_table ,
390+ { [ Trace . t ( ) ] , :searched_without_limit } | :end_of_table ,
393391 limit :: pos_integer ( )
394392 ) ::
395- { [ TracesStorage . trace ( ) ] , continuation ( ) } | :end_of_table
393+ { [ Trace . t ( ) ] , continuation ( ) } | :end_of_table
396394 defp limit_response ( :end_of_table , _ ) , do: :end_of_table
397395
398396 defp limit_response ( { traces , :searched_without_limit } , limit ) do
@@ -475,7 +473,7 @@ defmodule LiveDebugger.API.TracesStorage do
475473 [
476474 { { :_ ,
477475 % {
478- __struct__: LiveDebugger.Structs.Trace ,
476+ __struct__: LiveDebugger.Structs.Trace.FunctionTrace ,
479477 function: :"$1" ,
480478 execution_time: :"$2" ,
481479 arity: :"$3" ,
@@ -489,7 +487,7 @@ defmodule LiveDebugger.API.TracesStorage do
489487 [
490488 { { :_ ,
491489 % {
492- __struct__: LiveDebugger.Structs.Trace ,
490+ __struct__: LiveDebugger.Structs.Trace.FunctionTrace ,
493491 function: :"$1" ,
494492 execution_time: :"$2" ,
495493 arity: :"$3" ,
@@ -502,7 +500,7 @@ defmodule LiveDebugger.API.TracesStorage do
502500 [
503501 { { :_ ,
504502 % {
505- __struct__: LiveDebugger.Structs.Trace ,
503+ __struct__: LiveDebugger.Structs.Trace.FunctionTrace ,
506504 function: :"$1" ,
507505 execution_time: :"$2" ,
508506 arity: :"$3"
@@ -513,7 +511,7 @@ defmodule LiveDebugger.API.TracesStorage do
513511 defp maybe_attach_diff_spec ( trace_spec , true ) do
514512 trace_spec ++
515513 [
516- { { :_ , % { __struct__: LiveDebugger.Structs.DiffTrace } } , [ ] , [ :"$_" ] }
514+ { { :_ , % { __struct__: LiveDebugger.Structs.Trace. DiffTrace } } , [ ] , [ :"$_" ] }
517515 ]
518516 end
519517
0 commit comments