Permalink
Browse files

Merge branch 'master' of github.com:massemanet/eper

Conflicts:
	src/redbug.erl
  • Loading branch information...
2 parents 0c1ad06 + 54830b9 commit a0fa4706eda942cee26053655f487f1334f8c15d mats cronqvist committed Jan 27, 2011
View
@@ -46,7 +46,7 @@ trc(Filename,Fun,Acc) ->
fold(Filename,Fun,Acc,Opts) ->
Type = take_first(Opts,[line,sax,xml,term,trc]),
case file:open(Filename, [read, raw, binary]) of
- {ok, FD} ->
+ {ok, FD} ->
try fold(read(FD),FD,wrap(Fun,Type),chunker(Type),?state(Acc,?tail_0()))
after file:close(FD)
end;
@@ -68,7 +68,7 @@ term_f(Fun) ->
catch {parsing_failed,R} -> ?log([{parse_error,R},{string,TermBin}]),O
end
end.
-
+
to_term(Bin) ->
try
{ok,Ts,_} = erl_scan:string(binary_to_list(Bin)),
@@ -81,7 +81,7 @@ to_term(Bin) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% SAX funs
sax_f(Fun) ->
- fun(RawXML,O) ->
+ fun(RawXML,O) ->
try [erlsom:sax(encoding(RawXML),[],sax_if(Fun))|O]
catch error:R -> ?log([{bt,erlang:get_stacktrace()},{doc,RawXML}]),
exit(R)
@@ -116,7 +116,7 @@ fold(eof,_,Fun,Chunker,State) ->
?state(Acc,Tail) = folder(Chunker,Fun,state_eof(State)),
[?log([{trailing,Tail}]) || not is_empty(Tail)],
Acc;
-fold({ok,Chunk},FD,Fun,Chunker,State) ->
+fold({ok,Chunk},FD,Fun,Chunker,State) ->
fold(read(FD),FD,Fun,Chunker,folder(Chunker,Fun,add_chunk(Chunk,State))).
folder(Chunker,Fun,?state(Acc,Tail)) ->
@@ -152,7 +152,7 @@ chunker(trc) ->
?log([{garbarge_at_eof,byte_size(R)}]),
{cont,?tail_0()}
end;
- (?tail(Bin,Off)) ->
+ (?tail(Bin,Off)) ->
case Bin of
<<_:Off/binary,0,S:32/integer,B:S/binary,_/binary>> ->
{ok,binary_to_term(B),?tail(Bin,Off+5+S)};
@@ -167,7 +167,7 @@ chunker(Type) ->
{_,T} when ?is_empty(T) -> {cont,?tail_0()};
{_,Trail} -> {ok,Trail,?tail_0()}
end;
- (Tail=?tail(Bin,Off)) ->
+ (Tail=?tail(Bin,Off)) ->
case re:run(Bin,Patt,[{offset,Off},{capture,[1]}]) of
nomatch -> {cont,Tail};
{match,[{O,L}]} -> {ok,snip(Bin,O,L),?tail(Bin,O+L)}
View
@@ -68,11 +68,11 @@ start_breader(File,Files,LD) ->
LD#ld{file=File,files=Files,bread_pid=BP,bread_ref=BR}.
%% runs in its own process
-breader(File,guess) ->
+breader(File,guess) ->
breader(File,guess_type(filename:extension(File)));
-breader(File,Type) ->
+breader(File,Type) ->
bread:fold(File,fun breaded/2,0,[Type]).
-
+
breaded(Blob,N) ->
receive
quit -> exit(N);
View
@@ -54,34 +54,34 @@ memi(Sys) ->
sys_str(Sys) ->
{_, Time} = calendar:now_to_local_time(lks(now, Sys)),
- H = pad(element(1,Time),2,$0,left),
- M = pad(element(2,Time),2,$0,left),
- S = pad(element(3,Time),2,$0,left),
- Node = to_list(lks(node, Sys)),
+ H = pad(element(1,Time),2,$0,left),
+ M = pad(element(2,Time),2,$0,left),
+ S = pad(element(3,Time),2,$0,left),
+ Node = to_list(lks(node, Sys)),
MEMbeam = prf:human(lks(beam_vss,Sys,0)),
- MEM = prf:human(lks(total,Sys)),
+ MEM = prf:human(lks(total,Sys)),
CPUbeam = to_list(100*(lks(beam_user,Sys,0)+lks(beam_kernel,Sys,0))),
CPU = to_list(100*(lks(user,Sys,0)+lks(kernel,Sys,0))),
- Procs = prf:human(lks(procs,Sys)),
- RunQ = prf:human(lks(run_queue, Sys)),
+ Procs = prf:human(lks(procs,Sys)),
+ RunQ = prf:human(lks(run_queue, Sys)),
SYS = lists:sublist(lists:append(["size: " ,MEM,
- "(" ,MEMbeam,
- "), cpu%: " ,CPUbeam,
- "(" ,CPU,
- "), procs: ",Procs,
- ", runq: " ,RunQ,
- ", ",H,":",M,":",S]),79),
+ "(" ,MEMbeam,
+ "), cpu%: " ,CPUbeam,
+ "(" ,CPU,
+ "), procs: ",Procs,
+ ", runq: " ,RunQ,
+ ", ",H,":",M,":",S]),79),
pad(Node,79-length(SYS),$ , right)++SYS.
pad(Item,Len,Pad,LeftRight) ->
I = to_list(Item),
case length(I) of
L when L=:=Len -> I;
- L when L<Len -> case LeftRight of
- left -> lists:duplicate(Len-L,Pad)++I;
- right-> I++lists:duplicate(Len-L,Pad)
- end;
+ L when L<Len -> case LeftRight of
+ left -> lists:duplicate(Len-L,Pad)++I;
+ right-> I++lists:duplicate(Len-L,Pad)
+ end;
_ -> lists:sublist(I,Len)
end.
@@ -100,10 +100,10 @@ which_sort(msgq,PrfPrc) -> expand(lks(msgq,PrfPrc),lks(info,PrfPrc));
which_sort(dmem,PrfPrc) -> expand(lks(dmem,PrfPrc),lks(info,PrfPrc));
which_sort( mem,PrfPrc) -> expand(lks(mem,PrfPrc),lks(info,PrfPrc)).
-expand(Pids,Infos) ->
+expand(Pids,Infos) ->
lists:reverse([[{pid,Pid}|lks(Pid,Infos)] || Pid <- Pids]).
-print_procs(FD,Items,PrfSys,Prcs) ->
+print_procs(FD,Items,PrfSys,Prcs) ->
CpuPerRed = cpu_per_red(PrfSys),
[procsI(FD,P,CpuPerRed) || P <- resize(Items,Prcs)].
@@ -126,22 +126,22 @@ procsI(FD,PP,CpuPerRed) ->
io:fwrite(FD,
format(),
[pidf(to_list(lks(pid,PP))),
- funf(reg(PP)),
- funf(lks(current_function, PP)),
+ funf(reg(PP)),
+ funf(lks(current_function, PP)),
prf:human(lks(message_queue_len, PP)),
- prf:human(lks(memory,PP)),
+ prf:human(lks(memory,PP)),
to_list(lks(dreductions,PP)*CpuPerRed)])
catch _:_ ->
io:fwrite(FD,"~n",[])
end.
-reg(PP) ->
+reg(PP) ->
case lks(registered_name, PP) of
[] -> lks(initial_call, PP);
Val -> Val
end.
-pidf(Pid) ->
+pidf(Pid) ->
[_,A,B] = string:tokens(Pid,"."),
lists:append(["<0.",A,".",B]).
@@ -156,7 +156,7 @@ to_list(A) when is_tuple(A) -> tuple_to_list(A);
to_list(A) when is_integer(A) -> integer_to_list(A).
lks(Tag,TVs,Def) ->
- try lks(Tag,TVs)
+ try lks(Tag,TVs)
catch {not_found, _} -> Def
end.
View
@@ -13,7 +13,7 @@
replay(TrcFile,Node) -> replay(TrcFile,Node,[]).
-replay(TrcFile,OldNode,Opts) ->
+replay(TrcFile,OldNode,Opts) ->
Node = ck_node(OldNode),
replay_trc:go(TrcFile,mk_dtop_fun(Node),mk_dtop_init(Node,Opts),Opts).
View
@@ -39,10 +39,10 @@ start(Mod) ->
start(Mod,Args) ->
gen_server:start_link({local, Mod}, ?MODULE, {Mod,Args}, []).
-stop(Mod) ->
+stop(Mod) ->
cast(Mod,stop).
-shutdown(Mod) ->
+shutdown(Mod) ->
cast(Mod,shutdown).
get_state(Mod,Field) ->
@@ -71,19 +71,19 @@ unlink() ->
init({Mod,Args}) ->
safer(#ld{mod=Mod,args=Args},init,[Args]).
-terminate(Reason,LD) ->
+terminate(Reason,LD) ->
safer(LD,terminate,[Reason,LD#ld.cld]).
-code_change(OldVsn,LD,Info) ->
+code_change(OldVsn,LD,Info) ->
safer(LD,code_change,[OldVsn,LD#ld.cld,Info]).
-handle_cast(Msg,LD) ->
+handle_cast(Msg,LD) ->
safer(LD,handle_cast,[Msg,LD#ld.cld]).
-handle_call(Msg,From,LD) ->
+handle_call(Msg,From,LD) ->
safer(LD,handle_call,[Msg,From,LD#ld.cld]).
-handle_info(Msg,LD) ->
+handle_info(Msg,LD) ->
safer(LD,handle_info,[Msg,LD#ld.cld]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -100,8 +100,8 @@ safer(LD,F,As) ->
case erlang:function_exported(LD#ld.mod,F,length(As)) of
false-> safe_default(F,LD);
true ->
- try safe_reply(F,LD,apply(LD#ld.mod,F,As))
- catch
+ try safe_reply(F,LD,apply(LD#ld.mod,F,As))
+ catch
error:R ->
?log([R,{mfa,{LD#ld.mod,F,As}},erlang:get_stacktrace()]),
safe_default(F,LD);
@@ -128,32 +128,32 @@ last(L) -> hd(lists:reverse(L)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% utilities
-print_term(Term) ->
+print_term(Term) ->
print_term(group_leader(),Term).
-print_term(FD,Term) ->
+print_term(FD,Term) ->
case node(FD) == node() of
true -> error_logger:info_report(Term);
false-> io:fwrite(FD," ~p~n",[Term])
end.
expand_recs(M,List) when is_list(List) ->
[expand_recs(M,L)||L<-List];
-expand_recs(M,Tup) when is_tuple(Tup) ->
+expand_recs(M,Tup) when is_tuple(Tup) ->
case tuple_size(Tup) of
L when L < 1 -> Tup;
L ->
try Fields = M:rec_info(element(1,Tup)),
L = length(Fields)+1,
lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup))))
- catch _:_ ->
+ catch _:_ ->
list_to_tuple(expand_recs(M,tuple_to_list(Tup)))
end
end;
expand_recs(_,Term) ->
Term.
cast(Mod,What) ->
- try gen_server:cast(Mod,What)
+ try gen_server:cast(Mod,What)
catch exit:{noproc,_} -> ok
end.
View
@@ -114,7 +114,7 @@ parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of
{value, {Name, _Short, Long, undefined, _Help}} ->
parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
-
+
{value, {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec} ->
% The option argument string is empty, but the option requires
% an argument, so we look into the next string in the list.
@@ -217,7 +217,7 @@ parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [] = Args, {Name, _Sh
_ ->
throw({error, {missing_option_arg, Name}})
end.
-
+
%% @doc Find the option for the discrete argument in position specified in the
%% Pos argument.
@@ -318,7 +318,7 @@ is_arg_true(Arg) ->
(Arg =:= "on") orelse (Arg =:= "enabled") orelse
(Arg =:= "1").
-
+
-spec is_arg_false(string()) -> boolean().
is_arg_false(Arg) ->
(Arg =:= "false") orelse (Arg =:= "f") orelse
@@ -362,7 +362,7 @@ is_float_arg([_Head | _Tail]) ->
false;
is_float_arg([]) ->
true.
-
+
%% @doc Show a message on stdout indicating the command line options and
%% arguments that are supported by the program.
@@ -441,8 +441,8 @@ usage_options(OptSpecList) ->
lists:flatten(lists:reverse(usage_options_reverse(OptSpecList, []))).
usage_options_reverse([{Name, Short, Long, _ArgSpec, Help} | Tail], Acc) ->
- Prefix =
- case Long of
+ Prefix =
+ case Long of
undefined ->
case Short of
% Neither short nor long form (non-option argument).
View
@@ -2,7 +2,7 @@
%%%-------------------------------------------------------------------
%%% File : gperfConsumer.erl
%%% Author : Mats Cronqvist <locmacr@mwlx084>
-%%% Description :
+%%% Description :
%%%
%%% Created : 17 May 2005 by Mats Cronqvist <locmacr@mwlx084>
%%%-------------------------------------------------------------------
@@ -21,7 +21,7 @@ init(Node) -> #ld{node = Node}.
terminate(_LD) -> ok.
-tick(LD, Data) ->
+tick(LD, Data) ->
NLD = update_ld(LD, Data),
gperf ! {tick, {ltime(NLD#ld.data),info(NLD)}},
NLD.
@@ -47,11 +47,11 @@ info(LD) ->
dump_ld(LD) ->
?log(lists:zip(record_info(fields,ld),tl(tuple_to_list(LD)))).
-update_ld(LD,[]) ->
+update_ld(LD,[]) ->
LD#ld{data=[]};
-update_ld(LD,[{prfSys,Sys}]) ->
+update_ld(LD,[{prfSys,Sys}]) ->
LD#ld{data=Sys};
-update_ld(LD,[X]) ->
+update_ld(LD,[X]) ->
?log({unrecognized_data,X}), LD.
ltime(Sys) ->
@@ -76,7 +76,7 @@ mem(Max,Sys) ->
mn(1,dv(lks(ets,Sys)+lks(processes,Sys),Max)),
mn(1,dv(lks(processes,Sys),Max))].
-net(Max,Sys) ->
+net(Max,Sys) ->
[mn(1,dv(lks(io_in,Sys),Max)),
mn(1,dv(lks(io_out,Sys),Max))].
Oops, something went wrong.

0 comments on commit a0fa470

Please sign in to comment.