diff options
author | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
commit | 84adefa331c4159d432d22840663c38f155cd4c1 (patch) | |
tree | bff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/reltool/examples/mnesia_core_dump_viewer | |
download | otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2 otp-84adefa331c4159d432d22840663c38f155cd4c1.zip |
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/reltool/examples/mnesia_core_dump_viewer')
-rwxr-xr-x | lib/reltool/examples/mnesia_core_dump_viewer | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/reltool/examples/mnesia_core_dump_viewer b/lib/reltool/examples/mnesia_core_dump_viewer new file mode 100755 index 0000000000..725637f95b --- /dev/null +++ b/lib/reltool/examples/mnesia_core_dump_viewer @@ -0,0 +1,54 @@ +#!/usr/bin/env escript +%% -*- erlang -*- +%% +%% Pretty print a Mnesia Core Dump +%% +%% core_dump_viewer CoreFile [OutputFile] +%% +%% Status codes: +%% +%% 0 -> Ok +%% 1 -> Bad usage +%% 2 -> Cannot read Mnesia Core file +%% 3 -> Cannot write to file + +-mode(compile). + +main([CoreFile | OptOutputFile]) when CoreFile =/= "--help" -> + %% io:format("Args: ~p\n", [init:get_arguments()]), + case file:read_file(CoreFile) of + {ok, Bin} -> + Core = binary_to_term(Bin), + PrettyCore = io_lib:format("~p\n", [Core]), + PrettyBin = list_to_binary(PrettyCore), + case OptOutputFile of + [OutputFile] -> + case file:write_file(OutputFile, PrettyBin) of + ok -> + ok; + {error, Reason} -> + io:format("<ERROR> Cannot write to file ~p ~p\n", + [OutputFile, Reason]), + halt(3) + end; + [] -> + io:format("~p\n", [Core]), + io:format("ok\n", []), + timer:sleep(timer:seconds(2)), % Poor mans flush of io buffers + init:stop(); + _ -> + usage() + end; + {error, Reason} -> + io:format("<ERROR> Cannot read Mnesia Core file ~p ~p\n", + [CoreFile, Reason]), + halt(2) + end; +main(_BadArgs) -> + usage(). + +usage() -> + FullName = escript:script_name(), + BaseName = filename:basename(FullName), + io:format("usage: ~s CoreFile [OutputFile]\n", [BaseName]), + halt(1). |