Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.35 KB | None | 0 0
  1. %% -------------------------------------------------------------------
  2. %% @doc
  3. %% Utility for debugging of applications.
  4. %%
  5. %% Usage:
  6. %%
  7. %% ```
  8. %% 1> osint_dev:debug_app(osint).
  9. %% ...
  10. %% 2> osint_dev:debug_app([osint, jwt]).
  11. %% ...
  12. %% ```
  13. %% @see debug/0
  14. %% @see debug/1
  15. %% @see stop_debug/0
  16. %% @end
  17. %% -------------------------------------------------------------------
  18. -spec debug_app(X) -> ok when
  19.   X :: App | [App, ...],
  20.   App :: atom().
  21.  
  22. debug_app(App) when is_atom(App) ->
  23.   debug_app([App]);
  24.  
  25. debug_app(Apps) when is_list(Apps) ->
  26.   F =
  27.     fun(E, AccIn) ->
  28.       {ok, L} = application:get_key(E, modules),
  29.       L ++ AccIn
  30.     end,
  31.   L = lists:foldl(F, [], Apps),
  32.   io:format("~n[DEBUG] Modules to debugging: ~p~n", [L]),
  33.   debug(L).
  34.  
  35. %% -------------------------------------------------------------------
  36. %% @doc
  37. %% Utility for debugging the `drotr` application.
  38. %%
  39. %% Usage:
  40. %%
  41. %% ```
  42. %% 1> drotr_dev:debug().
  43. %% ```
  44. %% @see debug/1
  45. %% @see stop_debug/0
  46. %% @end
  47. %% -------------------------------------------------------------------
  48. -spec debug() -> ok.
  49.  
  50. debug() ->
  51.   {ok, L} = application:get_key(?APP_NAME, modules),
  52.   io:format("~n[DEBUG] Modules to debugging: ~p~n", [L]),
  53.   debug(L).
  54.  
  55. %% -------------------------------------------------------------------
  56. %% @doc
  57. %% Utility for debugging of modules and/or functions.
  58. %%
  59. %% Usage:
  60. %%
  61. %% ```
  62. %% 1> osint_dev:debug([osint_api_v1, osint_users, osint_net_ws, osint_net_http]).
  63. %% ```
  64. %% @see stop_debug/0
  65. %% @end
  66. %% -------------------------------------------------------------------
  67. -spec debug(L) -> ok when
  68.   L :: [E, ...],
  69.   E :: Module | {Module, Function} | {Module, Function, Arity},
  70.   Module :: atom(),
  71.   Function :: atom(),
  72.   Arity :: non_neg_integer().
  73.  
  74. debug(L) ->
  75.   F =
  76.     fun
  77.       (M) when is_atom(M) ->
  78.         dbg:tp(M, '_', '_', []);
  79.       ({M, F}) when is_atom(M), is_atom(F) ->
  80.         dbg:tp(M, F, '_', []);
  81.       ({M, F, A}) when is_atom(M), is_atom(F), is_integer(A) ->
  82.         dbg:tp(M, F, A, []);
  83.       (_) ->
  84.         ok
  85.     end,
  86.   dbg:tracer(),
  87.   lists:foreach(F, L),
  88.   dbg:p(all, c),
  89.   ok.
  90.  
  91. %% -------------------------------------------------------------------
  92. %% @doc
  93. %% ...
  94. %% @end
  95. %% -------------------------------------------------------------------
  96. -spec stop_debug() -> ok.
  97.  
  98. stop_debug() ->
  99.   dbg:stop_clear().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement