aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-16 07:36:21 +0200
committerBjörn Gustavsson <[email protected]>2015-04-22 10:12:32 +0200
commita5d724cf240ac8770c7b465c65c7b50d6583c057 (patch)
treebc34e128008877976043700a30538f3c09dafdc5 /lib/compiler
parentf4c7080ba83ff5df0c57d8b517563e6106b8a994 (diff)
downloadotp-a5d724cf240ac8770c7b465c65c7b50d6583c057.tar.gz
otp-a5d724cf240ac8770c7b465c65c7b50d6583c057.tar.bz2
otp-a5d724cf240ac8770c7b465c65c7b50d6583c057.zip
compile: Add the {eprof,Pass} option for easy eprof running
To run eprof for a compiler pass: erlc +'{eprof,beam_asm}' file.erl The name of the compiler pass is the name as printed when 'time' option is used. It is usually, but not always, the module name for the compiler pass.
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/compile.erl29
-rw-r--r--lib/compiler/test/compile_SUITE.erl2
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index f4ef6fcebf..0b021073db 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -285,11 +285,20 @@ internal_comp(Passes, File, Suffix, St0) ->
St1 = St0#compile{filename=File, dir=Dir, base=Base,
ifile=erlfile(Dir, Base, Suffix),
ofile=objfile(Base, St0)},
- Run = case member(time, St1#compile.options) of
- true ->
- io:format("Compiling ~tp\n", [File]),
- fun run_tc/2;
- false -> fun({_Name,Fun}, St) -> catch Fun(St) end
+ Opts = St1#compile.options,
+ Run0 = case member(time, Opts) of
+ true ->
+ io:format("Compiling ~tp\n", [File]),
+ fun run_tc/2;
+ false -> fun({_Name,Fun}, St) -> catch Fun(St) end
+ end,
+ Run = case keyfind(eprof, 1, Opts) of
+ {eprof,EprofPass} ->
+ fun(P, St) ->
+ run_eprof(P, EprofPass, St)
+ end;
+ false ->
+ Run0
end,
case fold_comp(Passes, Run, St1) of
{ok,St2} -> comp_ret_ok(St2);
@@ -331,6 +340,16 @@ run_tc({Name,Fun}, St) ->
[Name,(After_c-Before_c) / 1000,Mem]),
Val.
+run_eprof({Name,Fun}, Name, St) ->
+ io:format("~p: Running eprof\n", [Name]),
+ eprof:start_profiling([self()]),
+ Val = (catch Fun(St)),
+ eprof:stop_profiling(),
+ eprof:analyze(),
+ Val;
+run_eprof({_,Fun}, _, St) ->
+ catch Fun(St).
+
comp_ret_ok(#compile{code=Code,warnings=Warn0,module=Mod,options=Opts}=St) ->
case werror(St) of
true ->
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 1c96abe017..6d4fde662b 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -102,6 +102,8 @@ file_1(Config) when is_list(Config) ->
?line compile_and_verify(Simple, Target, [debug_info]),
?line {ok,simple} = compile:file(Simple, [no_line_info]), %Coverage
+ {ok,simple} = compile:file(Simple, [{eprof,beam_z}]), %Coverage
+
?line ok = file:set_cwd(Cwd),
?line true = exists(Target),
?line passed = run(Target, test, []),