Permalink
Browse files

First step to the unification of the interface. Goal is to reach the …

…state

where all snapshot/1 and diff/2 usage is list-argument based with proplist
style args.
  • Loading branch information...
1 parent f822bff commit ff590468736a413787c10d551162dc187d4c0a18 Gianfranco committed Jun 30, 2011
Showing with 24 additions and 3 deletions.
  1. +21 −1 src/frame_axiom.erl
  2. +3 −2 test/frame_axiom_tests.erl
View
22 src/frame_axiom.erl
@@ -42,6 +42,10 @@ snapshot(SnapShots) when is_list(SnapShots) ->
lists:foldl(fun(SnapShot,Ets) -> snapshot(Ets,SnapShot)
end,ets:new(snapshot,[private]),SnapShots).
+snapshot(Ets,{process,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,process,Option)
+ end,Ets,Options);
+
snapshot(Ets,process) ->
Processes = erlang:processes(),
ets:insert(Ets,{process,Processes}),
@@ -76,11 +80,21 @@ snapshot(Ets,named_process) ->
ets:insert(Ets,{named_process,Current}),
Ets.
+snapshot(Ets,process,creation) ->
+ Pids = erlang:processes(),
+ ets:insert(Ets,{{process,creation},Pids}),
+ Ets.
+
+diff(Ets,[X]) ->
+ diff(Ets,X);
diff(Ets,DiffSpecs) when is_list(DiffSpecs) ->
lists:foldl(fun(DiffSpec,Res) ->
Key = diffspec_key(DiffSpec),
Res++[{Key,diff(Ets,DiffSpec)}]
end,[],DiffSpecs);
+diff(Ets,{process,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,Res) -> Res++diff(Ets,process,Option)
+ end,[],Options);
diff(Ets,process) ->
Processes = erlang:processes(),
[{process,Recorded}] = ets:lookup(Ets,process),
@@ -136,7 +150,13 @@ diff(Ets,application,load_unload) ->
[{application,_,Recorded}] = ets:lookup(Ets,application),
NewLoaded = [{loaded,hd(tuple_to_list(App))} ||App <- Loaded, not lists:member(App,Recorded)],
UnLoaded = [{unloaded,hd(tuple_to_list(App))} ||App <- Recorded, not lists:member(App,Loaded)],
- NewLoaded++UnLoaded.
+ NewLoaded++UnLoaded;
+diff(Ets,process,creation) ->
+ CurrentPids = erlang:processes(),
+ Key = {process,creation},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{created,P}||P<-CurrentPids,not lists:member(P,Recorded)].
+
%% Helpers section
%% ----------------------------------------------------------
View
5 test/frame_axiom_tests.erl
@@ -28,9 +28,10 @@
%% process and named_process
%% ---------------------------------------------------------
process_creation_diff_test() ->
- Ref = frame_axiom:snapshot(process),
+ Options = [creation],
+ Ref = frame_axiom:snapshot([{process,Options}]),
Pid = spawn_link(fun() -> receive _ -> ok end end),
- ?assertEqual([{created,Pid}],frame_axiom:diff(Ref,process)).
+ ?assertEqual([{created,Pid}],frame_axiom:diff(Ref,[{process,Options}])).
process_death_diff_test() ->
process_flag(trap_exit,true),

0 comments on commit ff59046

Please sign in to comment.