anchor.diff:  -else.
   md5(Bin) -> crypto:md5(Bin).
   -endif.
  +
  +load_apps([]) ->
  +    ok;
  +load_apps([App | Apps]) ->
  +    case application:load(App) of
  +        ok -> load_apps(Apps);
  +        {error, {already_loaded, basho_bench}} -> load_apps(Apps);
  +        {error, Reason} -> {error, App, Reason}
  +    end.
  
positive.code:     ok = maybe_show_usage(Opts),
      ok = maybe_net_node(Opts),
      ok = maybe_join(Opts),
      BenchName = bench_name(Opts),
      TestDir = test_dir(Opts, BenchName),
  
      %% Load baseline configs
      case application:load(basho_bench) of
          ok -> ok;
          {error, {already_loaded, basho_bench}} -> ok
      end,
      register(basho_bench, self()),
      %% TODO: Move into a proper supervision tree, janky for now
      {ok, _Pid} = basho_bench_config:start_link(),
      basho_bench_config:set(test_id, BenchName),
  
      application:load(lager),
      ConsoleLagerLevel = basho_bench_config:get(log_level, debug),
      ErrorLog = filename:join([TestDir, "error.log"]),
      ConsoleLog = filename:join([TestDir, "console.log"]),
      CrashLog = filename:join([TestDir, "crash.log"]),
      application:set_env(lager,
                          handlers,
                          [{lager_console_backend, ConsoleLagerLevel},
                           {lager_file_backend, [{file, ErrorLog},   {level, error}, {size, 10485760}, {date, "$D0"}, {count, 5}]},
                           {lager_file_backend, [{file, ConsoleLog}, {level, debug}, {size, 10485760}, {date, "$D0"}, {count, 5}]}
                          ]),
      application:set_env(lager, crash_log, CrashLog),
      lager:start(),
  
      application:ensure_all_started(couch),
  
      %% Make sure this happens after starting lager or failures wont
      %% show.
      basho_bench_config:load(Configs),
  
      %% Log level can be overriden by the config files
      CustomLagerLevel = basho_bench_config:get(log_level),
      lager:set_loglevel(lager_console_backend, CustomLagerLevel),
      lager:set_loglevel(lager_file_backend, ConsoleLog, CustomLagerLevel),
  
      %% Init code path
      add_code_paths(basho_bench_config:get(code_paths, [])),
  
      %% If a source directory is specified, compile and load all .erl files found
      %% there.
      case basho_bench_config:get(source_dir, []) of
          [] ->
              ok;
          SourceDir ->
              load_source_files(SourceDir)
      end,
  
      %% Copy the config into the test dir for posterity
      [ begin {ok, _} = file:copy(Config, filename:join(TestDir, filename:basename(Config))) end
        || Config <- Configs ],
      case basho_bench_config:get(distribute_work, false) of 
          true -> setup_distributed_work();
          false -> ok
      end,
      %% Set our CWD to the test dir
      ok = file:set_cwd(TestDir),
      log_dimensions(),
  
      %% Run pre_hook for user code preconditions
      run_pre_hook(),
      %% Spin up the application
      ok = basho_bench_app:start(),
  
      %% Pull the runtime duration from the config and sleep until that's passed OR
      %% the supervisor process exits
      Mref = erlang:monitor(process, whereis(basho_bench_sup)),
      DurationMins = basho_bench_config:get(duration),
      wait_for_stop(Mref, DurationMins).
  
  
  %% ====================================================================
  %% Internal functions
  
negative.code: %% -------------------------------------------------------------------
  -module(basho_bench).
  
  -export([start/0]).
  
  -export([setup_benchmark/1, run_benchmark/1, await_completion/1, main/1, md5/1]).
  -include("basho_bench.hrl").
  
  
  start() ->
      application:ensure_all_started(basho_bench).
  
  %% ====================================================================
  %% API
  %% ====================================================================
  
  setup_benchmark(Opts) ->
      BenchName = bench_name(Opts),
      TestDir = test_dir(Opts, BenchName),
      application:set_env(basho_bench, test_dir, TestDir),
      basho_bench_config:set(test_id, BenchName),
      ConsoleLagerLevel = application:get_env(basho_bench, log_level, debug),
      ErrorLog = filename:join([TestDir, "error.log"]),
      ConsoleLog = filename:join([TestDir, "console.log"]),
      CrashLog = filename:join([TestDir, "crash.log"]),
      % Stop/start lager in order to clear out old lager backend handlers
      % if this is secondary benchmark run.
      ok = application:stop(lager),
      application:set_env(
          lager,
          handlers,
          [
              {lager_console_backend, ConsoleLagerLevel},
              {lager_file_backend, [{file, ErrorLog},   {level, error}, {size, 10485760}, {date, "$D0"}, {count, 5}]},
              {lager_file_backend, [{file, ConsoleLog}, {level, debug}, {size, 10485760}, {date, "$D0"}, {count, 5}]}
          ]
      ),
      application:set_env(lager, crash_log, CrashLog),
      load_apps([lager, basho_bench]),
      lager:start(),
      %% Log level can be overriden by the config files
      CustomLagerLevel = basho_bench_config:get(log_level, debug),
      lager:set_loglevel(lager_console_backend, CustomLagerLevel),
      lager:set_loglevel(lager_file_backend, ConsoleLog, CustomLagerLevel),
      case basho_bench_config:get(distribute_work, false) of 
          true -> setup_distributed_work();
          false -> ok
      end,
      ok.
  
  
  run_benchmark(Configs) ->
      TestDir = application:get_env(basho_bench, test_dir, "./"),
      %% Init code path
      add_code_paths(basho_bench_config:get(code_paths, [])),
  
      %% If a source directory is specified, compile and load all .erl files found
      %% there.
      case basho_bench_config:get(source_dir, []) of
          [] ->
              ok;
          SourceDir ->
              load_source_files(SourceDir)
      end,
  
      %% Make sure this happens after starting lager or failures wont
      %% show.
      basho_bench_config:load(Configs),
  
      %% Copy the config into the test dir for posterity
      [ begin {ok, _} = file:copy(Config, filename:join(TestDir, filename:basename(Config))) end
        || Config <- Configs ],
  
      log_dimensions(),
  
      basho_bench_sup:start_child(),
      ok = basho_bench_stats:run(),
      ok = basho_bench_measurement:run(),
      ok = basho_bench_worker:run(basho_bench_worker_sup:workers()),
      ok = basho_bench_duration:run(),
      application:set_env(basho_bench_app, is_running, true).
  
  
  cli_options() ->
      [
  