SisMaker пре 3 година
родитељ
комит
f764d5b1dd
9 измењених фајлова са 50 додато и 60 уклоњено
  1. +0
    -1
      include/eTpf.hrl
  2. +24
    -38
      src/callgrind/tpCallGrind.erl
  3. +11
    -3
      src/eTpf.erl
  4. +1
    -1
      src/fileHer/tpFReader.erl
  5. +3
    -3
      src/flame/tpFlame.erl
  6. +1
    -1
      src/messages/tpMsgRS.erl
  7. +1
    -1
      src/messages/tpMsgSD.erl
  8. +2
    -2
      src/tracer/tpTracerFile.erl
  9. +7
    -10
      src/tracer/tpTracerLog.erl

+ 0
- 1
include/eTpf.hrl Прегледај датотеку

@ -40,7 +40,6 @@
, fDir => string() %%
, fBaseName => string() %% base file name
, fMaxSize => pos_integer() %%
, fMaxLog => pos_integer() %%
, fMaxMsg => pos_integer() %%
%% tracer for console

+ 24
- 38
src/callgrind/tpCallGrind.erl Прегледај датотеку

@ -1,43 +1,29 @@
-module(tpCallGrind).
-export([patterns/0]).
-export([profile/2]).
-export([profile/3]).
-export([pts/0]).
-export([pfs/2]).
-export([pfm/3]).
-export([profile_many/2]).
-export([profile_many/3]).
%% @todo Add an option with a list of modules to exclude.
-type opts() :: #{
scope => global | per_process, %% Whether we filter the output per process.
running => boolean() %% Whether we compute and save wait times.
scope => global | per_process, %% Whether we filter the output per process.
running => boolean() %% Whether we compute and save wait times.
}.
-record(call, {
%% The MFA for the call.
mfa :: atom(),
%% The source file name.
source :: {string(), pos_integer()},
%% The timestamp for the call.
ts :: pos_integer(),
%% The timestamp for when we last started executing this function.
self_ts :: pos_integer(),
%% Execution time including subcalls.
incl :: undefined | non_neg_integer(),
%% Execution time excluding subcalls.
self = 0 :: integer(),
%% Number of times the function was called.
count = 1 :: pos_integer(),
%% Time when the process was not running in this function.
wait = 0 :: non_neg_integer(),
%% Time when the process was not running in this function or any subcalls.
wait_incl = 0 :: non_neg_integer(),
%% Number of times the process was scheduled out.
wait_count = 0 :: non_neg_integer(),
%% Number of times the function or any subcall was scheduled out.
wait_count_incl = 0 :: non_neg_integer(),
%% Calls done by this MFA.
calls = #{} :: #{atom() => #call{}}
mfa :: atom(), %% The MFA for the call.
source :: {string(), pos_integer()}, %% The source file name.
ts :: pos_integer(), %% The timestamp for the call.
self_ts :: pos_integer(), %% The timestamp for when we last started executing this function.
incl :: undefined | non_neg_integer(), %% Execution time including subcalls.
self = 0 :: integer(), %% Execution time excluding subcalls.
count = 1 :: pos_integer(), %% Number of times the function was called.
wait = 0 :: non_neg_integer(), %% Time when the process was not running in this function.
wait_incl = 0 :: non_neg_integer(), %% Time when the process was not running in this function or any subcalls.
wait_count = 0 :: non_neg_integer(), %% Number of times the process was scheduled out.
wait_count_incl = 0 :: non_neg_integer(), %% Number of times the function or any subcall was scheduled out.
calls = #{} :: #{atom() => #call{}} %% Calls done by this MFA.
}).
-record(proc, {
@ -64,16 +50,16 @@ running => boolean() %% Whether we compute and save wait time
sources = #{} :: #{mfa() => {string(), pos_integer()}}
}).
-spec patterns() -> eTpf:input().
patterns() ->
-spec pts() -> eTpf:input().
pts() ->
[{app, kernel}, {app, stdlib}, {app, looking_glass}].
-spec profile(file:filename_all(), file:filename_all()) -> ok.
profile(Input, Output) ->
profile(Input, Output, #{}).
-spec pfs(file:filename_all(), file:filename_all()) -> ok.
pfs(Input, Output) ->
pfm(Input, Output, #{}).
-spec profile(file:filename_all(), file:filename_all(), opts()) -> ok.
profile(Input, Output, Opts) ->
-spec pfm(file:filename_all(), file:filename_all(), opts()) -> ok.
pfm(Input, Output, Opts) ->
{ok, OutDevice} = file:open(Output, [write]),
State = #state{input = Input, output = Output, output_device = OutDevice, opts = Opts},
write_header(State),

+ 11
- 3
src/eTpf.erl Прегледај датотеку

@ -3,7 +3,9 @@
-include("eTpf.hrl").
-export([
start/0
sts/0
, stl/0
, stf/0
, trace/1
, trace/2
, trace/3
@ -13,16 +15,22 @@
]).
start() ->
sts() ->
trace([{scope, [all]}]).
stl() ->
trace([{scope, [new_processes]}], tpTracerLog).
stf() ->
trace([{scope, [new_processes]}], tpTracerFile).
-spec trace(userInput()) -> ok.
trace(Input) ->
trace(Input, tpTracerShell).
-spec trace(userInput(), module()) -> ok.
trace(Input, TracerMod) ->
trace(Input, TracerMod, undefined, #{}).
trace(Input, TracerMod, #{}, #{}).
-spec trace(userInput(), module(), tracerOpts()) -> ok.
trace(Input, TracerMod, TracerOpts) ->

+ 1
- 1
src/fileHer/tpFReader.erl Прегледај датотеку

@ -11,7 +11,7 @@ fold(Fun, Acc, Filename) ->
Ret.
readEvent(IoDevice, Fun, Acc) ->
case file:read(IoDevice, 32) of
case file:read(IoDevice, 4) of
{ok, <<BinSize:32>>} ->
case file:read(IoDevice, BinSize) of
{ok, Data} ->

+ 3
- 3
src/flame/tpFlame.erl Прегледај датотеку

@ -20,7 +20,7 @@ pfs(InputFile, OutputPath) ->
-spec pfm(file:filename(), filelib:dirname(), file:filename()) -> ok.
pfm(InputFiles, Cwd, OutputPath) ->
PfFiles = filelib:wildcard(InputFiles, Cwd),
PfFiles = lists:sort(filelib:wildcard(InputFiles, Cwd)),
doPfm(PfFiles, #state{outputPath = OutputPath}).
doPfm([], State) ->
@ -29,7 +29,7 @@ doPfm([InputFile | PfFiles], State) ->
{ok, NewState} = tpFReader:fold(fun handleEvent/2, State, InputFile),
doPfm(PfFiles, NewState).
handleEvent({_TraceTag, _Pid, _Ts, _Arg} = Trace, State) ->
handleEvent(Trace, State) ->
Pid = element(2, Trace),
PidState = getPidState(Pid),
NewPidState = doExpInner(Trace, PidState),
@ -213,7 +213,7 @@ mfaf(I) ->
flush(#state{outputPath = OutputPath}) ->
PidStates = get(),
{ok, FH} = file:open(OutputPath, [write, raw, binary, delayed_write]),
io:format("\n\nWriting to ~s for ~w processes... ", [OutputPath, length(PidStates)]),
io:format("\n\nWriting to ~s for ~w processes...", [OutputPath, length(PidStates)]),
[
[
begin

+ 1
- 1
src/messages/tpMsgRS.erl Прегледај датотеку

@ -23,7 +23,7 @@ pfs(InputFile) ->
-spec pfm(file:filename(), filelib:dirname()) -> ok.
pfm(InputFiles, Cwd) ->
PfFiles = filelib:wildcard(InputFiles, Cwd),
PfFiles = lists:sort(filelib:wildcard(InputFiles, Cwd)),
doPfm(PfFiles, #state{}).
doPfm([], State) ->

+ 1
- 1
src/messages/tpMsgSD.erl Прегледај датотеку

@ -20,7 +20,7 @@ pfs(InputFile, Pids) ->
-spec pfm(file:filename(), filelib:dirname(), list()) -> ok.
pfm(InputFiles, Cwd, Pids) ->
PfFiles = filelib:wildcard(InputFiles, Cwd),
PfFiles = lists:sort(filelib:wildcard(InputFiles, Cwd)),
doPfm(PfFiles, #state{pids = preparePids(Pids)}).
doPfm([], State) ->

+ 2
- 2
src/tracer/tpTracerFile.erl Прегледај датотеку

@ -78,9 +78,9 @@ loop(#state{parent = Parent, size = Size, fDir = FDir, fBaseName = FBaseName, io
true ->
MsgListBin = zlib:zip(term_to_binary(NewMsgList)),
MsgListSize = byte_size(MsgListBin),
NewSize = Size + MsgListSize,
ok = file:write(IoDevice, [<<NewSize:32>>, MsgListBin]),
ok = file:write(IoDevice, [<<MsgListSize:32>>, MsgListBin]),
NewSize = Size + MsgListSize,
case NewSize >= MaxSize of
true ->
ok = file:close(IoDevice),

+ 7
- 10
src/tracer/tpTracerLog.erl Прегледај датотеку

@ -21,8 +21,6 @@
, fMaxSize :: infinity | non_neg_integer()
, ioDevice :: file:io_device()
, tcmIsCut = false
, fMaxLog :: pos_integer()
, fLogIndex = 0 :: non_neg_integer()
}).
start_link(Opts) ->
@ -56,13 +54,12 @@ init(Parent, TracerOpts) ->
, fDir = FDir
, fBaseName = FBaseName
, ioDevice = IoDevice
, fMaxSize = maps:get(fMaxSize, TracerOpts, 61644800)
, fMaxLog = maps:get(fMaxLog, TracerOpts, 50000)
, fMaxSize = maps:get(fMaxSize, TracerOpts, 52428800)
, tcmIsCut = TcmIsCut
},
loop(State).
loop(#state{parent = Parent, fDir = FDir, fBaseName = FBaseName, size = Size, ioDevice = IoDevice, fMaxSize = MaxSize, fMaxLog = FMaxLog, fLogIndex = FLogIndex, tcmIsCut = TcmIsCut} = State) ->
loop(#state{parent = Parent, fDir = FDir, fBaseName = FBaseName, size = Size, ioDevice = IoDevice, fMaxSize = MaxSize, tcmIsCut = TcmIsCut} = State) ->
receive
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], State);
@ -70,18 +67,18 @@ loop(#state{parent = Parent, fDir = FDir, fBaseName = FBaseName, size = Size, io
terminate(Reason, State);
RMsg ->
Msg = case TcmIsCut of true -> tpTermCut:cut(RMsg); _ -> RMsg end,
MsgBin = eFmt:format("~w", [Msg]),
MsgBin = eFmt:formatBin("~w\n", [Msg]),
ok = file:write(IoDevice, MsgBin),
NewSize = Size + byte_size(MsgBin),
NewFLogIndex = FLogIndex + 1,
case NewFLogIndex >= FMaxLog orelse NewSize >= MaxSize of
io:format("IMY************** ~p ~p~n", [{NewSize, MaxSize}, MsgBin]),
case NewSize >= MaxSize of
true ->
ok = file:close(IoDevice),
Filename = fileName(FDir, FBaseName),
{ok, NewIoDevice} = file:open(Filename, [write, raw]),
loop(State#state{size = 0, fLogIndex = 0, ioDevice = NewIoDevice});
loop(State#state{size = 0, ioDevice = NewIoDevice});
_ ->
loop(State#state{size = NewSize, fLogIndex = NewFLogIndex})
loop(State#state{size = NewSize})
end
end.

Loading…
Откажи
Сачувај