From 45fc18f990ab93bbcce8934f0ba397f3cd87e519 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 25 Oct 2011 13:33:40 -0600 Subject: Add support for -p flag to profile rebar run --- src/rebar.erl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rebar.erl b/src/rebar.erl index a103d29..95f43df 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -67,7 +67,17 @@ run(RawArgs) -> ok = application:load(rebar), %% Parse out command line arguments -- what's left is a list of commands to %% run -- and start running commands - run_aux(parse_args(RawArgs)). + Args = parse_args(RawArgs), + + case rebar_config:get_global(enable_profiling, false) of + true -> + io:format("Profiling!\n"), + fprof:apply(fun(A) -> run_aux(A) end, [Args]), + fprof:profile(), + fprof:analyse(); + _ -> + run_aux(Args) + end. run_aux(["help"]) -> help(), @@ -138,6 +148,10 @@ parse_args(Args) -> GlobalDefines = proplists:get_all_values(defines, Options), rebar_config:set_global(defines, GlobalDefines), + %% Setup profiling flag + rebar_config:set_global(enable_profiling, + proplists:get_bool(profile, Options)), + %% Set global variables based on getopt options set_global_flag(Options, verbose), set_global_flag(Options, force), @@ -268,7 +282,8 @@ option_spec_list() -> {force, $f, "force", undefined, "Force"}, {defines, $D, undefined, string, "Define compiler macro"}, {jobs, $j, "jobs", integer, JobsHelp}, - {config, $C, "config", string, "Rebar config file to use"} + {config, $C, "config", string, "Rebar config file to use"}, + {profile, $p, "profile", undefined, "Profile this run of rebar"} ]. %% -- cgit v1.1