Function frequency: Difference between revisions

m
Line 1,160:
log_function_call(rtnNo)
</pre>
(I may have been a bit too literal about "function" here, specifically "not procedure")
 
Now create our test.exw program, which wraps the entire compiler:
<lang Phix>constant func_log = new_dict(),
Line 1,192 ⟶ 1,194:
traverse_dict(r_visitor,2,func_freq,rev:=true) -- top 10</lang>
Invoke using "p test -norun test" (note you can omit the ".exw" part of "test.exw")
 
Notes:<br>
The log_function call is passed an index into the symbol table.<br>
For performance reasons the compiler uses integer indexes, so we need to invoke
rebuild_callback() to replace them with human-readable names in the symbol table.<br>
For more details of S_Name and other constants/contents of the symbol table, see pglobals.e<br>
The compiler (p.exe) interprets test.exw(+p.exw) which compiles a third copy of itself under -norun.<br>
Notice that it is not necessary to compile the compiler (using p -c p) to test changes in it, and in
fact weeks or months of work on the compiler often happens purely in interpreter mode, between actually
creating a new executable.<br>
If, instead, you want to know how many times a function is called at run-time, just add "with profile"
to the source and it will create a ex.pro listing which tells you.
 
Lastly, remember to remove/comment out that log_function_call() in pmain.e
{{out}}
<pre>
Line 1,220 ⟶ 1,208:
{90,"platform"}
</pre>
Notes:<br>
The log_function call is passed an index into the symbol table.<br>
For performance reasons the compiler uses integer indexes, so we need to invoke
rebuild_callback() to replace them with human-readable names in the symbol table.<br>
For more details of S_Name and other constants/contents of the symbol table, see pglobals.e<br>
The compiler (p.exe) interprets test.exw(+p.exw) which compiles a third copy of itself under -norun.<br>
Notice that it is not necessary to compile the compiler (using p -c p) to test changes in it, and in
fact weeks or months of work on the compiler often happens purely in interpreter mode, between actually
creating a new executable.<br>
If, instead, you want to know how many times a function is called at run-time, just add "with profile"
to the source and it will create a ex.pro listing which tells you.
 
Lastly, remember to remove/comment out that log_function_call() in pmain.e
 
=={{header|PicoLisp}}==
7,806

edits