File 0942-Modernize-the-examples-in-the-User-s-Guide-for-cprof.patch of Package erlang

From 5bc660ab8f3ba9ea26e22596f6f8eb3670d8a2fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 21 Mar 2022 07:07:03 +0100
Subject: [PATCH 2/2] Modernize the examples in the User's Guide for cprof

---
 lib/tools/doc/src/cprof_chapter.xml | 145 +++++++++++++++-------------
 1 file changed, 77 insertions(+), 68 deletions(-)

diff --git a/lib/tools/doc/src/cprof_chapter.xml b/lib/tools/doc/src/cprof_chapter.xml
index 986ad85bbf..671f9717a6 100644
--- a/lib/tools/doc/src/cprof_chapter.xml
+++ b/lib/tools/doc/src/cprof_chapter.xml
@@ -96,33 +96,38 @@
     <p>From the Erlang shell:</p>
     <pre>
 1> <input>cprof:start(), cprof:pause(). % Stop counters just after start</input>
-3476
+8492
 2> <input>cprof:analyse().</input>
-{30,
- [{erl_eval,11,
-            [{{erl_eval,expr,3},3},
-             {{erl_eval,'-merge_bindings/2-fun-0-',2},2},
-             {{erl_eval,expand_module_name,2},1},
-             {{erl_eval,merge_bindings,2},1},
-             {{erl_eval,binding,2},1},
-             {{erl_eval,expr_list,5},1},
-             {{erl_eval,expr_list,3},1},
-             {{erl_eval,exprs,4},1}]},
-  {orddict,8,
-           [{{orddict,find,2},6},
-            {{orddict,dict_to_list,1},1},
-            {{orddict,to_list,1},1}]},
-  {packages,7,[{{packages,is_segmented_1,1},6},
-               {{packages,is_segmented,1},1}]},
-  {lists,4,[{{lists,foldl,3},3},{{lists,reverse,1},1}]}]}
+{539,
+ [{shell,155,
+         [{{shell,prep_check,1},55},
+          {{shell,used_records,4},45},
+          {{shell,used_records,1},45},
+          {{shell,used_record_defs,2},1},
+          {{shell,record_defs,2},1},
+          {{shell,record_bindings,2},1},
+          {{shell,exprs,7},1},
+          {{shell,expr,4},1},
+          {{shell,expand_records,2},1},
+          {{shell,check_command,2},1},
+          {{shell,apply_fun,3},1},
+          {{shell,'-exprs/7-lc$^0/1-0-',1},1},
+          {{shell,'-eval_loop/3-fun-0-',3},1}]},
+  %% Information about many modules omitted.
+                     .
+                     .
+                     .
+  %% Here is the last part.
+  {erts_internal,2,[{{erts_internal,trace_pattern,3},2}]},
+  {otp_internal,1,[{{otp_internal,obsolete,3},1}]},
+  {maps,1,[{{maps,from_list,1},1}]},
+  {erl_internal,1,[{{erl_internal,bif,3},1}]}]}
 3> <input>cprof:analyse(cprof).</input>
 {cprof,3,[{{cprof,tr,2},2},{{cprof,pause,0},1}]}
 4> <input>cprof:stop().</input>
-3476</pre>
-    <p>The example showed the background work that the shell performs
-      just to interpret the first command line. Most work is done by
-      <c>erl_eval</c> and <c>orddict</c>.
-      </p>
+8586</pre>
+    <p>The example showed some of the background work that the shell
+    performs just to interpret the first command line.</p>
     <p>What is captured in this example is the part of the work the
       shell does while interpreting the command line that occurs
       between the actual calls to <c>cprof:start()</c> and
