appmon_web.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,037 行 · 第 1/3 页
ERL
1,037 行
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The process information is quite messy tidi it up by creating a %%%% table that looks like key val %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%start_process_proc_data(Proc_data)-> %%Pic out the special cases the links and the process dict {Special,Usual}=split_proc_data(Proc_data), Usual2=append_empty(Usual), UsualProcData=process_proc_data(Usual2,0), SpecProcData=process_proc_data(Special), UsualProcData++SpecProcData.append_empty(List) when length(List) rem 2 == 0 -> List;append_empty(List)-> append_empty(lists:append(List,[empty])).split_proc_data(Proc_data)-> Spec=lists:map(fun(Key)-> case lists:keysearch(Key,1,Proc_data) of {value,Data}-> Data; _ -> not_included end end,[links,dictionary,messages]), Spec2=clear(Spec,[]), Usual=lists:filter(fun({Key,_Val})-> case Key of messages -> false; links -> false; dictionary -> false; _ -> true end end,Proc_data), {Spec2,Usual}. clear([],New)-> New;clear([not_included|Spec],New)-> clear(Spec,New);clear([Other|Spec],New)-> clear(Spec,[Other|New]).process_proc_data(Data,3)-> "</TR>"++process_proc_data(Data,0);process_proc_data([],_N)-> [];process_proc_data(Data,0)-> "<TR>"++process_proc_data(Data,1);process_proc_data([empty|Data],N)-> "<TD> </TD><TD> </TD> "++process_proc_data(Data,N+1);process_proc_data([{current_function,MFA}|Rest],N)-> "<TD NOWRAP=true><FONT SIZE=3><B>Current function:</B></TD><TD><FONT SIZE=3>"++ io_lib:format("~p",[MFA]) ++"</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{error_handler,Mod}|Rest],N)-> "<TD NOWRAP=\"true\"><B><FONT SIZE=3>Error handler:</B></TD><TD><FONT SIZE=3>" ++ atom_to_list(Mod) ++ "</TD>\n" ++ process_proc_data(Rest,N+1);process_proc_data([{group_leader,Grp}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Group leader:</B></TD><TD><FONT SIZE=3>" ++ htmlify_pid(pid_to_list(Grp),[]) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{heap_size,Size}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Heap size:</B></TD><TD><FONT SIZE=3>" ++ integer_to_list(Size) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{initial_call,MFA}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Initial call:</B></TD><TD><FONT SIZE=3>"++ io_lib:format("~p",[MFA]) ++"</TD>\n " ++ process_proc_data(Rest,N+1); process_proc_data([{message_queue_len,Size}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Message queue length:</B></TD><TD><FONT SIZE=3>" ++ integer_to_list(Size) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{priority,Level}|Rest],N)-> "<TD><FONT SIZE=3><B>Process priority:</B></TD><TD><FONT SIZE=3>" ++ atom_to_list(Level) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{reductions,Number}|Rest],N)-> "<TD ><FONT SIZE=3><B>Number of executed reductions:</B></TD> <TD><FONT SIZE=3>" ++ integer_to_list(Number) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{registered_name,Name}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Process Name:</B></TD><TD><FONT SIZE=3>" ++ atom_to_list(Name) ++ "</TD>\n" ++ process_proc_data(Rest,N+1);process_proc_data([{stack_size,Size}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Stack size:</B></TD><TD><FONT SIZE=3>" ++ integer_to_list(Size) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{status,Status}|Rest],N)-> "<TD NOWRAP=\"true\"><FONT SIZE=3><B>Process status:</B></TD><TD><FONT SIZE=3>" ++ atom_to_list(Status) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{trap_exit,Boolean}|Rest],N)-> "<TD NOWRAP=\"true\" ><FONT SIZE=3><B>Trap Exit:</B></TD><TD><FONT SIZE=3>" ++ atom_to_list(Boolean) ++ "</TD>\n " ++ process_proc_data(Rest,N+1);process_proc_data([{Key,Val}|Rest],N)-> "<TD NOWRAP=\"true\" ><FONT SIZE=3><B>" ++ io_lib:write(Key) ++ "</B></TD><TD><FONT SIZE=3>" ++ io_lib:write(Val) ++ "</TD>\n " ++ process_proc_data(Rest,N). process_proc_data([])-> [];process_proc_data([{links,List_of_pids}|Rest])-> "<TR><TD NOWRAP=\"true\"><FONT SIZE=3><B>Links:</B></TD><TD COLSPAN=5><FONT SIZE=3>"++ print_links(List_of_pids) ++"</TD></TR>\n " ++ process_proc_data(Rest);process_proc_data([{messages,Queue}|Rest])-> "<TR><TD NOWRAP=\"true\"><FONT SIZE=3><B>Message Queue:</B></TD><TD COLSPAN=5><FONT SIZE=3>" ++ io_lib:write(Queue) ++ "</TD></TR>\n " ++ process_proc_data(Rest);process_proc_data([{dictionary,Dict}|Rest])-> "<TR><TD NOWRAP=\"true\"><FONT SIZE=3><B>Process dictionary:</B></TD><TD COLSPAN=5><FONT SIZE=3> </TD></TR>\n " ++ get_dictionary_data(Dict) ++ process_proc_data(Rest).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% In the process info there are the links to other processes print %%%% this pid %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%print_links(Pids)-> print_links(Pids,[]). print_links([],Links)-> htmlify_pid(Links,[]);print_links([Pid],Links) when is_pid(Pid) -> print_links([],Links ++ pid_to_list(Pid));print_links([Pid],Links) when is_port(Pid) -> print_links([],Links ++ erlang:port_to_list(Pid));print_links([Pid|Rest],Links) when is_pid(Pid) -> print_links(Rest,Links ++ pid_to_list(Pid) ++ ", ");print_links([Pid|Rest],Links) when is_port(Pid) -> print_links(Rest,Links ++ erlang:port_to_list(Pid) ++ ", ").%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Fix the data in the process dictionary %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%get_dictionary_data([])-> [];get_dictionary_data([{Key,Val}|Dict])-> FormatedVal=add_space(htmlify_pid(lists:flatten(fix_type(Val)),[])), "<TR><TD><FONT SIZE=3>" ++ htmlify_pid(lists:flatten(fix_type(Key)),[]) ++ "</TD><TD COLSPAN=5><FONT SIZE=3>" ++ FormatedVal++ "</TD></TR>\n" ++ get_dictionary_data(Dict).add_space(List)-> add_space(List,0,[]).add_space([],_Len,New) -> lists:reverse(New);add_space([Char|Rest],Len,New)when Len<50 -> add_space(Rest,Len+1,[Char|New]);add_space([$\,|Rest],_Len,New) -> add_space(Rest,0,[$\ ,$,|New]);add_space([Char|Rest],Len,New) -> add_space(Rest,Len+1,[Char|New]).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Interpret the type of the data and make it to a list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fix_type(Val) when is_atom(Val) -> atom_to_list(Val);fix_type(Val) when is_float(Val) -> float_to_list(Val);fix_type(Val) when is_integer(Val) -> integer_to_list(Val);fix_type(Val) when is_list(Val) -> case io_lib:printable_list(Val) of true-> case Val of []-> io_lib:write(Val); _-> Val end; _-> io_lib:write(Val) end;fix_type(Val) when is_pid(Val) -> pid_to_list(Val);fix_type(Val) when is_port(Val) -> erlang:port_to_list(Val);fix_type(Val) when is_tuple(Val) -> io_lib:write(Val);fix_type(_Val) -> [].%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Private functions that send the trace signal to the process %%%% thats the 4 member of the Arg list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%send_trace(Args)when length(Args)>=4-> {_,Proc}=lists:nth(4,Args), Pid2=unurlify_pid(Proc), process_info:send_trace(Pid2); send_trace(_Args)-> arg_error.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Private functions that prints the application environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%application_env_body(Args)when length(Args)>=2 -> App=element(2,lists:nth(1,Args)), Node=element(2,lists:nth(2,Args)), "<SCRIPT> function reload_bottom_frame() {parent.proc_data.location.href=\"/appmon/blank.html\";} </SCRIPT> <BODY BGCOLOR=\"#FFFFFF\" onLoad=reload_bottom_frame()>" ++ application_env_table(App,Node) ++ "</BODY>";application_env_body(_)-> "<BODY BGCOLOR=\"#FFFFFF\">Please dont call this side manually</BODY>".application_env_table(App,Node)-> case process_info:get_application_keys(list_to_atom(App), list_to_atom(Node)) of {ok,List}-> "<TABLE BORDER=1>" ++ application_env_head(App,Node) ++ print_key_list(List,[]) ++ "</TABLE>"; _ -> "Please try again,something went wrong" end.application_env_head(App,Node)-> "<TR BGCOLOR=\"#8899AA\"><TD ALIGN=\"center\" COLSPAN=3> <FONT SIZE=6>" ++ App ++ "@" ++ Node ++ "</FONT>\n </TD></TR> <TR><TD COLSPAN=3> </TD></TR> <TR BGCOLOR=\"#8899AA\"> <TD><B>Key</B></TD><TD><B>Val/Sec. key</B></TD><TD><B>Sec. Val</B></TD> </TR>".print_key_list([],Result)-> Result;print_key_list([{application,Name}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Application name :",Name));print_key_list([{description,Desc}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Description :",Desc));print_key_list([{vsn,Ver}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Version :",Ver));print_key_list([{id,Id}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("ID:",fix_type(Id)));print_key_list([{modules,Mods}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Modules:"," ") ++ print_secondary_list(Mods,[]));print_key_list([{maxP,Max}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Max nr of processes",fix_type(Max)));print_key_list([{maxT,Max}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Max running sec:",fix_type(Max)));print_key_list([{registered,Names}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Registered names:"," ") ++ print_secondary_list(Names,[]));print_key_list([{applications,Apps}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Depends on:"," ") ++ print_secondary_list(Apps,[]));print_key_list([{included_applications,Inc_apps}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Included applications:", fix_type(Inc_apps)));print_key_list([{env,Env}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Environment:",fix_type(Env)));print_key_list([{mod,Mod}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Application callback mod:", fix_type(Mod)));print_key_list([{start_phases,Phase_arg}|Rest],Result)-> print_key_list(Rest,Result ++ print_key("Application callback mod:", fix_type(Phase_arg)));print_key_list([_|Rest],Result)-> print_key_list(Rest,Result).print_key(Label,Val)-> "<TR> <TD><B>" ++ Label ++ "</B></TD><TD>" ++ Val ++ "</TD><TD> </TD> </TR>".print_key2(Label,Val)-> "<TR> <TD> </TD><TD>" ++ Label ++ "</TD><TD>" ++ Val ++ "</TD> </TR>".print_secondary_list([],Result)-> Result;print_secondary_list([{Mod,Ver}|Rest],Result) -> print_secondary_list(Rest,Result ++ print_key2(fix_type(Mod),fix_type(Ver)));print_secondary_list([Mod|Rest],Result) -> print_secondary_list(Rest,Result ++ print_key2(fix_type(Mod)," ")).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?