From 7a42d7ee12cba812367682ee49eaf33d33991960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 24 Feb 2015 06:51:13 +0100 Subject: cover: Optimize file operations Use the 'raw', 'delayed_write', and 'read_head' options to speed up file operations. The analysis at the end of: ts:run(compiler, [batch,cover]). is now roughly twice as fast. --- lib/tools/src/cover.erl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 9a76084bc0..6c32c47069 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -2377,9 +2377,9 @@ do_analyse_to_file(Module,File,OutFile,HTML,State) -> %% Module = atom() %% OutFile = ErlFile = string() do_analyse_to_file1(Module, OutFile, ErlFile, HTML) -> - case file:open(ErlFile, [read]) of + case file:open(ErlFile, [read,raw,read_ahead]) of {ok, InFd} -> - case file:open(OutFile, [write]) of + case file:open(OutFile, [write,raw,delayed_write]) of {ok, OutFd} -> if HTML -> Encoding = encoding(ErlFile), @@ -2422,7 +2422,9 @@ do_analyse_to_file1(Module, OutFile, ErlFile, HTML) -> CovLines = lists:keysort(1,ets:select(?COLLECTION_TABLE, MS)), print_lines(Module, CovLines, InFd, OutFd, 1, HTML), - if HTML -> io:format(OutFd,"\n\n\n",[]); + if + HTML -> + file:write(OutFd, "\n\n\n"); true -> ok end, @@ -2441,13 +2443,13 @@ do_analyse_to_file1(Module, OutFile, ErlFile, HTML) -> print_lines(Module, CovLines, InFd, OutFd, L, HTML) -> - case io:get_line(InFd, '') of + case file:read_line(InFd) of eof -> ignore; - "%"++_=Line -> %Comment line - not executed. - io:put_chars(OutFd, [tab(),escape_lt_and_gt(Line, HTML)]), + {ok,"%"++_=Line} -> %Comment line - not executed. + file:write(OutFd, [tab(),escape_lt_and_gt(Line, HTML)]), print_lines(Module, CovLines, InFd, OutFd, L+1, HTML); - RawLine -> + {ok,RawLine} -> Line = escape_lt_and_gt(RawLine,HTML), case CovLines of [{L,N}|CovLines1] -> @@ -2459,20 +2461,20 @@ print_lines(Module, CovLines, InFd, OutFd, L, HTML) -> %%Str = string:right("0", 6, 32), RedLine = ["",Str,fill1(), LineNoNL,"\n"], - io:put_chars(OutFd, RedLine); + file:write(OutFd, RedLine); N<1000000 -> Str = string:right(integer_to_list(N), 6, 32), - io:put_chars(OutFd, [Str,fill1(),Line]); + file:write(OutFd, [Str,fill1(),Line]); N<10000000 -> Str = integer_to_list(N), - io:put_chars(OutFd, [Str,fill2(),Line]); + file:write(OutFd, [Str,fill2(),Line]); true -> Str = integer_to_list(N), - io:put_chars(OutFd, [Str,fill3(),Line]) + file:write(OutFd, [Str,fill3(),Line]) end, print_lines(Module, CovLines1, InFd, OutFd, L+1, HTML); _ -> - io:put_chars(OutFd, [tab(),Line]), + file:write(OutFd, [tab(),Line]), print_lines(Module, CovLines, InFd, OutFd, L+1, HTML) end end. @@ -2484,7 +2486,7 @@ fill3() -> "| ". %%%--Export-------------------------------------------------------------- do_export(Module, OutFile, From, State) -> - case file:open(OutFile,[write,binary,raw]) of + case file:open(OutFile,[write,binary,raw,delayed_write]) of {ok,Fd} -> Reply = case Module of -- cgit v1.2.3 From 2c1514501519be143b335e594b69636593070a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 24 Feb 2015 07:32:33 +0100 Subject: test_server: Sort cover-analysed modules 'cover' has changed so that the analyzed results are returned in random order, which is annyoying. Sort the list so that modules appear in alphabetical order. --- lib/test_server/src/test_server.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl index 1d989ce9c8..a4f7d24540 100644 --- a/lib/test_server/src/test_server.erl +++ b/lib/test_server/src/test_server.erl @@ -266,9 +266,9 @@ cover_analyse(Dir,#cover{level=Analyse,mods=Modules,stop=Stop}) -> end end, {result,AOk,AFail} = cover:analyse(Modules,module), - R = merge_analysis_results(AOk,ATFOk++ATFFail,[]) ++ + R0 = merge_analysis_results(AOk,ATFOk++ATFFail,[]) ++ [{M,{error,Reason}} || {Reason,M} <- AFail], - + R = lists:sort(R0), io:fwrite(user, "done\n\n", []), case Stop of -- cgit v1.2.3