Permalink
Browse files

improved error message when dot is not avaialble.

  • Loading branch information...
huiqing
huiqing committed Sep 28, 2012
1 parent 3675415 commit 0af1e0f99826dbf14b6d72e0629a200777cae5db
Showing with 45 additions and 22 deletions.
  1. +19 −7 src/percept2_dot.erl
  2. +26 −15 src/percept2_html.erl
View
@@ -10,7 +10,7 @@
%%% --------------------------------%%%
%%% Callgraph Image generation %%%
%%% --------------------------------%%%
--spec(gen_callgraph_img(Pid::pid_value()) -> ok|no_image).
+-spec(gen_callgraph_img(Pid::pid_value()) -> ok|no_image|dot_not_found|gen_svg_failed).
gen_callgraph_img(Pid) ->
Res=ets:select(fun_calltree,
[{#fun_calltree{id = {Pid, '_','_'}, _='_'},
@@ -32,9 +32,7 @@ gen_callgraph_img_1({pid, {P1, P2, P3}}, CallTree) ->
[code:priv_dir(percept2), "server_root",
"images", BaseName++".svg"]),
fun_callgraph_to_dot(CallTree,DotFileName),
- os:cmd("dot -Tsvg " ++ DotFileName ++ " > " ++ SvgFileName),
- file:delete(DotFileName),
- ok.
+ dot_to_svg(DotFileName, SvgFileName).
fun_callgraph_to_dot(CallTree, DotFileName) ->
Edges=gen_callgraph_edges(CallTree),
@@ -175,9 +173,23 @@ gen_process_tree_img(ProcessTrees, CleanPid) ->
[code:priv_dir(percept2), "server_root",
"images", BaseName++".svg"]),
ok=process_tree_to_dot(ProcessTrees,DotFileName, CleanPid),
- os:cmd("dot -Tsvg " ++ DotFileName ++ " > " ++ SvgFileName),
- file:delete(DotFileName),
- ok.
+ dot_to_svg(DotFileName, SvgFileName).
+
+dot_to_svg(DotFileName, SvgFileName) ->
+ case os:find_executable(dot) of
+ false ->
+ dot_not_found;
+ _ ->
+ os:cmd("dot -Tsvg " ++ DotFileName ++ " > " ++ SvgFileName),
+ case filelib:is_file(SvgFileName) of
+ true ->
+ file:delete(DotFileName),
+ ok;
+ false ->
+ gen_svg_failed
+ end
+ end.
+
process_tree_to_dot(ProcessTrees, DotFileName, CleanPid) ->
{Nodes, Edges} = gen_process_tree_nodes_edges(ProcessTrees),
View
@@ -1005,12 +1005,9 @@ process_tree_content(_Env, _Input) ->
%% file already generated, so reuse.
Content;
false ->
- case percept2_dot:gen_process_tree_img() of
- ok ->
- Content;
- no_image ->
- blink_msg("No process tree generated.")
- end
+ GenImgRes=percept2_dot:gen_process_tree_img(),
+ io:format("GenImgRes:\n~p\n", [GenImgRes]),
+ process_gen_graph_img_result(Content, GenImgRes)
end.
%%% function callgraph content
@@ -1186,16 +1183,30 @@ callgraph_time_content(Env, Input) ->
case filelib:is_regular(ImgFullFilePath) of
true -> Content; %% file already generated.
false ->
- case percept2_dot:gen_callgraph_img(Pid) of
- ok ->
- Content;
- no_image ->
- "<div style=\"text-align:center;\">" ++
- "<h3 style=\"text-align:center;\">" ++ pid2html(Pid, CleanPid)++"</h3>"++
- "<blink><center><h3><p>No data generated </p></h3></center><blink>" ++
- "</div>"
- end
+ GenImgRes=percept2_dot:gen_callgraph_img(Pid),
+ process_gen_graph_img_result(Content, GenImgRes)
end.
+
+process_gen_graph_img_result(Content, GenImgRes) ->
+ case GenImgRes of
+ ok ->
+ Content;
+ no_image ->
+ Msg = "No data generated",
+ graph_img_error_page(Msg);
+ dot_not_found ->
+ Msg = "Percept2 cound not find the 'dot' executable from Graphviz; please make sure Graphviz is installed.",
+ graph_img_error_page(Msg);
+ gen_svg_failed ->
+ Msg = "Percept2 failed to use the 'dot' command (from Graphviz) to generate a .svg file.",
+ graph_img_error_page(Msg)
+ end.
+
+graph_img_error_page(Msg) ->
+ "<div style=\"text-align:center;\">" ++
+ "<blink><center><h3><p>" ++ Msg ++ "</p></h3></center><blink>" ++
+ "</div>".
+
calltime_content(Env, Pid)->
CacheKey = "calltime" ++ integer_to_list(erlang:crc32(pid2str(Pid))),

0 comments on commit 0af1e0f

Please sign in to comment.