Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 103 lines (82 sloc) 3.12 kb
06286ac Added dbg wrapper
Adam Lindberg authored
1 -module(user_default).
2
2f7a03c Added simple profiling function.
Adam authored
3 -export([sync/0]).
4 -export([make/0]).
5 -export([git/1]).
6 -export([reload/0]).
7 -export([reload_then/1]).
06286ac Added dbg wrapper
Adam Lindberg authored
8
9 -export([dbg/0]).
10 -export([dbg/1]).
11 -export([dbg/2]).
12 -export([dbg/3]).
13 -export([dbg/4]).
14
2f7a03c Added simple profiling function.
Adam authored
15 -export([tc_avg/4]).
16
06286ac Added dbg wrapper
Adam Lindberg authored
17 -compile(inline).
9d67443 @JonGretar Inital Import
JonGretar authored
18
81c7692 @andrewtj add reload() and reload_then()
andrewtj authored
19 %% Reload code
20 reload() ->
21 LibExclude = base_lib_path(),
22 Modules = [M || {M, P} <- code:all_loaded(), is_list(P) andalso string:str(P, LibExclude) =:= 0],
23 [shell_default:l(M) || M <- Modules].
24
25 %% Reload code then exec F
26 reload_then(F) ->
27 reload(),
28 F().
9d67443 @JonGretar Inital Import
JonGretar authored
29
30 %% Compiles all files in Emakefile and load into current shell.
31 sync() ->
32 make:all([load]).
33
e9c432f @JonGretar Fixing a comment
JonGretar authored
34 %% Run the make command in shell.
9d67443 @JonGretar Inital Import
JonGretar authored
35 make() ->
36 run_command(["make", "all"]).
37
38 %% Run git command in shell.
39 git(Command) ->
40 CommandList = ["git", Command],
41 run_command(CommandList).
42
06286ac Added dbg wrapper
Adam Lindberg authored
43 dbg() -> dbg:tracer().
44
45 dbg(c) -> dbg:stop_clear();
46 dbg(M) -> dbge({M, '_', '_'}, []).
47
48 dbg(M, c) -> dbgc({M, '_', '_'});
49 dbg(M, r) -> dbge({M, '_', '_'}, dbg_rt());
50 dbg(M, l) -> dbgl({M, '_', '_'}, []);
51 dbg(M, lr) -> dbgl({M, '_', '_'}, dbg_rt());
a516102 Added exceptions in return trace
Adam Lindberg authored
52 dbg(M, F) when is_atom(F) -> dbge({M, F, '_'}, []);
53 dbg(M, O) -> dbge({M, '_', '_'}, O).
06286ac Added dbg wrapper
Adam Lindberg authored
54
55 dbg(M, F, c) -> dbgc({M, F, '_'});
56 dbg(M, F, l) -> dbgl({M, F, '_'}, dbg_rt());
57 dbg(M, F, r) -> dbge({M, F, '_'}, dbg_rt());
58 dbg(M, F, lr) -> dbgl({M, F, '_'}, dbg_rt());
a516102 Added exceptions in return trace
Adam Lindberg authored
59 dbg(M, F, A) when is_integer(A) -> dbge({M, F, A}, []);
60 dbg(M, F, O) -> dbge({M, F, '_'}, O).
06286ac Added dbg wrapper
Adam Lindberg authored
61
62 dbg(M, F, A, c) -> dbgc({M, F, A});
63 dbg(M, F, A, r) -> dbge({M, F, A}, dbg_rt());
64 dbg(M, F, A, l) -> dbgl({M, F, A}, dbg_rt());
65 dbg(M, F, A, lr) -> dbgl({M, F, A}, dbg_rt());
66 dbg(M, F, A, O) -> dbge({M, F, A}, O).
9d67443 @JonGretar Inital Import
JonGretar authored
67
2f7a03c Added simple profiling function.
Adam authored
68 tc_avg(M, F, A, N) when N > 1 ->
69 L = tl(lists:reverse(tc_loop(M, F, A, N, []))),
70 Length = length(L),
71 Min = lists:min(L),
72 Max = lists:max(L),
73 Med = lists:nth(round((Length / 2)), lists:sort(L)),
74 Avg = round(lists:foldl(fun(X, Sum) -> X + Sum end, 0, L) / Length),
75 io:format("Range: ~b - ~b mics~n"
76 "Median: ~b mics~n"
77 "Average: ~b mics~n",
78 [Min, Max, Med, Avg]),
79 Med.
80
81 tc_loop(_M, _F, _A, 0, List) ->
82 List;
83 tc_loop(M, F, A, N, List) ->
84 case timer:tc(M, F, A) of
85 {_T, {'EXIT', Reason}} -> exit(Reason);
86 {T, _Result} -> tc_loop(M, F, A, N - 1, [T|List])
87 end.
88
9d67443 @JonGretar Inital Import
JonGretar authored
89 %%%% Private Functions
90
91 run_command(CommandList) ->
92 Result = os:cmd(string:join(CommandList, " ")),
93 io:format("~s~n", [Result]).
06286ac Added dbg wrapper
Adam Lindberg authored
94
95 dbgc(MFA) -> dbg:ctp(MFA).
96 dbge(MFA, O) -> dbg:tracer(), dbg:p(all, call), dbg:tp(MFA, O).
97 dbgl(MFA, O) -> dbg:tracer(), dbg:p(all, call), dbg:tpl(MFA, O).
a516102 Added exceptions in return trace
Adam Lindberg authored
98 dbg_rt() -> x.
20f34e3 Pulled and merged from JonGretar's master. Updated README.markdown.
Adam Lindberg authored
99
81c7692 @andrewtj add reload() and reload_then()
andrewtj authored
100 base_lib_path() ->
101 KernAppPath = code:where_is_file("kernel.app"),
102 string:substr(KernAppPath, 1, string:str(KernAppPath,"kernel") - 1).
Something went wrong with that request. Please try again.