Commit 878d4fad authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Updated benchmark system

- Remember, to run benchmarks you require a "server" process for Erlang (see previous commits).
- If you output slices, astCounter.erl can be used to count the number of AST nodes in a given program.
parent ad8763fd
Loading
Loading
Loading
Loading

astCounter.erl

0 → 100644
+94 −0
Original line number Diff line number Diff line
-module(astCounter).
-compile(export_all).

% Call: astCounter:enterDeepestDir("ComputedSlices/erlsom/","erlsom").
enterDeepestDir(FileDir,Set) ->
	enterDeepestDir(FileDir,Set,[]).

enterDeepestDir(FileDir,Set,FolderList) ->
	AdditionalRoute = lists:foldr(fun(F,Acc) -> Acc ++ F ++ "/" end, "",FolderList),
	{ok,Files} = file:list_dir(FileDir++AdditionalRoute),
	InnerDirs = lists:filter(fun(F) -> filelib:is_dir(FileDir++AdditionalRoute++F) end, Files),
	case InnerDirs of
		[] ->
			countASTsNodes(FileDir,Set,FolderList); % TODO: VALIDAR FUNCIONAMIENTO
		_ ->
			lists:map(fun(D) -> enterDeepestDir(FileDir,Set,[D|FolderList]) end, InnerDirs)
	end.

% THIS CLAUSE IS ONLY VALID FOR DIRECTORY STRUCTURE => $PWD/program.erl
countASTsNodes(FileDir,_Set,[]) ->
    FilePath = FileDir,
	[LastFolder | _] = lists:reverse(filename:split(FileDir)),
	{ok,Fd} = file:open("Results/results"++LastFolder++".txt",[append]),
	Files = lists:sort(getErlFiles(FilePath)),
	lists:map(fun(F) ->
				Nodes = counter(FilePath ++ F),
				io:format(Fd,"File: ~s => ~w AST Nodes\n",[F,Nodes])
			  end,
			  Files),
	file:close(Fd);

countASTsNodes(FileDir,Set,FolderList) ->
    % THIS CLAUSE IS ONLY VALID FOR DIRECTORY STRUCTURE => $PWD/benchName/program.erl
	BenchName = case length(FolderList) of
		1 -> [Name] = FolderList,
		     Name;
		N -> throw("MORE/LESS THAN 2 ELEMENTS: " ++ N)
	end,
	FilePath = FileDir ++ BenchName ++ "/",
	[LastFolder | _] = lists:reverse(filename:split(FilePath)),
	filelib:ensure_dir("Results/"++Set++"/"),
	{ok,Fd} = file:open("Results/"++Set++"/"++LastFolder++".txt",[append]),
	Files = lists:sort(getErlFiles(FilePath)),
	lists:map(fun(F) -> 
				Nodes = counter(FilePath ++ F),
				Fname = filename:basename(F,".erl"),
                [Graph,Crit] = string:split(Fname,"_"),
				io:format(Fd,"~s;~s;~s;~w\n",[BenchName,Graph,"#"++Crit,Nodes])
			  end,
			  Files),
	file:close(Fd).

getErlFiles(Filename) ->
	case file:list_dir(Filename) of
		{ok,Names} -> 
			lists:filter(fun(File) -> filename:extension(File) == ".erl" end, Names);
		_ -> throw("The file does not exist")
	end.

counter(File) ->
	FunctionForms = getAST(File),
	lists:foldl(fun countNodes/2, 0, FunctionForms).

getAST(File) ->
	{ok, Forms} = epp:parse_file(File, [], []),
	lists:filter(fun(Form) -> element(1,Form) == function end, Forms).

countNodes(Form, NumNodes) ->
	erl_syntax_lib:fold(fun(N,Acc) ->
							case erl_syntax:type(N) of
								atom -> 
									case erl_syntax:atom_literal(N) of
                                        "sliced" -> Acc;
                                        _ -> Acc + 1
                                    end;
								underscore -> 
									Acc;
								_ ->
									Acc + 1
							end
						end, NumNodes, Form).

fileCounter(Path,FolderList) ->
	AdditionalRoute = lists:foldr(fun(F,Acc) -> Acc ++ F ++ "/" end, "",FolderList),
	{ok,Files} = file:list_dir(Path++AdditionalRoute),
	InnerDirs = lists:filter(fun(F) -> filelib:is_dir(Path++AdditionalRoute++F) end, Files),
	case InnerDirs of
		[] ->
			io:format("Slices in ~s => ~p\n",[AdditionalRoute,length(getErlFiles(Path++AdditionalRoute))/2]);
		_ ->
			lists:map(fun(D) -> fileCounter(Path,[D|FolderList]) end, InnerDirs)
	end.

printer(N) -> io:format("Node: ~w\n",[N]).
 No newline at end of file
+18 −8
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import eknife.erlang.ErlangCodeFactory;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.io.File;
import java.util.LinkedList;
@@ -49,7 +51,7 @@ public class EKnife {
	public static final String outputSizeFolder = baseDir + "Sizes/";
	public static final String sliceTimeFolder = outputTimeFolder + "Slices/";
	public static final String outputSliceGenerationFolder = baseDir + "Slices/";

	public static final String slicesFolder = "./ComputedSlices/";

	public static void main(String[] args) {
		if (args.length == 0) {
@@ -231,12 +233,12 @@ public class EKnife {
	 */
	private static void timedRun(Args a, String setName) {
		// CONFIGURE MEASURED DIMENSIONS
		boolean measureGenerationTime = false;
		boolean measureGenerationTime = true;
		boolean performAllSCs = true;
		boolean countSlices = false;
		boolean measureSlicingTime = false;
		boolean measureAccessConstraints = false;
		boolean outputSlice = true;
		boolean countSlices = true;
		boolean measureSlicingTime = true;
		boolean measureAccessConstraints = true;
		boolean outputSlice = false;
		/* ***************************************************** */
		/* ** MEASUREMENT OF GENERATION TIME (100 executions) ** */
		/* ***************************************************** */
@@ -249,6 +251,14 @@ public class EKnife {
		moduleName = moduleName.lastIndexOf(".") != -1 ?
				moduleName.substring(0, moduleName.lastIndexOf(".")) : moduleName;

		// CREATE DIRECTORIES TO SAVE SLICES
		if (outputSlice)
			try {
				Files.createDirectories(Path.of(slicesFolder + moduleName +"/"));
			} catch (Exception e) {
				e.printStackTrace();
			}

		if (measureAccessConstraints) {
			LAST last = LASTFactory.createLAST(Language.Erlang, a.inputPath, true);
			EDG edg = new EDGFactory(last).createEDG();
@@ -370,8 +380,8 @@ public class EKnife {
					if (outputSlice) {
						Set<Node> stdSlice = standardAlgorithm.slice(SC);
						Set<Node> ctdSlice = constrainedAlgorithm.slice(SC);
						ErlangCodeFactory.createErlangFile(new File(moduleName + "_SC" + scCounter + ".erl"), edg, stdSlice);
						ErlangCodeFactory.createErlangFile(new File(moduleName + "_CE_SC" + scCounter + ".erl"), edg, ctdSlice);
						ErlangCodeFactory.createErlangFile(new File(slicesFolder + moduleName +"/PDG_" + scCounter + ".erl"), edg, stdSlice);
						ErlangCodeFactory.createErlangFile(new File(slicesFolder + moduleName +"/CE-PDG_" + scCounter + ".erl"), edg, ctdSlice);
					}

					// MEASURE TIME FOR EACH SC