X-Git-Url: https://git.xandkar.net/?p=beam_stats.git;a=blobdiff_plain;f=src%2Fbeam_stats_process.erl;h=5dc64d7676262a32a8fd5c3ac75e2719621f3a27;hp=ab6d1c2658413945c40d6e6abb936ace975080fb;hb=39ff67a62324705869d1ee364e98b17d14e70438;hpb=3088c08bcb23e8f0dbd991974d381af8a4e3b10c diff --git a/src/beam_stats_process.erl b/src/beam_stats_process.erl index ab6d1c2..5dc64d7 100644 --- a/src/beam_stats_process.erl +++ b/src/beam_stats_process.erl @@ -11,7 +11,7 @@ ]). -export( - [ of_pid/1 + [ of_pid/2 , get_best_known_origin/1 , print/1 ]). @@ -42,26 +42,35 @@ %% Public API %% ============================================================================ --spec of_pid(pid()) -> - t(). -of_pid(Pid) -> - Dict = pid_info_exn(Pid, dictionary), - Ancestry = - #beam_stats_process_ancestry - { raw_initial_call = pid_info_exn(Pid, initial_call) - , otp_initial_call = hope_kv_list:get(Dict, '$initial_call') - , otp_ancestors = hope_kv_list:get(Dict, '$ancestors') - }, - ?T - { pid = Pid - , registered_name = pid_info_opt(Pid, registered_name) - , ancestry = Ancestry - , status = pid_info_exn(Pid, status) - , memory = pid_info_exn(Pid, memory) - , total_heap_size = pid_info_exn(Pid, total_heap_size) - , stack_size = pid_info_exn(Pid, stack_size) - , message_queue_len = pid_info_exn(Pid, message_queue_len) - }. +-spec of_pid(pid(), beam_stats_delta:t()) -> + none % when process is dead + | {some, t()} % when process is alive + . +of_pid(Pid, DeltasServer) -> + try + Dict = pid_info_exn(Pid, dictionary), + Ancestry = + #beam_stats_process_ancestry + { raw_initial_call = pid_info_exn(Pid, initial_call) + , otp_initial_call = hope_kv_list:get(Dict, '$initial_call') + , otp_ancestors = hope_kv_list:get(Dict, '$ancestors') + }, + T = + ?T + { pid = Pid + , registered_name = pid_info_opt(Pid, registered_name) + , ancestry = Ancestry + , status = pid_info_exn(Pid, status) + , memory = pid_info_exn(Pid, memory) + , total_heap_size = pid_info_exn(Pid, total_heap_size) + , stack_size = pid_info_exn(Pid, stack_size) + , message_queue_len = pid_info_exn(Pid, message_queue_len) + , reductions = pid_info_reductions(Pid, DeltasServer) + }, + {some, T} + catch throw:{process_dead, _} -> + none + end. -spec print(t()) -> ok. @@ -70,15 +79,16 @@ print( { pid = Pid , registered_name = RegisteredNameOpt , ancestry = #beam_stats_process_ancestry - { raw_initial_call = InitialCallRaw - , otp_initial_call = InitialCallOTPOpt - , otp_ancestors = AncestorsOpt + { raw_initial_call = InitialCallRaw + , otp_initial_call = InitialCallOTPOpt + , otp_ancestors = AncestorsOpt } , status = Status , memory = Memory , total_heap_size = TotalHeapSize , stack_size = StackSize , message_queue_len = MsgQueueLen + , reductions = Reductions }=T ) -> BestKnownOrigin = get_best_known_origin(T), @@ -95,6 +105,7 @@ print( "TotalHeapSize : ~p~n" "StackSize : ~p~n" "MsgQueueLen : ~p~n" + "Reductions : ~p~n" "~n", [ Pid , BestKnownOrigin @@ -107,6 +118,7 @@ print( , TotalHeapSize , StackSize , MsgQueueLen + , Reductions ] ). @@ -114,14 +126,25 @@ print( %% Private helpers %% ============================================================================ +-spec pid_info_reductions(pid(), beam_stats_delta:t()) -> + non_neg_integer(). +pid_info_reductions(Pid, DeltasServer) -> + case beam_stats_delta:of_process_info_reductions(DeltasServer, Pid) + of {some, Reductions} -> + Reductions + ; none -> + throw({process_dead, Pid}) + end. + pid_info_exn(Pid, Key) -> {some, Value} = pid_info_opt(Pid, Key), Value. pid_info_opt(Pid, Key) -> - case {Key, erlang:process_info(Pid, Key)} + case {Key, beam_stats_source:erlang_process_info(Pid, Key)} of {registered_name, []} -> none ; {_ , {Key, Value}} -> {some, Value} + ; {_ , undefined} -> throw({process_dead, Pid}) end. %% ============================================================================