a06c48e2fd41fb073687720a0fc0989db0f6d37b
[beam_stats.git] / src / beam_stats_process.erl
1 -module(beam_stats_process).
2
3 -include("include/beam_stats_process.hrl").
4
5 -export_type(
6 [ t/0
7 , status/0
8 ]).
9
10 -export(
11 [ of_pid/1
12 ]).
13
14 -type status() ::
15 exiting
16 | garbage_collecting
17 | runnable
18 | running
19 | suspended
20 | waiting
21 .
22
23 -define(T, #?MODULE).
24
25 -type t() ::
26 ?T{}.
27
28 -spec of_pid(pid()) ->
29 t().
30 of_pid(Pid) ->
31 Dict = pid_info_exn(Pid, dictionary),
32 ?T
33 { pid = Pid
34 , registered_name = pid_info_opt(Pid, registered_name)
35 , raw_initial_call = pid_info_exn(Pid, initial_call)
36 , otp_initial_call = hope_kv_list:get(Dict, '$initial_call')
37 , otp_ancestors = hope_kv_list:get(Dict, '$ancestors')
38 , status = pid_info_exn(Pid, status)
39 , memory = pid_info_exn(Pid, memory)
40 , total_heap_size = pid_info_exn(Pid, total_heap_size)
41 , stack_size = pid_info_exn(Pid, stack_size)
42 , message_queue_len = pid_info_exn(Pid, message_queue_len)
43 }.
44
45 pid_info_exn(Pid, Key) ->
46 {some, Value} = pid_info_opt(Pid, Key),
47 Value.
48
49 pid_info_opt(Pid, Key) ->
50 case {Key, erlang:process_info(Pid, Key)}
51 of {registered_name, []} -> none
52 ; {_ , {Key, Value}} -> {some, Value}
53 end.
This page took 0.047751 seconds and 3 git commands to generate.