Skip to content

Commit

Permalink
showing some info about the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielegenovese committed Feb 4, 2025
1 parent e7f6a3c commit 071922d
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 52 deletions.
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
1 change: 0 additions & 1 deletion rebarconfig.json

This file was deleted.

12 changes: 6 additions & 6 deletions src/choreography/gv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ generate() ->
G = create_globalview(EntryPoint),
MinG = fsa:minimize(G),
Data = #localview{graph = G, min_graph = MinG},
db:set(?GLOBALVIEW, Data),
share:save_graph(Data, EntryPoint, global, settings:get(minimizeG)),
log:info("Finished!~n", []),
finished
Expand All @@ -48,8 +49,7 @@ create_globalview(Name) ->
MainProcPid = spawn(actor_emul, proc_loop, [#actor_info{fun_name = Name, id = N}]),
PidKey = share:atol(Name) ++ ?NSEQSEP ++ integer_to_list(N),
ProcPidMap = #{share:ltoa(PidKey) => MainProcPid},
S = sets:new(),
ets:insert(?DBMANAGER, {global_state, #{1 => sets:add_element({share:ltoa(PidKey), 1}, S)}}),
db:set(?GLOBALSTATE, #{1 => sets:add_element({share:ltoa(PidKey), 1}, sets:new())}),
% initialize first branch
BData = progress_all(RetG, [new_branch(RetG, VNew, ProcPidMap)]),
% share:show_global_state(),
Expand Down Expand Up @@ -440,10 +440,10 @@ add_spawn_to_global(EInfo, SLabel, EmulProcName, Data) ->
% log:debug("LocalList ~p~n", [LocalList]),
% create the edge on the global graph
VNew = share:add_vertex(Data#branch.graph),
[{_, StateM}] = ets:lookup(?DBMANAGER, global_state),
StateM = db:get(?GLOBALSTATE),
AggrGState = create_gv_state(NewMap, share:ltoa(FunSpawned), 1, EmulProcName, PV),
% log:debug("SPAWN AGGR ~p~n", [AggrGState]),
ets:insert(?DBMANAGER, {global_state, maps:put(VNew, AggrGState, StateM)}),
db:set(?GLOBALSTATE, maps:put(VNew, AggrGState, StateM)),
NewLabel = format_spawn_label(SLabel, EmulProcName, FunSpawned),
digraph:add_edge(Data#branch.graph, Data#branch.last_vertex, VNew, NewLabel),
{VNew, NewMap}.
Expand Down Expand Up @@ -787,7 +787,7 @@ check_pid_self(Data, ProcId) ->
%%% TODO: consider message queue also
complex_add_vertex_recv(Proc1, CurrVertex, Proc2, EdgeInfo, Data, Label) ->
ProcPid = Data#branch.proc_pid_m,
[{_, StateM}] = ets:lookup(?DBMANAGER, global_state),
StateM = db:get(?GLOBALSTATE),
% log:debug("stateM ~p~n", [StateM]),
% log:debug("Label ~p~n", [share:ltoa(Label)]),
VLast = Data#branch.last_vertex,
Expand All @@ -803,7 +803,7 @@ complex_add_vertex_recv(Proc1, CurrVertex, Proc2, EdgeInfo, Data, Label) ->
digraph:add_edge(G, VLast, VNew, Label),
% log:debug("[DEBUG] Adding new global state ~p~n", [VNew]),
NewM = maps:put(VNew, AggregateGlobalState, StateM),
ets:insert(?DBMANAGER, {global_state, NewM}),
db:set(?GLOBALSTATE, NewM),
empty_filter_all_proc(Data#branch.proc_pid_m),
{VNew, true};
VFound ->
Expand Down
8 changes: 4 additions & 4 deletions src/choreography/lv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
generate() ->
ActorList = get_actors(),
lists:foldl(
fun(Actor, Acc) ->
fun(Actor, Error) ->
case create_localview(Actor, ?ANYDATA, true) of
no_graph -> false;
_ -> Acc
no_graph -> true;
_ -> Error
end
end,
true,
false,
ActorList
).

Expand Down
66 changes: 65 additions & 1 deletion src/choreography/md.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-include("../share/common_data.hrl").

%%% API
-export([extract/0, parse_file/1]).
-export([extract/0, parse_file/1, show_data/1]).

%%%===================================================================
%%% API
Expand All @@ -27,6 +27,30 @@ extract() ->
parse_file(Path) ->
element(2, epp_dodger:quick_parse_file(Path)).

show_data(InputFile) ->
TotLine = get_tot_line(InputFile),
io:fwrite("~nTotal numeber of lines: ~p~n", [TotLine]),
{LocalViewData, GlobalViewMap} = get_graph_data(),
lists:foreach(
fun({FunName, LvMap}) ->
io:fwrite("Data of ~p localview:~n", [FunName]),
maps:foreach(
fun(Key, Value) ->
io:fwrite("~p ~p~n", [Key, Value])
end,
LvMap
)
end,
LocalViewData
),
io:fwrite("Data of global view: ~n"),
maps:foreach(
fun(Key, Value) ->
io:fwrite("~p ~p~n", [Key, Value])
end,
GlobalViewMap
).

%%%===================================================================
%%% Internal Functions
%%%===================================================================
Expand Down Expand Up @@ -54,3 +78,43 @@ gen_fun_ast_and_exported(Ast) ->
Ast
),
ets:insert(?DBMANAGER, {?ACTORLIST, ActorList}).

get_tot_line(FileName) ->
{ok, Device} = file:open(FileName, [read]),
get_all_lines(Device, 0).

get_all_lines(Device, Accum) ->
case io:get_line(Device, "") of
eof ->
file:close(Device),
Accum;
_Line ->
get_all_lines(Device, Accum + 1)
end.

get_graph_data() ->
LocalViewData = get_lv_data(),
GlobalViewData = get_gv_data(),
{LocalViewData, GlobalViewData}.

get_lv_data() ->
AllLovalViewList = ets:tab2list(?LOCALVIEW),
lists:map(
fun({FunName, FunData}) ->
G = FunData#localview.min_graph,
LvNodes = length(digraph:vertices(G)),
LvEdges = length(digraph:edges(G)),
Map = maps:put(num_nodes, LvNodes, #{}),
RetMap = maps:put(num_edges, LvEdges, Map),
{FunName, RetMap}
end,
AllLovalViewList
).

get_gv_data() ->
Data = db:get(?GLOBALVIEW),
G = Data#localview.min_graph,
GvNodes = length(digraph:vertices(G)),
GvEdges = length(digraph:edges(G)),
Map = maps:put(num_nodes, GvNodes, #{}),
maps:put(num_edges, GvEdges, Map).
9 changes: 5 additions & 4 deletions src/chorer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ generate(InputFile, EntryPoint, OutDir, MinG, GState, MinL) ->
Settings = settings:new_settings(InputFile, EntryPoint, OutDir, MinL, MinG, GState),
db:init(Settings),
md:extract(),
NoError = lv:generate(),
case NoError of
true -> gv:generate();
false -> done
ErrorIsPresent = lv:generate(),
case ErrorIsPresent of
false -> gv:generate();
true -> done
end,
md:show_data(InputFile),
db:close().
2 changes: 2 additions & 0 deletions src/share/common_data.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
-define(FUNAST, fun_ast).
-define(ARGUMENTS, args).
-define(LOCALVIEW, lv).
-define(GLOBALVIEW, gv).
-define(REGISTERDB, reg).
-define(SPAWNCOUNT, spc).
-define(SETTINGS, settings).
-define(GLOBALSTATE, global_state).

%%% Separators
-define(ARITYSEP, "/").
Expand Down
23 changes: 20 additions & 3 deletions src/share/db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@
-export([
init/1,
close/0,
get/1,
set/2,
get_fun_ast/1,
get_localview/1,
get_lv_graph/1,
get_lv_edge_additonal_info/1,
inc_spawn_counter/1
]).

-define(DB_NAMESL, [?DBMANAGER, ?CLINE, ?FUNAST, ?LOCALVIEW, ?REGISTERDB, ?ARGUMENTS, ?SPAWNCOUNT]).
-define(ALL, [
?DBMANAGER,
?CLINE,
?FUNAST,
?LOCALVIEW,
?REGISTERDB,
?ARGUMENTS,
?SPAWNCOUNT,
?GLOBALSTATE
]).

%%%===================================================================
%%% API
Expand All @@ -26,16 +37,22 @@
init(Settings) ->
lists:foreach(
fun(DbName) -> ets:new(DbName, [set, named_table]) end,
?DB_NAMESL
?ALL
),
ets:insert(?DBMANAGER, {?SETTINGS, Settings}).

close() ->
lists:foreach(
fun(DbName) -> ets:delete(DbName) end,
?DB_NAMESL
?ALL
).

get(Key) ->
lookup(?DBMANAGER, Key).

set(Key, Value) ->
ets:insert(?DBMANAGER, {Key, Value}).

get_fun_ast(FunName) ->
lookup(?FUNAST, share:atol(FunName)).

Expand Down
70 changes: 37 additions & 33 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
#!/bin/python
import os
# import time
import subprocess
import time

# default: minimize global views
test_list = [
("./examples/account/account.erl", "main/0", "examples/account", "true"),
("./examples/dining/dining.erl", "main/0", "examples/dining", "true"),
("./examples/hello/hello.erl", "main/0", "examples/hello", "true"),
("./examples/async/simple.erl","main/0","examples/async", "true"),
("./examples/ticktackstop/tictacstop.erl","start/0","examples/ticktackstop", "true"),
("./examples/ticktackloop/tictacloop.erl","start/0","examples/ticktackloop", "true"),
("./examples/customer/customer.erl","main/0","examples/customer", "true"),
("./examples/serverclient/serverclient.erl","main/0","examples/serverclient", "true"),
("./examples/trick/trick.erl","main/0","examples/trick", "true"),
("./examples/airline/airline.erl","main/0","examples/airline", "true"),
("./examples/conditional-case/conditional_case.erl","main/0","examples/conditional-case", "true"),
("./examples/for-loop-recursion/forloop.erl","main/0","examples/for-loop-recursion", "true"),
("./examples/function-call/funny.erl","main/0","examples/function-call", "true"),
("./examples/high-order-fun/hof.erl","greet/0","examples/high-order-fun", "true"),
("./examples/if-cases/ifcases.erl","main/0","examples/if-cases", "true"),
("./examples/test/foo1/foo1.erl","test/0","examples/test/foo1", "true"),
("./examples/test/foo2/foo2.erl","test/0","examples/test/foo2", "true"),
("./examples/test/foo3/foo3.erl","test/0","examples/test/foo3", "true"),
("./examples/test/foo4/foo4.erl","test/0","examples/test/foo4", "true"),
("./examples/test/foo5/foo5.erl","test/0","examples/test/foo5", "true"),
("./examples/test/foo6/foo6.erl","test/0","examples/test/foo6", "true"),
("./examples/test/ping/ping.erl","start/0","examples/test/ping", "true"),
("./examples/cauder_suite/airline/airline.erl","main/0","examples/cauder_suite/airline", "true"),
# ("./examples/cauder_suite/barber/barber.erl","main/0","examples/cauder_suite/barber", "true"),
("./examples/cauder_suite/meViolation/meViolation.erl","main/0","examples/cauder_suite/meViolation", "true"),
("./examples/cauder_suite/purchase/purchase.erl","main/0","examples/cauder_suite/purchase", "true"),
["./examples/account/account.erl", "main/0", "examples/account", "true"],
["./examples/dining/dining.erl", "main/0", "examples/dining", "true"],
["./examples/hello/hello.erl", "main/0", "examples/hello", "true"],
["./examples/async/simple.erl","main/0","examples/async", "true"],
["./examples/ticktackstop/tictacstop.erl","start/0","examples/ticktackstop", "true"],
["./examples/ticktackloop/tictacloop.erl","start/0","examples/ticktackloop", "true"],
["./examples/customer/customer.erl","main/0","examples/customer", "true"],
["./examples/serverclient/serverclient.erl","main/0","examples/serverclient", "true"],
["./examples/trick/trick.erl","main/0","examples/trick", "true"],
["./examples/airline/airline.erl","main/0","examples/airline", "true"],
["./examples/conditional-case/conditional_case.erl","main/0","examples/conditional-case", "true"],
["./examples/for-loop-recursion/forloop.erl","main/0","examples/for-loop-recursion", "true"],
["./examples/function-call/funny.erl","main/0","examples/function-call", "true"],
["./examples/high-order-fun/hof.erl","greet/0","examples/high-order-fun", "true"],
["./examples/if-cases/ifcases.erl","main/0","examples/if-cases", "true"],
["./examples/test/foo1/foo1.erl","test/0","examples/test/foo1", "true"],
["./examples/test/foo2/foo2.erl","test/0","examples/test/foo2", "true"],
["./examples/test/foo3/foo3.erl","test/0","examples/test/foo3", "true"],
["./examples/test/foo4/foo4.erl","test/0","examples/test/foo4", "true"],
["./examples/test/foo5/foo5.erl","test/0","examples/test/foo5", "true"],
["./examples/test/foo6/foo6.erl","test/0","examples/test/foo6", "true"],
["./examples/test/ping/ping.erl","start/0","examples/test/ping", "true"],
["./examples/cauder_suite/airline/airline.erl","main/0","examples/cauder_suite/airline", "true"],
# ["./examples/cauder_suite/barber/barber.erl","main/0","examples/cauder_suite/barber", "true"],
["./examples/cauder_suite/meViolation/meViolation.erl","main/0","examples/cauder_suite/meViolation", "true"],
["./examples/cauder_suite/purchase/purchase.erl","main/0","examples/cauder_suite/purchase", "true"],
]

os.system("rebar3 escriptize")

outputs = []

for item in test_list:
path, entrypoint, dir, minl, ming = item
cmd = f"./_build/default/bin/chorer {path} {entrypoint} {dir} {minl} {ming}"
print(cmd)
os.system(cmd)
# time.sleep(1)
print("\n")
item = ["./_build/default/bin/chorer"] + item
print("Executing ", " ".join(item))
output = subprocess.check_output(item).decode('utf-8')
print(output + "\n")
outputs.append(output)
time.sleep(1)

0 comments on commit 071922d

Please sign in to comment.