-
Notifications
You must be signed in to change notification settings - Fork 191
/
profile_ex.erl
55 lines (47 loc) · 1.58 KB
/
profile_ex.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%%%-------------------------------------------------------------------
%%% @author Martin Logan <martinjlogan@erlware.org>
%%% @copyright (C) 2009, Martin Logan
%%% @doc simple demonstration of profiling functionalty
%%% @end
%%%-------------------------------------------------------------------
-module(profile_ex).
%% API
-export([run/0, run_with_fprof/0]).
%%%===================================================================
%%% API
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc start the system and ouput fprof stats to a file
%% @spec () -> ok
%% @end
%%--------------------------------------------------------------------
run_with_fprof() ->
fprof:trace(start),
run(),
timer:sleep(5000),
fprof:trace(stop),
fprof:profile(),
fprof:analyse({dest, atom_to_list(?MODULE)}).
%%--------------------------------------------------------------------
%% @doc start two nearly identical running processes
%% @spec () -> ok
%% @end
%%--------------------------------------------------------------------
run() ->
spawn(fun() -> looper(1000) end),
spawn(fun() -> funner(1000) end).
%%%===================================================================
%%% Internal functions
%%%===================================================================
looper(0) ->
ok;
looper(N) ->
integer_to_list(N),
looper(N - 1).
funner(N) ->
funner(fun(N_) -> integer_to_list(N_) end, N).
funner(_Fun, 0) ->
ok;
funner(Fun, N) ->
Fun(N),
funner(Fun, N - 1).