File 0132-Speed-up-erts_debug-df.patch of Package erlang

From 79f28cfd8df1b700baff0df5e3d766d0a5592581 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 22 Sep 2017 07:24:51 +0200
Subject: [PATCH 1/2] Speed up erts_debug:df()

The test case erts_debug_SUITE:df/1 in the emulator test suite is
about 4 times faster with this change.
---
 lib/kernel/src/erts_debug.erl | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lib/kernel/src/erts_debug.erl b/lib/kernel/src/erts_debug.erl
index 480db6814e..2887014c1c 100644
--- a/lib/kernel/src/erts_debug.erl
+++ b/lib/kernel/src/erts_debug.erl
@@ -378,16 +378,11 @@ df(Mod, Func, Arity) when is_atom(Mod), is_atom(Func) ->
     catch _:_ -> {undef,Mod}
     end.
 
-dff(File, Fs) when is_pid(File), is_list(Fs) ->
-    lists:foreach(fun(Mfa) ->
-			  disassemble_function(File, Mfa),
-			  io:nl(File)
-		  end, Fs);
-dff(Name, Fs) when is_list(Name) ->
-    case file:open(Name, [write]) of
+dff(Name, Fs) ->
+    case file:open(Name, [write,raw,delayed_write]) of
 	{ok,F} ->
 	    try
-		dff(F, Fs)
+		dff_1(F, Fs)
 	    after
 		_ = file:close(F)
 	    end;
@@ -395,12 +390,18 @@ dff(Name, Fs) when is_list(Name) ->
 	    {error,{badopen,Reason}}
     end.
 
+dff_1(File, Fs) ->
+    lists:foreach(fun(Mfa) ->
+                          disassemble_function(File, Mfa),
+                          file:write(File, "\n")
+                  end, Fs).
+
 disassemble_function(File, {_,_,_}=MFA) ->
     cont_dis(File, erts_debug:disassemble(MFA), MFA).
 
 cont_dis(_, false, _) -> ok;
 cont_dis(File, {Addr,Str,MFA}, MFA) ->
-    io:put_chars(File, binary_to_list(Str)),
+    ok = file:write(File, Str),
     cont_dis(File, erts_debug:disassemble(Addr), MFA);
 cont_dis(_, {_,_,_}, _) -> ok.
 
-- 
2.14.1