Section Intro: Code Profiling
The profiler module allows you to get a detailed listing of the number of times a particular function has executed, the amount of time spent within each function, and other information which can help you to tune your Meta-HTML application, and get it running as fast as possible.
The use of this module is trivial. First, place
<set-var mhtml::profile-functions = true>at the top of the page that you would like to profile.
At the bottom of the page, after the last normal instruction, place
After visiting the page in a browser, the file /tmp/meta.prog will contain a human readable dump of the profile information. Your page won't perceptibly slow down during loading -- the only indication that profiling is on is the creation of the output file that you specify.
Place the amount of time it takes to execute CODE into VARNAME. The value appears as a floating point number which represents the elapsed time in milliseconds (by default -- use the UNITS keyword argument to change this).
<measuring-elapsed-time timer> <set-var sample-code=<get-var x>> </measuring-elapsed-time> It took <get-var timer> milliseconds to execute the sample code.produces:
; It took milliseconds to execute the sample code.
Returns the number of milliseconds that have elapsed since Jan 1st, 1970, as a large floating point value.
This can be more convenient to use than <measuring-elapsed-time> since the use of it can be broken up across many include files. It isn't as accurate to use this over <measuring-elapsed-time> since the overhead of setting a variable and getting its value is included in your timing:
<set-var start=<mtime>> <set-var sample-code=<get-var x>> <set-var end=<mtime>> It took <sub end start> milliseconds to execute the sample code.produces:
It took 0.00 milliseconds to execute the sample code.
Write profiling information to FILENAME. Unlike C profilers, the output is quite self-explanatory.
To try it out, do the following in mdb:
<set-var mhtml::profile-functions = true> <set-var x=<make-alist foo=bar bar=<make-alist foo=bar>>> <profiler::dump /tmp/alist.calls sort=calls> <profiler::dump /tmp/alist.time sort=time> <profiler::dump /tmp/alist.expense sort=expense>
Known bugs: The total time doesn't really correctly reflect the amount of time spent processing the entire page -- the time displayed is additive, so it is always orders of magnitude larger than it should be. However, the time displayed for each function call is correct.
The META-HTML Reference Manual V2.0 Copyright © 1995, 1998, Brian J. Fox
Found a bug? Send mail to firstname.lastname@example.org