From 84adefa331c4159d432d22840663c38f155cd4c1 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Fri, 20 Nov 2009 14:54:40 +0000 Subject: The R13B03 release. --- lib/reltool/examples/mnesia_core_dump_viewer | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 lib/reltool/examples/mnesia_core_dump_viewer (limited to 'lib/reltool/examples/mnesia_core_dump_viewer') 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(" 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(" 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). -- cgit v1.2.3