檢視原始碼 tprof (工具 v4.1.1)
程序追蹤分析工具
tprof
提供便利的輔助工具,使用追蹤 BIF 來分析 Erlang 程序。
警告
此模組旨在將
eprof
和cprof
整合為一個統一的 API,以測量呼叫次數、時間和記憶體配置。在 Erlang/OTP 27.0 中屬於實驗性質。
可以分析函數的呼叫次數、函數花費的時間以及函數的堆積記憶體配置。分析可以臨時進行,或者以伺服器輔助模式運行,以便更深入地了解生產環境中運行的程式碼。伺服器輔助模式可以使用預設的 tprof 伺服器或通過start(#{ session => atom() })
啟動的隔離server/0
來運行。
此模組支援三種分析類型
call_count
call_time
call_memory
預設值為 call_count
,它對效能的影響和記憶體佔用最小,但它不支援逐程序分析。因此,以下所有範例都使用 call_memory
,它會測量堆積記憶體配置,並提供更複雜的功能集來演示。
不適合單個機器字的 Erlang 詞彙會配置在程序的堆積記憶體中。例如,返回兩個元素的 tuple 的函數需要在程序的堆積記憶體上配置 tuple。實際消耗為三個字,因為運行時系統還需要一個額外的字來儲存 tuple 的大小。
注意
啟用分析時,程式執行速度會變慢。
為了方便分析,對於某些追蹤模式中未啟用的函數,會累積測量結果。
top_traced_function(...) not_traced_function() bottom_traced_function()
在
not_traced_function
中發生的記憶體配置將會被添加到top_traced_function
的記憶體配置中。但是,在bottom_traced_function
中發生的記憶體配置不會包含在top_traced_function
中。為了僅追蹤每個函數自己的記憶體配置,必須追蹤所有函數。
警告
避免對參與追蹤的模組進行熱碼重新載入。重新載入模組會停用追蹤並捨棄累積的統計資訊。如果分析的程式碼在分析會話期間重新載入,
tprof
的結果可能會不正確。
臨時分析
臨時分析對於分析單個函數呼叫非常方便。
例如
1> tprof:profile(lists, seq, [1, 16], #{type => call_memory}).
****** Process <0.92.0> -- 100.00% of total ***
FUNCTION CALLS WORDS PER CALL [ %]
lists:seq_loop/3 5 32 6.40 [100.00]
32 [ 100.0]
ok
預設情況下,會針對所有模組中的所有函數啟用追蹤。當在互動式 shell 中建立 fun 時,也會追蹤 shell 程式碼的一部分
1> tprof:profile(fun() -> lists:seq(1, 16) end, #{type => call_memory}).
****** Process <0.95.0> -- 100.00% of total ***
FUNCTION CALLS WORDS PER CALL [ %]
erl_eval:do_apply/7 1 3 3.00 [ 3.61]
erl_eval:match_list/6 1 3 3.00 [ 3.61]
lists:reverse/1 1 4 4.00 [ 4.82]
erl_eval:expr_list/7 3 7 2.33 [ 8.43]
erl_eval:ret_expr/3 4 16 4.00 [19.28]
erl_eval:merge_bindings/4 3 18 6.00 [21.69]
lists:seq_loop/3 5 32 6.40 [38.55]
83 [100.0]
ok
但是,可以將追蹤限制為特定的函數或模組
2> tprof:profile(fun() -> lists:seq(1, 16) end,
#{type => call_memory, pattern => [{lists, seq_loop, '_'}]}).
****** Process <0.98.0> -- 100.00% of total ***
FUNCTION CALLS WORDS PER CALL [ %]
lists:seq_loop/3 5 32 6.40 [100.00]
32 [ 100.0]
ok
臨時分析結果可以通過幾種不同的方式列印。以下範例使用定義如下的 test
模組
-module(test).
-export([test_spawn/0]).
test_spawn() ->
{Pid, MRef} = spawn_monitor(fun () -> lists:seq(1, 32) end),
receive
{'DOWN', MRef, process, Pid, normal} ->
done
end.
預設情況下,會顯示每個程序的統計資訊
1> tprof:profile(test, test_spawn, [], #{type => call_memory}).
****** Process <0.176.0> -- 23.66 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
erlang:spawn_monitor/1 1 2 2 [ 9.09]
erlang:spawn_opt/4 1 6 6 [27.27]
test:test_spawn/0 1 14 14 [63.64]
22 [100.0]
****** Process <0.177.0> -- 76.34 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
erlang:apply/2 1 7 7 [ 9.86]
lists:seq_loop/3 9 64 7 [90.14]
71 [100.0]
以下範例會列印所有程序的組合記憶體配置,並按配置的總字數降序排序
2> tprof:profile(test, test_spawn, [],
#{type => call_memory, report => {total, {measurement, descending}}}).
FUNCTION CALLS WORDS PER CALL [ %]
lists:seq_loop/3 9 64 7 [68.82]
test:test_spawn/0 1 14 14 [15.05]
erlang:apply/2 1 7 7 [ 7.53]
erlang:spawn_opt/4 1 6 6 [ 6.45]
erlang:spawn_monitor/1 1 2 2 [ 2.15]
93 [100.0]
也可以收集分析資料以供進一步檢查
3> {done, ProfileData} = tprof:profile(fun test:test_spawn/0,
#{type => call_memory, report => return}).
<...>
4> tprof:format(tprof:inspect(ProfileData, process, {percent, descending})).
****** Process <0.223.0> -- 23.66 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
test:test_spawn/0 1 14 14 [63.64]
erlang:spawn_opt/4 1 6 6 [27.27]
erlang:spawn_monitor/1 1 2 2 [ 9.09]
22 [100.0]
****** Process <0.224.0> -- 76.34 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
lists:seq_loop/3 9 64 7 [90.14]
erlang:apply/2 1 7 7 [ 9.86]
71 [100.0]
分析的程序取決於分析類型。
call_count
(預設) 會計算所有程序中的呼叫次數。call_time
和call_memory
會將分析限制為由使用者提供的函數衍生的程序(使用trace:process/4
的set_on_spawn
選項)。
call_time
和 call_memory
可以限制為分析單個程序
2> tprof:profile(test, test_spawn, [],
#{type => call_memory, set_on_spawn => false}).
****** Process <0.183.0> -- 100.00 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
erlang:spawn_monitor/1 1 2 2 [ 9.09]
erlang:spawn_opt/4 1 6 6 [27.27]
test:test_spawn/0 1 14 14 [63.64]
Erlang 程式可以在與原始程序不同的程序中執行昂貴的操作。您可以在測量時間或記憶體時,將多個、新的或甚至所有程序包含在追蹤中
7> pg:start_link().
{ok,<0.252.0>}
8> tprof:profile(fun() -> pg:join(group, self()) end,
#{type => call_memory, rootset => [pg]}).
****** Process <0.252.0> -- 52.86 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
pg:leave_local_update_ets/5 1 2 2 [ 1.80]
gen:reply/2 1 3 3 [ 2.70]
erlang:monitor/2 1 3 3 [ 2.70]
gen_server:try_handle_call/4 1 3 3 [ 2.70]
gen_server:try_dispatch/4 1 3 3 [ 2.70]
maps:iterator/1 2 4 2 [ 3.60]
maps:take/2 1 6 6 [ 5.41]
pg:join_local_update_ets/5 1 8 8 [ 7.21]
pg:handle_info/2 1 8 8 [ 7.21]
pg:handle_call/3 1 9 9 [ 8.11]
gen_server:loop/7 2 9 4 [ 8.11]
ets:lookup/2 2 10 5 [ 9.01]
pg:join_local/3 1 11 11 [ 9.91]
pg:notify_group/5 2 16 8 [14.41]
erlang:setelement/3 2 16 8 [14.41]
111 [100.0]
****** Process <0.255.0> -- 47.14 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
erl_eval:match_list/6 1 3 3 [ 3.03]
erlang:monitor/2 1 3 3 [ 3.03]
lists:reverse/1 2 4 2 [ 4.04]
pg:join/3 1 4 4 [ 4.04]
erl_eval:add_bindings/2 1 5 5 [ 5.05]
erl_eval:do_apply/7 2 6 3 [ 6.06]
gen:call/4 1 8 8 [ 8.08]
erl_eval:expr_list/7 4 10 2 [10.10]
gen:do_call/4 1 16 16 [16.16]
erl_eval:ret_expr/3 4 16 4 [16.16]
erl_eval:merge_bindings/4 3 24 8 [24.24]
99 [100.0]
預設情況下,分析時間沒有限制。對於臨時分析,可以設定時間限制。如果被分析的函數在該時間到期之前沒有返回,則該程序會被終止,原因為 kill
。使用者提供的函數啟動的任何未連結的子程序都會保留;開發人員有責任處理這些程序。
9> tprof:profile(timer, sleep, [100000], #{timeout => 1000}).
預設情況下,任何時間點只允許一個臨時或伺服器輔助分析會話。可以強制多個臨時會話同時進行,但開發人員有責任確保追蹤模式不會重疊
1> tprof:profile(fun() -> lists:seq(1, 32) end,
#{registered => false, pattern => [{lists, '_', '_'}]}).
伺服器輔助分析
伺服器輔助分析可以在正在運行的系統上進行。為此,請啟動 tprof
伺服器,然後在系統處理實際流量時新增追蹤模式和要追蹤的程序。可以隨時提取、檢查和列印資料。以下範例會追蹤 Kernel supervisor 監督的所有程序的活動
1> tprof:start(#{type => call_memory}).
{ok,<0.200.0>}
2> tprof:enable_trace({all_children, kernel_sup}).
34
3> tprof:set_pattern('_', '_' , '_').
16728
4> Sample = tprof:collect().
{call_memory,
[{gen_server,try_dispatch,4,[{<0.154.0>,2,6}]},
{erlang,iolist_to_iovec,1,[{<0.161.0>,1,8}]},
<...>
5 > tprof:format(tprof:inspect(Sample)).
****** Process <0.154.0> -- 14.21 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
maps:iterator/1 2 4 2 [15.38]
gen_server:try_dispatch/4 2 6 3 [23.08]
net_kernel:handle_info/2 2 16 8 [61.54]
26 [100.0]
****** Process <0.161.0> -- 85.79 % of total allocations ***
FUNCTION CALLS WORDS PER CALL [ %]
disk_log:handle/2 2 2 1 [ 1.27]
disk_log_1:maybe_start_timer/1 1 3 3 [ 1.91]
disk_log_1:mf_write_cache/1 1 3 3 [ 1.91]
<...>
可以分析整個正在運行的系統,然後檢查個別程序
1> tprof:start(#{type => call_memory}).
2> tprof:enable_trace(all), tprof:set_pattern('_', '_' , '_').
9041
3> timer:sleep(10000), tprof:disable_trace(all), Sample = tprof:collect().
{call_memory,
[{user_drv,server,3,[{<0.64.0>,12,136}]},
{user_drv,contains_ctrl_g_or_ctrl_c,1,[{<0.64.0>,80,10}]},
<...>
4> Inspected = tprof:inspect(Sample, process, measurement), Shell = maps:get(self(), Inspected).
{call_memory, 2743,
[{shell,{enc,0},1,2,2,0.07291286912139992},
<...>
5> tprof:format(Shell).
FUNCTION CALLS WORDS PER CALL [ %]
<...>
erl_lint:start/2 2 300 150 [10.94]
shell:used_records/1 114 342 3 [12.47]
摘要
類型
程序識別碼 (pid) 或已註冊的程序名稱。
指定 Module
的單個函數的已檢查資料。
臨時分析器選項;請參閱 profile/4
。
單個程序的分析,或多個程序的組合分析,按選定的欄位排序。
tprof 伺服器。
從追蹤 BIF 中提取的原始資料。
按模組名稱分組的追蹤函數(及其元數),如果追蹤所有程式碼,則為 all
。
用於啟用所選程序分析的選項;請參閱 enable_trace/2
。
tprof 伺服器將執行的分析類型。
函數
停用與提供的模式相符的追蹤函數。
與 clear_pattern(Mod, Fun, Arity)
等效,但使用提供的 Server
。
傳回目前追蹤對應的統計資訊。
與 collect/0
等效,但使用提供的 Server
。
恢復先前暫停的分析。
與 continue/0
等效,但使用提供的 Server
。
停止累積指定程序的追蹤。
類似於 trace:process/4
,但支援更多方便追蹤的選項。
與 enable_trace/2
等效,但使用提供的 Server
。
格式化用 inspect/3
轉換的分析資料,輸出到預設輸出裝置。
格式化用 inspect/3
轉換的分析資料,輸出到裝置 IoDevice
。
傳回模組名稱對應至函數及其元數的對應。
與 get_trace_map/0
等效,但使用提供的 Server
。
將追蹤 BIF 傳回的原始資料轉換為方便後續分析和格式化的形式。
暫停目前所有追蹤函數的追蹤收集,保留現有追蹤。
與 pause/0
等效,但使用提供的 Server
。
對呼叫 Fun()
執行臨時分析。
對呼叫 apply(Module, Function, Args)
執行臨時分析。
清除累積的分析,如果已暫停,則開始分析。
與 restart/0
等效,但使用提供的 Server
。
啟用與提供的模式相符的所有函數的追蹤。
與 set_pattern/3
等效,但使用提供的 Server
。
與 start(#{})
等效。
啟動未受監督的伺服器。
與 start_link(#{})
等效。
與 start/1
等效,但也會將分析伺服器連結到呼叫端。
停止預設 tprof
伺服器並停用由伺服器啟用的追蹤。
與 stop/0
等效,但使用提供的 Server
。
類型
-type column() :: module | function | calls | measurement | measurement_per_call | percent.
要通過 inspect/3
或 profile/4
排序的欄位。
module
- 模組名稱。function
- 函式名稱。calls
- 函式被呼叫的次數。measurement
- 所有函式呼叫的總計量測值 (呼叫次數、時間或堆積記憶體配置)。measurement_per_call
- 每次函式呼叫的平均量測值 (呼叫次數、時間或堆積記憶體配置)。percent
- 在整個分析收集期間,量測值佔總量的百分比。
程序識別碼 (pid) 或已註冊的程序名稱。
-type profile_line() :: {module(), Function :: {atom(), arity()}, Count :: pos_integer(), Measurement :: pos_integer(), MeasurementPerCall :: non_neg_integer(), Percent :: float()}.
指定 Module
的單個函數的已檢查資料。
-type profile_options() :: #{type => trace_type(), timeout => timeout(), pattern => trace_pattern() | [trace_pattern()], set_on_spawn => boolean(), rootset => rootset(), report => return | process | total | {process, sort_by()} | {total, sort_by()}, device => io:device()}.
臨時分析器選項;請參閱 profile/4
。
-type profile_result() :: {trace_type(), TotalMeasurement :: non_neg_integer(), [profile_line()]}.
單個程序的分析,或多個程序的組合分析,按選定的欄位排序。
-type rootset() :: [process()] | all | existing | new.
-type server() :: pid() | tprof.
tprof 伺服器。
每個伺服器使用單獨的 trace:session/0
以保持分析隔離。
-type start_options() :: #{type => trace_type(), session => atom()}.
-type trace_info() :: {module(), Fun :: atom(), Arity :: non_neg_integer(), [{pid(), Count :: pos_integer(), Measurement :: pos_integer()}]}.
從追蹤 BIF 中提取的原始資料。
按模組名稱分組的追蹤函數(及其元數),如果追蹤所有程式碼,則為 all
。
-type trace_options() :: #{set_on_spawn => boolean()}.
用於啟用所選程序分析的選項;請參閱 enable_trace/2
。
-type trace_type() :: call_count | call_time | call_memory.
tprof 伺服器將執行的分析類型。
- call_count - 計算函式被呼叫的次數。這是一個全域分析事件,無法限制在特定程序中。更多詳細資訊請參閱 call_count 在
trace:function/4
中的說明。 - call_time - 計算函式中花費的累計時間。更多詳細資訊請參閱 call_time 在
trace:function/4
中的說明。 - call_memory - 計算函式中配置的累計記憶體。更多詳細資訊請參閱 call_memory 在
trace:function/4
中的說明。
函式
停用與提供的模式相符的追蹤函數。
1> tprof:set_pattern(lists, seq, '_').
2
2> tprof:clear_pattern(lists, seq, 3).
1
3> tprof:get_trace_map().
#{lists => [{seq,2}]}
需要已啟動
預設的 tprof
伺服器。
與 clear_pattern(Mod, Fun, Arity)
等效,但使用提供的 Server
。
-spec collect() -> {trace_type(), [trace_info()]}.
傳回目前追蹤對應的統計資訊。
-spec collect(server()) -> {trace_type(), [trace_info()]}.
與 collect/0
等效,但使用提供的 Server
。
-spec continue() -> ok | not_paused.
恢復先前暫停的分析。
-spec continue(server()) -> ok | not_paused.
與 continue/0
等效,但使用提供的 Server
。
-spec disable_trace(Spec) -> non_neg_integer() when Spec :: pid() | all | new | existing | {children | all_children, process()}; ([process()]) -> non_neg_integer() | {non_neg_integer(), [process()]}.
-spec disable_trace(Spec, trace_options()) -> non_neg_integer() when Spec :: pid() | all | new | existing | {children | all_children, process()}; ([process()], trace_options()) -> non_neg_integer() | {non_neg_integer(), [process()]}.
停止累積指定程序的追蹤。
有關選項的描述,請參閱 enable_trace/2
。
在從追蹤清單中移除程序之前累積的分析數據會被保留。這使得可以為系統中的許多或所有程序啟用追蹤,休眠一小段時間,然後為所有程序停用追蹤(以避免系統過載),但保留分析數據。
-spec disable_trace(server(), Spec, trace_options()) -> non_neg_integer() when Spec :: pid() | all | new | existing | {children | all_children, process()}; (server(), [process()], trace_options()) -> non_neg_integer() | {non_neg_integer(), [process()]}.
-spec enable_trace(Spec) -> non_neg_integer() when Spec :: pid() | all | new | existing | {children | all_children, process()}; ([process()]) -> non_neg_integer() | {non_neg_integer(), [process()]}.
-spec enable_trace(Spec, trace_options()) -> Traced :: non_neg_integer() when Spec :: pid() | all | new | existing; (Spec, trace_options()) -> Traced :: non_neg_integer() | {Traced :: non_neg_integer(), Failed :: [process()]} when Spec :: [process()] | {children | all_children, process()}.
類似於 trace:process/4
,但支援更多方便追蹤的選項。
call_count
分析器不支援每個程序的追蹤。
Spec
要嘛是本地程序的程序識別符 (pid),要嘛是下列原子之一,或是本地程序識別符或其註冊名稱的清單
all
- 所有目前存在的程序以及未來將建立的所有程序。existing
- 所有目前存在的程序。new
- 所有未來將建立的程序。children
- 所有目前執行且由指定程序直接產生的程序。此模式有助於追蹤單一監督者的工作程序。all_children
- 所有目前執行且由指定程序產生的程序,或其任何遞迴後代。此模式旨在方便追蹤監督樹。
傳回啟用追蹤的程序數。
當使用 pid 清單、children
或 all_children
時,也會傳回追蹤啟用失敗的程序。如果程序在啟用追蹤之前已終止,則可能無法啟用追蹤。
注意
分析伺服器不會追蹤已新增至追蹤集合的程序。允許停止分析伺服器(清除任何累積的數據)、重新啟動伺服器、設定完全不同的追蹤模式,並保留已追蹤程序的清單以供將來使用。使用
disable_trace(Processes)
清除已追蹤程序的清單。
指定 Options
以修改追蹤行為
set_on_spawn
- 自動開始追蹤由已追蹤程序產生的程序。預設為開啟。
-spec enable_trace(server(), Spec, trace_options()) -> non_neg_integer() when Spec :: pid() | all | new | existing | {children | all_children, process()}; (server(), [process()], trace_options()) -> non_neg_integer() | {non_neg_integer(), [process()]}.
與 enable_trace/2
等效,但使用提供的 Server
。
-spec format(profile_result() | #{pid() | all => profile_result()}) -> ok.
格式化用 inspect/3
轉換的分析資料,輸出到預設輸出裝置。
-spec format(io:device(), profile_result() | #{pid() | all => profile_result()}) -> ok.
格式化用 inspect/3
轉換的分析資料,輸出到裝置 IoDevice
。
-spec get_trace_map() -> trace_map().
傳回模組名稱對應至函數及其元數的對應。
與 get_trace_map/0
等效,但使用提供的 Server
。
-spec inspect({trace_type(), [trace_info()]}) -> #{all => profile_result()}.
與 inspect(Profile, process, percent)
等效。
將原始分析轉換為程序識別符的對應,其中包含配置的單字總數,以及依配置百分比升序排序的所有追蹤函式清單。
-spec inspect(Profile :: {trace_type(), [trace_info()]}, Type :: process | total, SortBy :: sort_by()) -> #{pid() | all => profile_result()}.
將追蹤 BIF 傳回的原始資料轉換為方便後續分析和格式化的形式。
當
Type
引數為process
時,此函式會傳回程序識別符的對應,其中包含按所選欄位排序的對應分析結果。當
Type
引數為total
或使用call_count
分析時,此函式會傳回具有單一all
金鑰的對應,其中包含來自所有程序的分析結果。
可以利用檢視的分析數據來列印分析結果。
-spec pause() -> ok | not_running.
暫停目前所有追蹤函數的追蹤收集,保留現有追蹤。
使用 continue/0
來恢復追蹤收集。
-spec pause(server()) -> ok | not_running.
與 pause/0
等效,但使用提供的 Server
。
-spec profile(fun(() -> term())) -> ok | {term(), [trace_info()]}.
與 profile(Fun, #{})
等效。
-spec profile(fun(() -> term()), profile_options()) -> ok | {term(), {trace_type(), [trace_info()]}}.
對呼叫 Fun()
執行臨時分析。
預設情況下,結果會格式化輸出到輸出裝置;使用 report
選項來變更此行為。
臨時(Ad-hoc)分析會啟動一個新的 tprof
伺服器實例,執行分析常式,提取結果,然後關閉伺服器。
請參閱 profile/4
以取得支援的選項列表。
-spec profile(module(), Fun :: atom(), Args :: [term()]) -> ok | {term(), {trace_type(), [trace_info()]}}.
-spec profile(module(), Fun :: atom(), Args :: [term()], profile_options()) -> ok | {term(), {trace_type(), [trace_info()]}}.
對呼叫 apply(Module, Function, Args)
執行臨時分析。
預設情況下,結果會格式化輸出到輸出裝置;使用 report
選項來變更此行為。
臨時(Ad-hoc)分析會啟動一個新的 tprof
伺服器實例,執行分析常式,提取結果,然後關閉伺服器。
臨時分析器支援以下 Options
type
- 要執行的分析類型。device
- 指定將分析資料列印到的 I/O 裝置。用於將文字輸出重新導向到主控台或standard_error
非常有用。pattern
- 指定要啟用的追蹤模式,或追蹤模式列表。預設情況下,會追蹤所有函式 ({'_', '_', '_'}
)。report
- 控制輸出格式。預設值為process
;印出每個程序分析數據,並依總配置的百分比排序。指定report => return
以抑制列印,並取得原始數據以使用inspect/3
進行進一步評估,並使用format/2
進行格式化。rootset
- 在追蹤列表中包含額外的程序。對於分析gen_server
的配置、呼叫,或其他由跨程序通訊引起的配置非常有用。請參閱 此範例。set_on_spawn
- 自動開始追蹤由被追蹤的程序所產生的程序。預設啟用。timeout
- 在指定的時間量(毫秒)後終止分析。
-spec restart() -> ok.
清除累積的分析,如果已暫停,則開始分析。
-spec restart(server()) -> ok.
與 restart/0
等效,但使用提供的 Server
。
-spec set_pattern(module(), atom(), arity() | '_') -> ok | {error, {trace_pattern, trace_pattern()}}.
啟用與提供的模式相符的所有函數的追蹤。
模式是累加的,遵循與 trace:function/4
相同的規則。傳回符合所提供模式的函式數量。
1> tprof:set_pattern(lists, seq, '_').
2
2> tprof:set_pattern(lists, keyfind, 3).
1
3> tprof:get_trace_map().
#{lists => [{keyfind,3},{seq,2},{seq,3}]}
如果沒有函式符合模式,則會傳回 error
元組
> tprof:set_pattern(no_module, func, '_').
{error,{trace_pattern,no_module,func,'_'}}
需要已啟動
預設的 tprof
伺服器。
-spec set_pattern(server(), module(), atom(), arity() | '_') -> ok | {error, {trace_pattern, trace_pattern()}}.
與 set_pattern/3
等效,但使用提供的 Server
。
-spec start() -> {ok, Server} | {error, Reason} when Server :: server(), Reason :: {already_started, pid()}.
與 start(#{})
等效。
-spec start(Config :: start_options()) -> {ok, Server} | {error, Reason} when Server :: server(), Reason :: {already_started, pid()}.
啟動未受監督的伺服器。
分析伺服器儲存目前的追蹤模式,並擁有用於分析的 追蹤工作階段。
如果 Config
中未提供 session
,則會使用名為 tprof
的預設工作階段,並且分析伺服器會 註冊為 tprof
。
如果 Config
中提供了 session
,則會建立具有該名稱的工作階段,並且所有分析都會在該工作階段內完成。在這種情況下,分析伺服器不會註冊。像這樣使用 tprof
時,需要將此函式傳回的 pid/0
提供給此模組中的函式。
-spec start_link() -> {ok, Server} | {error, Reason} when Server :: server(), Reason :: {already_started, pid()}.
與 start_link(#{})
等效。
-spec start_link(Config :: start_options()) -> {ok, Server} | {error, Reason} when Server :: server(), Reason :: {already_started, pid()}.
與 start/1
等效,但也會將分析伺服器連結到呼叫端。
-spec stop() -> ok.
停止預設 tprof
伺服器並停用由伺服器啟用的追蹤。
-spec stop(server()) -> ok.
與 stop/0
等效,但使用提供的 Server
。