`
langzhe
  • 浏览: 292506 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

eprof代码分析工具

阅读更多

清参考http://www.erlang.org/doc/man/eprof.html

 

A Time Profiling Tool for Erlang

主要API  R14B 比R13B提供了更多的API

start/0,

start_profiling/1

stop_profiling/0

profile/2..

analyse/0,

total_analyse/0

log/0

 

 

 23 test(N)->
 24     {ok, Epid}=eprof:start(),  %启动
 25     Pid = spawn(?MODULE, hello, []),
 26     profiling = eprof:start_profiling([Pid]), %启动
 27     test(N,Pid), %执行被分析的程序
 28     eprof:stop_profiling(),
 29 %    eprof:analyse(),
           eprof:log(test), %将分析结果生成文件:
 30     eprof:total_analyse(), %分析结果
 31     eprof:stop(). %停止

 34 test(0,_Pid) ->
 35     ok;
 36 test(N,Pid) ->
 37     send(Pid),
 38     test(N-1,Pid). 
 39 
 40 send(Pid) ->
 41     Pid ! {self(),test},
 42     loop().

51 hello() ->
 52    % Pid1 = spawn(?MODULE, hello1, []),
 53    % loop(),
 54    t(),
 55     %Pid1 ! {self(),test},
 56     receive 
 57         {P,test} ->
 58             P ! returnok,
 59             hello()
 60     end.

61 t() ->
 62     ok.

 66 loop() ->
 67     receive 
 68         T ->
 69             T,                                                                                                                                           
 70             loop()
 71     after 500 ->
 72          timeout
 73     end.
~              

 

 

测试分析结果:

 

7> test_eprof:test(20). 
eprof: Starting profiling ..... 
eprof: Stop profiling
FUNCTION                                       CALLS      TIME 
test_eprof:hello/0                             20         80 % 
test_eprof:t/0                                    20         20 % 

Total time: 0.00
Measurement overhead: 0.00
stopped
8> 

  注意此方法的位置:是在analyse/0和total_analyse前面。否则日志里面没有数据

  log(File) -> ok

Types:

File = atom() | string()

 

This function ensures that the results displayed by analyse/0 and total_analyse/0 are printed both to the file File and the screen

 

 

 

(1)eprof:start_profiling([self()]),分析结果无法搜集到chat:handle_info chat:handle_cast chat:handle_call
(2)eprof:start_profiling([chat]), 分析结果无法搜集到chat:handle_info chat:handle_cast


出现问题的原因:
Sending a message (handled by handle_info) or doing a cast (handled by handle_cast) are both async.
You are stopping the profiler too early.Changing  the order to do the async operations first, then the sync one should  assure that all the requests have been handled before you stop eprof我添加seelp试过,问题搞定!
-module(chat).
-compile(export_all).
%-behaviour(gen_server).
start(N) ->
    start_link(),
    eprof:start(),
    eprof:start_profiling([self()]),
    test(N),
    testcast(),
    test(),
    eprof:stop_profiling(),
    eprof:log(chat),
    eprof:analyse(),
    eprof:total_analyse().

test(N)->
    gen_server:call(?MODULE, {test,N}).
test()->
    chat ! {test,1}.
testcast() ->
    gen_server:cast(?MODULE,castttt).

start_link() ->
    gen_server:start_link({local,?MODULE},?MODULE,[],[]).

init([]) ->
    {ok, {}}.

handle_cast(Msg,State) ->
    tttt(),
    io:format("cast=~p~n",[Msg]),
    {noreply,State}.

handle_call({test,Number},From, State) when is_number(Number) ->
    Reply = Number+1,
    {reply, Reply,State};

handle_call(_,From, State) ->
    Reply = numerror,
    {reply, Reply,State}.
handle_info(Ino,State) ->
    tttt(),
    io:format("info=~p~n",[Ino]),
    {noreply,State}.
tttt() ->
    ok.
 

 

 

0
2
分享到:
评论

相关推荐

    Erlang--性能分析工具之eprof

    **Erlang——性能分析工具之eprof** 在Erlang编程中,优化代码性能是提高系统效率的关键环节。...通过深入学习eprof的使用和源码分析,我们可以更好地理解和优化Erlang程序,从而实现更高效的并发计算。

    eurosys 2012

    Eprof作为一个精细化能源分析工具,不仅为开发者提供了在应用程序开发和调试过程中分析和优化能源消耗的能力,而且有助于学术界和工业界理解智能手机应用程序的能源效率问题。此外,通过公开共享研究成果,该论文还...

    Erlang项目内存泄漏分析方法

    - 使用Erlang提供的各种工具和命令来辅助分析。例如,`observer`工具可以提供关于内存使用和进程状态的直观视图。 - 当使用第三方工具(如appmon,webtool)由于内存不足无法启动时,可以依赖Erlang shell本身提供...

    viewer_cli:在命令行上可视化ErlangElixir节点

    虽然它可能不如专门的剖析工具(如Erlang的`eprof` 或Elixir的`memory_profiler`)强大,但在快速诊断时非常实用。 ### 文件结构 `observer_cli-master` 这个文件名表明这是`observer_cli` 的源码仓库主分支。如果...

Global site tag (gtag.js) - Google Analytics