@@ -138,17 +143,17 @@
 1
 2> <input>cprof:analyse(calendar).</input>
 {calendar,9,
-          [{{calendar,df,2},1},
-           {{calendar,dm,1},1},
-           {{calendar,dy,1},1},
-           {{calendar,last_day_of_the_month1,2},1},
+          [{{calendar,last_day_of_the_month1,2},1},
            {{calendar,last_day_of_the_month,2},1},
            {{calendar,is_leap_year1,1},1},
            {{calendar,is_leap_year,1},1},
+           {{calendar,dy,1},1},
+           {{calendar,dm,1},1},
+           {{calendar,df,2},1},
            {{calendar,day_of_the_week,3},1},
            {{calendar,date_to_gregorian_days,3},1}]}
 3> <input>cprof:stop().</input>
-3271</pre>
+8648</pre>
     <p>The example tells us that "Aktiebolaget LM Ericsson &amp; Co"
       was registered on a Monday (since the return value
       of the first command is 1), and that the <c>calendar</c> module
@@ -164,66 +169,70 @@
     <p>Write a module:</p>
     <pre>
 -module(sort).
-      
 -export([do/1]).
-      
+
 do(N) ->
     cprof:stop(),
     cprof:start(),
     do(N, []).
-      
+
 do(0, L) ->
     R = lists:sort(L),
     cprof:pause(),
     R;
 do(N, L) ->
-    do(N-1, [random:uniform(256)-1 | L]).</pre>
+    do(N-1, [rand:uniform(256)-1 | L]).</pre>
     <p>From the Erlang shell:</p>
     <pre>
 1> <input>c(sort).</input>
 {ok,sort}
-2> <input>l(random).</input>
-{module,random}
+2> <input>rand:seed(default, 42), ok.</input>
+ok.
 3> <input>sort:do(1000).</input>
-[0,0,1,1,1,1,1,1,2,2,2,3,3,3,3,3,4,4,4,5,5,5,5,6,6,6,6,6,6|...]
+[0,0,0,1,1,1,1,2,2,3,3,4,4,4,4,5,5,5,6,6,6,6,7,7,7,7,7,8,8|...]
 4> <input>cprof:analyse().</input>
-{9050,
- [{lists_sort,6047,
-              [{{lists_sort,merge3_2,6},923},
-               {{lists_sort,merge3_1,6},879},
-               {{lists_sort,split_2,5},661},
-               {{lists_sort,rmerge3_1,6},580},
-               {{lists_sort,rmerge3_2,6},543},
-               {{lists_sort,merge3_12_3,6},531},
-               {{lists_sort,merge3_21_3,6},383},
-               {{lists_sort,split_2_1,6},338},
-               {{lists_sort,rmerge3_21_3,6},299},
-               {{lists_sort,rmerge3_12_3,6},205},
-               {{lists_sort,rmerge2_2,4},180},
-               {{lists_sort,rmerge2_1,4},171},
-               {{lists_sort,merge2_1,4},127},
-               {{lists_sort,merge2_2,4},121},
-               {{lists_sort,mergel,2},79},
-               {{lists_sort,rmergel,2},27}]},
-  {random,2001,
-          [{{random,uniform,1},1000},
-           {{random,uniform,0},1000},
-           {{random,seed0,0},1}]},
+{13180,
+ [{lists,6173,
+         [{{lists,rmerge3_1,6},1045},
+          {{lists,rmerge3_2,6},977},
+          {{lists,split_1,5},652},
+          {{lists,merge3_1,6},579},
+          {{lists,merge3_2,6},577},
+          {{lists,rmerge3_12_3,6},511},
+          {{lists,split_1_1,6},347},
+          {{lists,merge3_12_3,6},310},
+          {{lists,rmerge3_21_3,6},282},
+          {{lists,merge3_21_3,6},221},
+          {{lists,merge2_1,4},154},
+          {{lists,merge2_2,5},138},
+          {{lists,reverse,2},106},
+          {{lists,rmerge2_2,5},87},
+          {{lists,rmergel,2},81},
+          {{lists,rmerge2_1,4},75},
+          {{lists,mergel,2},28},
+          {{lists,keyfind,3},2},
+          {{lists,sort,1},1}]},
+  {rand,5000,
+        [{{rand,uniform_s,2},1000},
+         {{rand,uniform,1},1000},
+         {{rand,seed_put,1},1000},
+         {{rand,seed_get,0},1000},
+         {{rand,exsss_uniform,2},1000}]},
+  {erlang,1004,
+          [{{erlang,put,2},1000},
+           {{erlang,trace_pattern,3},2},
+           {{erlang,ensure_tracer_module_loaded,2},2}]},
   {sort,1001,[{{sort,do,2},1001}]},
-  {lists,1,[{{lists,sort,1},1}]}]}
+  {erts_internal,2,[{{erts_internal,trace_pattern,3},2}]}]}
 5> <input>cprof:stop().</input>
-5369</pre>
+12625</pre>
     <p>The example shows some details of how <c>lists:sort/1</c>
-      works. It used 6047 function calls in the module
-      <c>lists_sort</c> to complete the work.
-      </p>
-    <p>This time, since the shell was not involved, no other work was
-      done in the system during the profiling. If you retry the same
-      example with a freshly started Erlang emulator, but omit the
-      command <c>l(random)</c>, the analysis will show a lot more
-      function calls done by <c>code_server</c> and others to
-      automatically load the module <c>random</c>.
+      works. It used 6173 function calls in the module
+      <c>lists</c> to complete the work.
       </p>
+    <p>This time, since the shell was not involved in starting and
+    stopping <c>cprof</c>, no other work was done in the system during
+    the profiling.</p>
   </section>
 </chapter>
 
-- 
2.34.1

openSUSE Build Service is sponsored by