okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61dad0e
main
1%% Count payload decodes on the preparation caller without production metrics. 2- module ( albedo_lcm_preparation_test_support ). 3- export ([ count_decodes / 2 ]). 4 5count_decodes ( Owner , Run ) -> 6Processes = lists : usort ([ self (), Owner ]), 7Patterns = [{ albedo_conversation , unpack , 2 }, { albedo_conversation , unpack_fit , 2 }], 8Tracer = spawn ( fun () -> collect ( 0 , none ) end ), 9lists : foreach ( fun ( Pattern ) -> erlang : trace_pattern ( Pattern , true , [ local ]) end , Patterns ), 10lists : foreach ( fun ( Pid ) -> erlang : trace ( Pid , true , [ call , { tracer , Tracer }]) end , Processes ), 11try 12Value = Run (), 13Tracer ! { count , self (), Processes }, 14receive { decode_count , Count } -> { Value , Count } end 15after 16lists : foreach ( fun ( Pid ) -> erlang : trace ( Pid , false , [ call ]) end , Processes ), 17lists : foreach ( fun ( Pattern ) -> erlang : trace_pattern ( Pattern , false , [ local ]) end , Patterns ), 18exit ( Tracer , kill ) 19end . 20 21%% The tracer drains its own delivery markers before answering. Keep call 22%% tracing enabled until the markers arrive, so queued events are retained. 23collect ( Count , Finish ) -> 24receive 25{ trace , _ , call , { albedo_conversation , Function , [ _ , _ ]}} 26when Function =:= unpack ; Function =:= unpack_fit -> 27collect ( Count + 1 , Finish ); 28{ count , Reply , Processes } -> 29Refs = [ erlang : trace_delivered ( Pid ) || Pid <- Processes ], 30collect ( Count , { Reply , Refs }); 31{ trace_delivered , _ , Ref } -> 32{ Reply , Refs } = Finish , 33case lists : delete ( Ref , Refs ) of 34[] -> Reply ! { decode_count , Count }, collect ( Count , none ); 35Pending -> collect ( Count , { Reply , Pending }) 36end ; 37_ -> collect ( Count , Finish ) 38end .