diff options
author | Henrik Nord <[email protected]> | 2011-09-06 15:27:22 +0200 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2011-09-06 15:29:35 +0200 |
commit | 684f1b321c8c4d07edee23737e178976af051913 (patch) | |
tree | 320f69cbd3cf279dfaf30a86e6b4099ba57549c0 /lib/runtime_tools/src/ttb_autostart.erl | |
parent | e7af9a6004cc13f1c49c4b6304adc9b8cd859cba (diff) | |
parent | 7e2c8763c225dc16f98cc5746fa141b970a6aaf3 (diff) | |
download | otp-684f1b321c8c4d07edee23737e178976af051913.tar.gz otp-684f1b321c8c4d07edee23737e178976af051913.tar.bz2 otp-684f1b321c8c4d07edee23737e178976af051913.zip |
Merge branch 'pd/ttb-cleanup' into major
OTP-9430
OTP-9403
OTP-9431
Diffstat (limited to 'lib/runtime_tools/src/ttb_autostart.erl')
-rw-r--r-- | lib/runtime_tools/src/ttb_autostart.erl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/runtime_tools/src/ttb_autostart.erl b/lib/runtime_tools/src/ttb_autostart.erl new file mode 100644 index 0000000000..4c6971c119 --- /dev/null +++ b/lib/runtime_tools/src/ttb_autostart.erl @@ -0,0 +1,55 @@ +%%%------------------------------------------------------------------- +%%% File : ttb_autostart.erl +%%% Author : Bartłomiej Puzoń <[email protected]> +%%% Description : This supervisor is used to resume ttb tracing +%%% Users are able to provide custom restart modules for *_config, as +%%% file:write/read/delete may not be possible on diskless nodes. +%%% +%%% Created : 31 Jul 2010 by <[email protected]> +%%%------------------------------------------------------------------- +-module(ttb_autostart). + +-behaviour(gen_server). + +%% API +-export([start_link/0, + read_config/0, + write_config/1, + delete_config/0]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-define(DEF_AUTOSTART_MODULE, ?MODULE). +-define(AUTOSTART_FILENAME, "ttb_autostart.bin"). + +start_link() -> + gen_server:start_link(?MODULE, no_args, []). + +delete_config() -> + file:delete(?AUTOSTART_FILENAME). + +read_config() -> + case file:read_file(?AUTOSTART_FILENAME) of + {ok, Data} -> {ok, binary_to_term(Data)}; + Error -> Error + end. + +write_config(Data) -> + file:write_file(?AUTOSTART_FILENAME, term_to_binary(Data)). + +init(no_args) -> + case application:get_env(runtime_tools, ttb_autostart_module) of + {ok, _} -> ok; + undefined -> application:set_env(runtime_tools, ttb_autostart_module, ?DEF_AUTOSTART_MODULE) + end, + observer_backend:ttb_resume_trace(), + %%As the process is not needed any more, it will shut itself down + {ok, no_args, 10000}. + +handle_call(_,_,_) -> {noreply, no_args}. +handle_cast(_,_) -> {noreply, no_args}. +handle_info(timeout,_) -> {stop, normal, no_args}. +terminate(_,_) -> ok. +code_change(_,_,_) -> {ok, no_args}. |