From affb8238c0103dcc1e9ffd52c295894e6c747709 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Thu, 20 May 2021 23:43:50 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++---- include/eTpf.hrl | 2 + rebar.config | 8 +-- src/{profile => callgrind}/tpCallgrind.erl | 0 src/eTpf_sup.erl | 2 +- src/{profile => fileHer}/tpFileReader.erl | 0 src/{profile => flame}/tpFlame.erl | 0 src/{profile => messages}/tpMessages.erl | 4 +- .../tpMessagesSeqdiag.erl | 4 +- src/profile/tpRabbitHole.erl | 59 ------------------- src/{profile => tracer}/tpFileTracer.erl | 0 .../tpRawConsoleTracer.erl | 0 src/{profile => tracer}/tpSocketTracer.erl | 0 src/{profile => tracer}/tpTracer.erl | 0 src/{profile => tracer}/tpTracerPool.erl | 0 src/utils/tpMsgHole.erl | 42 +++++++++++++ src/{profile => utils}/tpSocketClient.erl | 0 src/{profile => utils}/tpTerm.erl | 0 18 files changed, 67 insertions(+), 78 deletions(-) create mode 100644 include/eTpf.hrl rename src/{profile => callgrind}/tpCallgrind.erl (100%) rename src/{profile => fileHer}/tpFileReader.erl (100%) rename src/{profile => flame}/tpFlame.erl (100%) rename src/{profile => messages}/tpMessages.erl (98%) rename src/{profile => messages}/tpMessagesSeqdiag.erl (98%) delete mode 100644 src/profile/tpRabbitHole.erl rename src/{profile => tracer}/tpFileTracer.erl (100%) rename src/{profile => tracer}/tpRawConsoleTracer.erl (100%) rename src/{profile => tracer}/tpSocketTracer.erl (100%) rename src/{profile => tracer}/tpTracer.erl (100%) rename src/{profile => tracer}/tpTracerPool.erl (100%) create mode 100644 src/utils/tpMsgHole.erl rename src/{profile => utils}/tpSocketClient.erl (100%) rename src/{profile => utils}/tpTerm.erl (100%) diff --git a/README.md b/README.md index 9b84859..c51d7a9 100644 --- a/README.md +++ b/README.md @@ -212,14 +212,14 @@ end. 当出于分析目的而跟踪文件时,您很可能不关心某些事件,例如链接的进程。要禁用任何不必要的事件分析,请传递mode选项: ``` -1> lg:trace('_', lg_file_tracer, "traces.lz4", #{mode => profile}). +1> lg:trace('_', lg_file_tracer, "traces.lz4", #{mode => utils}). ``` [[tracing_running]] 您还可以通过启用选项来获得仅对配置文件有用的额外事件。 该running选项将启用事件,这些事件指示何时安排进出流程。 启用它通常会很有用,因为它可以启用其他统计信息,但会占用大量资源,因此默认情况下未启用: ``` -1> lg:trace('_', lg_file_tracer, "traces.lz4", #{mode => profile, running => true}). +1> lg:trace('_', lg_file_tracer, "traces.lz4", #{mode => utils, running => true}). ``` [[tracing_send]] @@ -241,7 +241,7 @@ events_per_frame。这两个选项使您可以控制文件写入或旋转的频 以下示例将文件大小限制为100MB: ``` -1> eTpf:trace('_', lg_file_tracer, #{filename_prefix => "traces.lz4", max_size => 100000000}, #{mode => profile, running =>true}). +1> eTpf:trace('_', lg_file_tracer, #{filename_prefix => "traces.lz4", max_size => 100000000}, #{mode => utils, running =>true}). ``` 在测试此功能期间,目前实施的轮换似乎很昂贵,因此您应注意不要设置太低的值。 @@ -267,16 +267,16 @@ $ qcachegrind callgrind.out 它将自动检测并打开所有与该callgrind.out.*模式匹配的文件。 -Profiling one file 您可以通过调用函数来分析一个文件 `tpCallgrind:profile/2,3`。它包含跟踪文件名,输出文件名和一个可选的选项映射: +Profiling one file 您可以通过调用函数来分析一个文件 `tpCallgrind:utils/2,3`。它包含跟踪文件名,输出文件名和一个可选的选项映射: ``` -1> tpCallgrind:profile("traces.lz4.1", "callgrind.out.1"). +1> tpCallgrind:utils("traces.lz4.1", "callgrind.out.1"). ``` 它还接受以下选项: ``` -1> tpCallgrind:profile("traces.lz4.1", "callgrind.out.1", #{running => true}). +1> tpCallgrind:utils("traces.lz4.1", "callgrind.out.1", #{running => true}). ``` Profiling many files 便利功能可用于一次分析许多文件:`tpCallgrind:profile_many/2,3`, 它以通配符模式作为第一个参数,并以文件名前缀作为第二个参数: @@ -351,7 +351,7 @@ eTpf只负责提供输出,然后可以使用常规工具(不附带)将其 要分析一个文件: ``` -1> lg_flame:profile("traces.lz4.1", "output"). +1> lg_flame:utils("traces.lz4.1", "output"). ``` 这将创建一个名为'output'的中间文件。 @@ -377,9 +377,9 @@ eTpf也可以根据它们发送的消息来分析Erlang进程。它可以帮助 然后,一个跟踪会话的输出可用于callgrind和消息概要分析。 -分析一个文件 您可以通过调用函数来分析一个文件 lg_messages:profile/1。它使用跟踪文件名并打印出分析结果。 +分析一个文件 您可以通过调用函数来分析一个文件 lg_messages:utils/1。它使用跟踪文件名并打印出分析结果。 -1> lg_messages:profile("traces.lz4.1"). +1> lg_messages:utils("traces.lz4.1"). 它还将创建一个GraphViz文件,当前将其硬编码为“ digraph.gv”,并打印使用说明。 @@ -468,7 +468,7 @@ edge [arrowhead=none, labelfontsize=12.0, minlen=3]; 要查看一个文件: ``` -1> lg_messages_seqdiag:profile("traces.lz4.1", +1> lg_messages_seqdiag:utils("traces.lz4.1", ["<7788.381.0>", "<7788.382.0>", "<7774.383.0>", "<7774.384.0>", "<7774.386.0>"]). ``` @@ -509,9 +509,9 @@ Glass将不可避免地将此消息记录在跟踪文件中,识别出目标为 当然,该过程仅在Looking Glass运行时可用,这意味着我们不能直接发送消息。以下作品: -is_pid(whereis(lg)) andalso (lg ! Info). 当然,这可以做成一个宏: +is_pid(whereis('$eTpfHole')) andalso ('$eTpfHole' ! Info). 当然,这可以做成一个宏: -%%启用消息跟踪时,将元数据存储在跟踪文件中。 -define(LG_INFO(Info), is_pid(whereis(lg)) andalso (lg ! Info)). 然后可以这样使用: +%%启用消息跟踪时,将元数据存储在跟踪文件中。 -define(LG_INFO(Info), is_pid(whereis('$eTpfHole')) andalso ('$eTpfHole' ! Info)). 然后可以这样使用: ?LG_INFO(#{process_type => reader}). 该消息必须始终是地图。否则,将无法读取跟踪文件。process_type在对消息交换进行概要分析时,Looking Glass仅识别该字段, 并将其用作标签来标识进程。您可以自由定义地图中需要的任何其他值。 diff --git a/include/eTpf.hrl b/include/eTpf.hrl new file mode 100644 index 0000000..bed3620 --- /dev/null +++ b/include/eTpf.hrl @@ -0,0 +1,2 @@ +%% Ignore Msg Hole Name +-define(eTpfHole, '$eTpfHole'). \ No newline at end of file diff --git a/rebar.config b/rebar.config index 8bf43ca..869a923 100644 --- a/rebar.config +++ b/rebar.config @@ -10,7 +10,7 @@ {apps, [eTpf]} ]}. -{pre_hooks, - [{"", compile, "escript c_src/eNpc compile"}]}. -{post_hooks, - [{"", clean, "escript c_src/eNpc clean"}]}. +% {pre_hooks, +% [{"", compile, "escript c_src/eNpc compile"}]}. +% {post_hooks, +% [{"", clean, "escript c_src/eNpc clean"}]}. diff --git a/src/profile/tpCallgrind.erl b/src/callgrind/tpCallgrind.erl similarity index 100% rename from src/profile/tpCallgrind.erl rename to src/callgrind/tpCallgrind.erl diff --git a/src/eTpf_sup.erl b/src/eTpf_sup.erl index 0387937..8950e3f 100644 --- a/src/eTpf_sup.erl +++ b/src/eTpf_sup.erl @@ -31,5 +31,5 @@ start_link() -> init([]) -> SupFlags = #{strategy => one_for_one, intensity => 5, period => 10}, - ChildSpecs = [?ChildSpec(tpRabbitHole, worker)], + ChildSpecs = [?ChildSpec(tpMsgHole, worker)], {ok, {SupFlags, ChildSpecs}}. \ No newline at end of file diff --git a/src/profile/tpFileReader.erl b/src/fileHer/tpFileReader.erl similarity index 100% rename from src/profile/tpFileReader.erl rename to src/fileHer/tpFileReader.erl diff --git a/src/profile/tpFlame.erl b/src/flame/tpFlame.erl similarity index 100% rename from src/profile/tpFlame.erl rename to src/flame/tpFlame.erl diff --git a/src/profile/tpMessages.erl b/src/messages/tpMessages.erl similarity index 98% rename from src/profile/tpMessages.erl rename to src/messages/tpMessages.erl index 796d5d8..696ef9f 100644 --- a/src/profile/tpMessages.erl +++ b/src/messages/tpMessages.erl @@ -14,6 +14,8 @@ -module(tpMessages). +-include("eTpf.hrl"). + -export([profile/1]). -export([profile_many/1]). @@ -42,7 +44,7 @@ profile_many(Wildcard) -> %% @todo Later we may want to look at the latency of gen_server call/reply. %% @todo Later we may want to look at particular messages, have some sort of callback. -handle_event({send, From, _, Info, lg}, State = #state{meta = Meta0}) -> +handle_event({send, From, _, Info, ?eTpfHole}, State = #state{meta = Meta0}) -> Meta = case Meta0 of #{From := Info0} -> Meta0#{From => maps:merge(Info0, Info)}; _ -> Meta0#{From => Info} diff --git a/src/profile/tpMessagesSeqdiag.erl b/src/messages/tpMessagesSeqdiag.erl similarity index 98% rename from src/profile/tpMessagesSeqdiag.erl rename to src/messages/tpMessagesSeqdiag.erl index 37b4f54..0841570 100644 --- a/src/profile/tpMessagesSeqdiag.erl +++ b/src/messages/tpMessagesSeqdiag.erl @@ -14,6 +14,8 @@ -module(tpMessagesSeqdiag). +-include("eTpf.hrl"). + -export([profile/2]). -export([profile_many/2]). @@ -38,7 +40,7 @@ profile_many(Wildcard, Pids) -> end, #state{pids = prepare_pids(Pids)}, Files), flush(FinalState). -handle_event({send, From, _, Info, lg}, State = #state{meta = Meta0}) -> +handle_event({send, From, _, Info, ?eTpfHole}, State = #state{meta = Meta0}) -> Meta = case Meta0 of #{From := Info0} -> Meta0#{From => maps:merge(Info0, Info)}; _ -> Meta0#{From => Info} diff --git a/src/profile/tpRabbitHole.erl b/src/profile/tpRabbitHole.erl deleted file mode 100644 index 6be97f4..0000000 --- a/src/profile/tpRabbitHole.erl +++ /dev/null @@ -1,59 +0,0 @@ -%% Copyright (c) 2017-Present Pivotal Software, Inc. All rights reserved. -%% -%% This package, Looking Glass, is double-licensed under the Mozilla -%% Public License 1.1 ("MPL") and the Apache License version 2 -%% ("ASL"). For the MPL, please see LICENSE-MPL-RabbitMQ. For the ASL, -%% please see LICENSE-APACHE2. -%% -%% This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, -%% either express or implied. See the LICENSE file for specific language governing -%% rights and limitations of this software. -%% -%% If you have any questions regarding licensing, please contact us at -%% info@rabbitmq.com. - -%% The purpose of this process is to be the target of messages -%% sent by traced processes. The messages contain metadata that -%% we want to log when we are tracing and later use when profiling -%% the sending of messages. This process does not need them, it -%% just needs to exist, and therefore it discards everything. - --module(tpRabbitHole). --behaviour(gen_server). - -%% API. --export([start_link/0]). - -%% gen_server. --export([init/1]). --export([handle_call/3]). --export([handle_cast/2]). --export([handle_info/2]). --export([terminate/2]). --export([code_change/3]). - -%% API. - --spec start_link() -> {ok, pid()}. -start_link() -> - gen_server:start_link({local, lg}, ?MODULE, [], []). - -%% gen_server. - -init([]) -> - {ok, undefined}. - -handle_call(_Request, _From, State) -> - {reply, ignored, State}. - -handle_cast(_Msg, State) -> - {noreply, State}. - -handle_info(_Info, State) -> - {noreply, State}. - -terminate(_Reason, _State) -> - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. diff --git a/src/profile/tpFileTracer.erl b/src/tracer/tpFileTracer.erl similarity index 100% rename from src/profile/tpFileTracer.erl rename to src/tracer/tpFileTracer.erl diff --git a/src/profile/tpRawConsoleTracer.erl b/src/tracer/tpRawConsoleTracer.erl similarity index 100% rename from src/profile/tpRawConsoleTracer.erl rename to src/tracer/tpRawConsoleTracer.erl diff --git a/src/profile/tpSocketTracer.erl b/src/tracer/tpSocketTracer.erl similarity index 100% rename from src/profile/tpSocketTracer.erl rename to src/tracer/tpSocketTracer.erl diff --git a/src/profile/tpTracer.erl b/src/tracer/tpTracer.erl similarity index 100% rename from src/profile/tpTracer.erl rename to src/tracer/tpTracer.erl diff --git a/src/profile/tpTracerPool.erl b/src/tracer/tpTracerPool.erl similarity index 100% rename from src/profile/tpTracerPool.erl rename to src/tracer/tpTracerPool.erl diff --git a/src/utils/tpMsgHole.erl b/src/utils/tpMsgHole.erl new file mode 100644 index 0000000..3a6428c --- /dev/null +++ b/src/utils/tpMsgHole.erl @@ -0,0 +1,42 @@ +-module(tpMsgHole). +-behaviour(gen_srv). + +-include("eTpf.hrl"). + +% 此过程的目的是成为跟踪过程发送的消息的目标。消息包含我们要在跟踪时记录的元数据,并在分析消息的发送时稍后使用。 +% 这个过程不需要它们,它只需要存在就可以了,因此它丢弃了所有东西。 + +-export([ + start_link/0 +]). + +-export([ + init/1 + , handleCall/3 + , handleCast/2 + , handleInfo/2 + , terminate/2 + , code_change/3 +]). + +-spec start_link() -> {ok, pid()}. +start_link() -> + gen_srv:start_link({local, ?eTpfHole}, ?MODULE, [], []). + +init(_Args) -> + {ok, undefined}. + +handleCall(_Msg, _State, _FROM) -> + {reply, ignored}. + +handleCast(_Msg, _State) -> + kpS. + +handleInfo(_Msg, _State) -> + kpS. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. diff --git a/src/profile/tpSocketClient.erl b/src/utils/tpSocketClient.erl similarity index 100% rename from src/profile/tpSocketClient.erl rename to src/utils/tpSocketClient.erl diff --git a/src/profile/tpTerm.erl b/src/utils/tpTerm.erl similarity index 100% rename from src/profile/tpTerm.erl rename to src/utils/tpTerm.erl