forked from marsleezm/basho_bench
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbasho_bench_app.erl
112 lines (94 loc) · 3.53 KB
/
basho_bench_app.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%% -------------------------------------------------------------------
%%
%% basho_bench: Benchmarking Suite
%%
%% Copyright (c) 2009-2010 Basho Techonologies
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(basho_bench_app).
-behaviour(application).
%% API
-export([start/0,
stop/0,
is_running/0,
halt_or_kill/0]).
%% Application callbacks
-export([start/2, stop/1]).
%% ===================================================================
%% API
%%===================================================================
start() ->
%% Redirect all SASL logging into a text file
case application:get_env(basho_bench,app_run_mode) of
{ok, included} ->
%%Make sure sasl and crypto is available
true=lists:keymember(sasl,1,application:which_applications()),
true=lists:keymember(crypto,1,application:which_applications()),
%% Start up our application
application:start(basho_bench);
NotInc when NotInc == {ok, standalone} orelse NotInc == undefined ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, {file, "log.sasl.txt"}),
%% Make sure crypto is available
ensure_started([sasl, crypto]),
%% Start up our application -- mark it as permanent so that the node
%% will be killed if we go down
application:start(basho_bench, permanent)
end.
stop() ->
application:stop(basho_bench).
is_running() ->
application:get_env(basho_bench_app, is_running) == {ok, true}.
halt_or_kill() ->
%% If running standalone, halt and kill node. Otherwise, just
%% kill top supervisor.
case application:get_env(basho_bench,app_run_mode) of
{ok, included} ->
exit(whereis(basho_bench_sup),kill);
_ ->
init:stop()
end.
%% ===================================================================
%% Application callbacks
%%===================================================================
start(_StartType, _StartArgs) ->
{ok, Pid} = basho_bench_sup:start_link(),
application:set_env(basho_bench_app, is_running, true),
ok = basho_bench_stats:run(),
ok = basho_bench_measurement:run(),
ok = basho_bench_worker:run(basho_bench_sup:workers()),
{ok, Pid}.
stop(_State) ->
%% intentionally left in to show where worker profiling start/stop calls go.
%% eprof:stop_profiling(),
%% eprof:analyze(total),
%% eprof:log("bb.eprof"),
ok.
%% ===================================================================
%% Internal functions
%% ===================================================================
ensure_started(Applications) when is_list(Applications) ->
[ensure_started(Application) || Application <- Applications];
ensure_started(Application) ->
case application:start(Application) of
ok ->
ok;
{error, {already_started, Application}} ->
ok;
Error ->
throw(Error)
end.