Utility for reporting running and loaded OTP applications

Jay Nelson jay@REDACTED
Sat Mar 20 02:01:43 CET 2010


Thought I would share this little function for
reporting the loaded applications.  I find it
helpful when testing or starting up a node
to see whether all the code is included.

-spec report_applications() -> ok.

report_applications() ->
     ColSizes = [15, 10, 35],
     FmtStr =
	lists:flatten(
	  io_lib:format("  ~~-~ws ~~-~ws  ~~-~ws~~n",
			ColSizes)),

     RunningApps = application:which_applications(),
     LoadedApps = application:loaded_applications(),

     report_applications("Running Applications:", FmtStr,
			ColSizes, RunningApps),
     report_applications("Loaded Applications:", FmtStr,
			ColSizes, LoadedApps -- RunningApps).


-spec report_applications(string(), string(),
			  [pos_integer(),...],
			  list({atom(), [any()], [any()]})
			 ) -> ok.

report_applications(Title, ColumnFmt, ColSizes, Apps) ->
     io:format("~n~s~n~n", [Title]),
     io:format(ColumnFmt,
	      ["Application","  Version","  Description"]),
     io:format(ColumnFmt,
	      [lists:duplicate(Count, $-)
	       || Count <- ColSizes]),
     [io:format(ColumnFmt, [App, Version, Desc])
      || {App, Desc, Version} <- Apps],
     io:format("~n").



It also shows a little format string trickery.
Hopefully the email client wrapping will not
mess up the code.

jay



More information about the erlang-questions mailing list