| 1 |
% Copyright 2017-2024 Martin Ruckert, Hochschule Muenchen, Lothstrasse 64, 80336 Muenchen |
| 2 |
% |
| 3 |
% Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
% of this software and associated documentation files (the "Software"), to deal |
| 5 |
% in the Software without restriction, including without limitation the rights |
| 6 |
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 |
% copies of the Software, and to permit persons to whom the Software is |
| 8 |
% furnished to do so, subject to the following conditions: |
| 9 |
% |
| 10 |
% The above copyright notice and this permission notice shall be |
| 11 |
% included in all copies or substantial portions of the Software. |
| 12 |
% |
| 13 |
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 17 |
% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT |
| 18 |
% OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 |
% THE SOFTWARE. |
| 20 |
% |
| 21 |
% Except as contained in this notice, the name of the copyright holders shall |
| 22 |
% not be used in advertising or otherwise to promote the sale, use or other |
| 23 |
% dealings in this Software without prior written authorization from the |
| 24 |
% copyright holders. |
| 25 |
\documentclass[a4paper,english]{article} |
| 26 |
\usepackage{a4wide} |
| 27 |
\usepackage{latex2man} |
| 28 |
|
| 29 |
\setVersion{1.1} |
| 30 |
\setDate{28-1-2025} |
| 31 |
|
| 32 |
\begin{document} |
| 33 |
\begin{Name}{1}{texprofile}{Martin Ruckert}{Displaying TeX profiles}{TeXprofile: Displaying TeX profiles} |
| 34 |
|
| 35 |
\Prog{texprofile} - Displaying the profile data collected by \Prog{texprof}. |
| 36 |
\end{Name} |
| 37 |
|
| 38 |
\section{Synopsis} |
| 39 |
|
| 40 |
\Prog{texprofile} [Options] \Arg{inputfile} |
| 41 |
|
| 42 |
\section{Description} |
| 43 |
\Prog{texprofile} reads the binary \Arg{inputfile} as produced by |
| 44 |
\Prog{texprof}. The extension \File{.tprof} of the input file can be |
| 45 |
omitted. It analyses the data and presents the results in a variety of |
| 46 |
tables, either optimized for human readability or as CSV (comma |
| 47 |
separated values) files for further processing. |
| 48 |
|
| 49 |
The output is written to the standard output stream where it can be redirected |
| 50 |
to a file or viewed immediately. |
| 51 |
|
| 52 |
\section{Options} |
| 53 |
There are four types of options: general options, table options, |
| 54 |
selection options, and formatting options. |
| 55 |
|
| 56 |
The general options: |
| 57 |
\begin{description} |
| 58 |
\item[\Opt{-?} \Opt{-h} \Opt{--help}] |
| 59 |
Display a short help text and exit the program. |
| 60 |
\item[\Opt{--version}] |
| 61 |
Display the version information and exit. |
| 62 |
\end{description} |
| 63 |
|
| 64 |
The table options determine the tables that will be displayed. |
| 65 |
These options all use upper case letters. |
| 66 |
If no table option is given, only some global information is shown. |
| 67 |
|
| 68 |
\begin{description} |
| 69 |
\item[\Opt{-T}] |
| 70 |
Show the table of the top 10 input lines. |
| 71 |
\item[\Opt{-G}] |
| 72 |
Show the table of the macro call graph. |
| 73 |
\item[\Opt{-C}] Show the table of times per TeX command. |
| 74 |
\item[\Opt{-L}] Show the table of times per input line. |
| 75 |
\item[\Opt{-R}] Show the table of raw time stamps. |
| 76 |
\item[\Opt{-S}] Show the table of macro stack changes. |
| 77 |
\item[\Opt{-F}] Show the table of all input files. |
| 78 |
\item[\Opt{-M}] Show the table of all macros called. |
| 79 |
\item[\Opt{-A}] Show important tables (equal to -TGFC) tables. |
| 80 |
\item[\Opt{-N}] Do not show the table of global information. |
| 81 |
\end{description} |
| 82 |
|
| 83 |
The selection options allow to reduce the amount of data that is shown |
| 84 |
in the table by omitting table entries that contribute little to the |
| 85 |
overall runtime. |
| 86 |
|
| 87 |
\begin{description} |
| 88 |
\item[\OptArg{-p}{n}] Do not show information for table entries |
| 89 |
with cumulative time below \Arg{n} percent. The default is 1.0 percent. |
| 90 |
\item[\OptArg{-t}{n}] Limit the number of input lines shown in the |
| 91 |
table of the ``Top Ten'' to \Arg{n}. This option is only useful |
| 92 |
with the \Opt{-T} option. |
| 93 |
\end{description} |
| 94 |
|
| 95 |
The formatting option determine the formatting of the information in the tables |
| 96 |
as well as the selection of information that is shown in the tables. |
| 97 |
|
| 98 |
\begin{description} |
| 99 |
\item[\Opt{-i}] |
| 100 |
Add the macros file and line numbers after the macro name. |
| 101 |
This option is useful to distinguish two macros that share |
| 102 |
the same name. |
| 103 |
\item[\Opt{-m}] |
| 104 |
Optimize output for machine readability. When optimized for human readability, |
| 105 |
times are rounded and given in a short form adding a unit identifier: |
| 106 |
s for seconds, ms for milliseconds, us for micro seconds, and ns for |
| 107 |
nanoseconds. This format is inconvenient if you want to import the data |
| 108 |
for example into a spread-sheet for further processing. |
| 109 |
With the \Opt{-m} option times are simply given in nano seconds without units. |
| 110 |
Similar the combined time for the total time used for a macro and the |
| 111 |
time used as a sub-macro from the call graph is given in a single column |
| 112 |
with a slash separating both numbers is nice for human readers. |
| 113 |
With the \Opt{-m} option both numbers will simply be given in separate columns. |
| 114 |
|
| 115 |
\item[\Opt{-n}] |
| 116 |
Show the time stamp numbers. This option is useful together with |
| 117 |
the \Opt{-R} option, if you import the table into a database or spread-sheet. |
| 118 |
If you sort the data by various properties into different |
| 119 |
categories, the time stamp number can be used to keeping the entries |
| 120 |
within a category sorted by time. |
| 121 |
|
| 122 |
\item[\Opt{-s}] |
| 123 |
Show the changes of the macro stack. |
| 124 |
This option is useful with the \Opt{-R} option if you want to see the changes |
| 125 |
in the macro stack (see \Opt{-S}) together with the timing information in |
| 126 |
a single table. |
| 127 |
\end{description} |
| 128 |
|
| 129 |
|
| 130 |
\section{Data Formats} |
| 131 |
\subsection{File Numbers} |
| 132 |
While \Prog{texprof} is running, every TeX input file is given a |
| 133 |
unique file number. The file name alone is often not unique because |
| 134 |
two files in different directories might have the same file |
| 135 |
name. Displaying the full file name with the complete path is however often |
| 136 |
not very |
| 137 |
convenient. So if you observe the same file name together with |
| 138 |
different file numbers, you can use the option \Opt{-F} to get a table of all |
| 139 |
file numbers and their full file names. |
| 140 |
|
| 141 |
But even within the same |
| 142 |
directory, TeX can read different files with the same name during one |
| 143 |
run: TeX can open a file for writing, write content to the file, close |
| 144 |
it, open it for reading, read it and close it again. Then TeX might |
| 145 |
repeat this process a second time, or multiple times, reusing the same |
| 146 |
file name over and over again. \Prog{texprof} will assign a new file |
| 147 |
number to this file each time it is opened for reading. So you can |
| 148 |
tell from the sequence of file numbers which one was the first, the |
| 149 |
second, or the third. |
| 150 |
|
| 151 |
Last not least, there are some special file |
| 152 |
numbers: |
| 153 |
\begin{description} |
| 154 |
\item[0 - unknown] |
| 155 |
If the file is unknown, which should rarely happen, |
| 156 |
the file number 0 is used. |
| 157 |
\item[1- system] |
| 158 |
\Prog{texprof} will map |
| 159 |
time intervals that are used to execute certain system routines |
| 160 |
to the ``system'' pseudo file |
| 161 |
using the line numbers to identify the specific routine |
| 162 |
like producing the output DVI file (shipout), breaking |
| 163 |
a paragraph into lines (linebrk), or breaking the |
| 164 |
document into pages (buildpg). These times do not depend on the |
| 165 |
use of macros but simply on the size of the document. |
| 166 |
\item[2 - terminal] |
| 167 |
TeX commands entered on the command line or interactively are mapped |
| 168 |
to file number 2. |
| 169 |
\end{description} |
| 170 |
|
| 171 |
\subsection{Time} |
| 172 |
If the option \Opt{-m} is given times are given as nanoseconds. |
| 173 |
Otherwise, times are rounded to at most 4 digits precission and |
| 174 |
displayed with a unit: seconds (s), milliseconds (ms), microseconds |
| 175 |
(um), or nanoseconds (ns). |
| 176 |
|
| 177 |
\subsection{Macro Names} |
| 178 |
Macro names are shown with the leading backslash. Since macro names |
| 179 |
are often not unique, the command line option \Opt{-i} can be used to |
| 180 |
show after the macro name in square brackets the file number and the |
| 181 |
line number where the macro is defined. Unless two macros with the |
| 182 |
same name are defined in the same file and line this is sufficient to |
| 183 |
uniquely identify a macro. A macro defined with ``let'' results in a |
| 184 |
complet copy of the original macro. Therefore it will not reference |
| 185 |
the file and line of the ``let'' command but the same file and line as |
| 186 |
the original macro. |
| 187 |
|
| 188 |
\section{Examples} |
| 189 |
Let's assume that you issue the command \Prog{texprof} \Opt{-prof} |
| 190 |
\Arg{hello.tex}. This will run \Prog{texprof} on the input file |
| 191 |
\Arg{hello.tex} with option \Opt{-prof}. The program \Prog{texprof} |
| 192 |
will load the plain TeX format and then process \File{hello.tex} to |
| 193 |
produce \File{hello.log} and \File{hello.dvi}. It will execute |
| 194 |
exactly the same steps that TeX would execute if you had issued the |
| 195 |
command \Prog{tex} \Arg{hello.tex}. |
| 196 |
|
| 197 |
In addition to \File{hello.log} and \File{hello.dvi}, \Prog{texprof} |
| 198 |
will also produce the file \File{hello.tprof} containing time |
| 199 |
measurements made while \Prog{texprof} was running. The option |
| 200 |
\Opt{-prof} will switch on the gathering of timing data as soon as |
| 201 |
\Prog{texprof} enters its main control procedure; The file |
| 202 |
\File{hello.tprof} will contain a time measurement, called a time |
| 203 |
stamp, for every command that TeX executed while processing the input. |
| 204 |
A binary format is used to store all that data in a simple and compact |
| 205 |
form. Still the file \File{hello.tprof} might become very big. |
| 206 |
|
| 207 |
The program \Prog{texprofile} is used to extract and analyse the data |
| 208 |
contained in \File{hello.tprof} and produce useful output. Here are |
| 209 |
some examples: |
| 210 |
|
| 211 |
\begin{description} |
| 212 |
\item[\Prog{texprofile} \Arg{hello}] |
| 213 |
Without further options \Prog{texprofile} will write some general |
| 214 |
information to the standard output, like the total time measured, |
| 215 |
the number of samples, the average time per sample, etc. |
| 216 |
The general information is always given unless explicitely disabled |
| 217 |
with the \Opt{-N} option or with the \Opt{-m} option. |
| 218 |
|
| 219 |
\item[\Prog{texprofile} \Opt{-T} \Arg{hello}] |
| 220 |
With the option \Opt{-T}, \Prog{texprofile} will map each time stamp |
| 221 |
to a specific line of input, add up the time intervalls for each input |
| 222 |
line separately, and output a table showing the ten lines that have |
| 223 |
the highest cummulative time. |
| 224 |
The table has the following seven columns: |
| 225 |
\begin{description} |
| 226 |
\item[1. file] |
| 227 |
The first column contains the input file number as explained above. |
| 228 |
The input file name if shown in column 7. |
| 229 |
\item[2. line] |
| 230 |
The line number. |
| 231 |
\item[3. percent] |
| 232 |
The time spent in this line and file as a percentage of the total |
| 233 |
time measured as given as part of the general information. |
| 234 |
\item[4. absolute] |
| 235 |
The absolute time spent in this line and file. |
| 236 |
\item[5. count] |
| 237 |
The number of times the execution path entered this line. |
| 238 |
Note, that a |
| 239 |
macro call usually redirects the execution path to another line |
| 240 |
from where the execution will return after the macro call has completed. |
| 241 |
Reentering the line after such an excursion to an other line will |
| 242 |
cause this counter to be incremented. In summary, this counter might |
| 243 |
reflect the number of partial executions of a line not the number |
| 244 |
of full executions of the entire line. |
| 245 |
\item[6. average] |
| 246 |
The average time spent in the line is simply computed by dividing the |
| 247 |
value in column 4 by the value in column 5. |
| 248 |
\item[7. file] |
| 249 |
The input file name. The corresponding file number is shown in column 1. |
| 250 |
\end{description} |
| 251 |
|
| 252 |
\item[\Prog{texprofile} \Opt{-G} \Arg{hello}] |
| 253 |
With the option \Opt{-G}, \Prog{texprofile} will map each time stamp |
| 254 |
either to file input or to a macro body. |
| 255 |
The table shown is divided into several sections, the first section |
| 256 |
is devoted to file input, each of the following sections is devoted |
| 257 |
to a specific macro. |
| 258 |
\\ |
| 259 |
Each section starts with a header. The header of the |
| 260 |
first section is ``File'' the header of a later section is the macro name. |
| 261 |
\\ |
| 262 |
The first line after the header gives the total time spent in the section |
| 263 |
in two different formats: |
| 264 |
\begin{description} |
| 265 |
\item[1. time] |
| 266 |
Column 1 gives it as an absolut time. |
| 267 |
\item[3. percentage] |
| 268 |
Column 3 gives it as a percentage of the total time measured. |
| 269 |
\end{description} |
| 270 |
For the first section with the header ``File'', the absolute time |
| 271 |
will be equal to the total time measured because \Prog{texprof} |
| 272 |
did spent all the time processing the file \Arg{hello}. |
| 273 |
And consequently the value in column 3 will be 100\%. |
| 274 |
\\ |
| 275 |
To accomplish a task, a macro usually calls other |
| 276 |
macros that we call child macros in the following. |
| 277 |
The following lines in the table will give a breakdown |
| 278 |
of the time shown in the first line. |
| 279 |
The breakdown starts with a line showing the time spent in the section |
| 280 |
excluding the time spent in child macros. It shows in column 4 the number |
| 281 |
of times the macro was called. |
| 282 |
\begin{description} |
| 283 |
\item[1. time] |
| 284 |
Column 1 gives the absolut time spent in the section excluding the time |
| 285 |
spent in child macros |
| 286 |
\item[3. percentage] |
| 287 |
Column 3 gives the time from column 1 as a percentage of the total time |
| 288 |
spent in this section as given in the previous line. |
| 289 |
\item[4. count/total] |
| 290 |
Column 4 gives the number of times the section was called. |
| 291 |
\end{description} |
| 292 |
The lines that follow in the table show the time spent in one of |
| 293 |
the child macros. Column 2, 4, and 5 need some explanation. |
| 294 |
\begin{description} |
| 295 |
\item[2. loop] |
| 296 |
The only case where column 2 is not empty is the case of a |
| 297 |
recursive macro. A recursive macro is a macro that along the |
| 298 |
chain of macro calls eventually calls itself creating a |
| 299 |
recursive loop. At this point, a macro becomesits own descendant |
| 300 |
and at the same time its own ancestor. |
| 301 |
\\ |
| 302 |
Therefore \Prog{texprofile} maintains for each child macro two |
| 303 |
accumulators for the elapsed time: For the time shown in |
| 304 |
column 2 labeled ``loop'', \Prog{texprofile} adds up the time |
| 305 |
differences observed at the return of a child macro. For the |
| 306 |
time shown in the column labeled ``time'' and ``percent'', it |
| 307 |
subtracts from the time differences observed at the return of a |
| 308 |
child macro all those time differences that were already added |
| 309 |
to one of the other lines in the time breakdown: the macro itself |
| 310 |
or one of the other child macros. |
| 311 |
So the times shown in column 1 of line 2 and the following lines |
| 312 |
will add up to the time shown in column 1 of the line 1; |
| 313 |
and the percentages shown in column 3 of line 2 and the following lines |
| 314 |
will add up to 100\%. |
| 315 |
The time shown in column 3 will show show the total time needed |
| 316 |
to accomplish the sub task assigned to the respective child macro. |
| 317 |
\item[4. count/total] |
| 318 |
Column 4 shows two counts $n/m$ for the macro named in column 5. |
| 319 |
$m$ is the total number of calls to the macro and $n$ is the number of |
| 320 |
calls as a child macro in the current section. The number $n$ will |
| 321 |
always be less or equal to $m$. |
| 322 |
|
| 323 |
\item[5. child] |
| 324 |
Column 5 shows the name of the child macro as explained above. |
| 325 |
\end{description} |
| 326 |
\item[\Prog{texprofile} \Opt{-G} \Opt{-m} \Arg{hello}] |
| 327 |
This table will contain the same data as the previous example |
| 328 |
but this time the \Opt{-m} option will optimize the output for |
| 329 |
machine readability. |
| 330 |
\begin{itemize} |
| 331 |
\item There are no column headers. |
| 332 |
\item The times in column 1 ``time'' and column 2 ``loop'' |
| 333 |
are given in nanoseconds without a unit identifier. |
| 334 |
\item The numbers $n/m$ in column 4 are now shown in two separate |
| 335 |
columns 4 and 5; the macro name moves from column 5 to column 6. |
| 336 |
\end{itemize} |
| 337 |
|
| 338 |
\item[\Prog{texprofile} \Opt{-F} \Arg{hello}] |
| 339 |
With the option \Opt{-F}, \Prog{texprofile} outputs the table |
| 340 |
of all of TeX's input files using 5 columns: |
| 341 |
\begin{description} |
| 342 |
\item[1. file] The file number as explained above. |
| 343 |
\item[2. lines] The difference between the highest and the lowest |
| 344 |
line number found in the profile data for this file. This is |
| 345 |
usually only a subset of all the lines of the file. |
| 346 |
\item[3. percent] |
| 347 |
The percentage of the total time measured that is attibuted to the file. |
| 348 |
\item[4. time] |
| 349 |
The absolute time that is attibuted to the file. |
| 350 |
\item[5. name] |
| 351 |
The full file name of the file. |
| 352 |
\end{description} |
| 353 |
\item[\Prog{texprofile} \Opt{-C} \Arg{hello}] |
| 354 |
With the option \Opt{-C}, \Prog{texprofile} outputs the table |
| 355 |
of all TeX commands executed while profiling |
| 356 |
using 6 columns: |
| 357 |
\begin{description} |
| 358 |
\item[1. cmd] The command code used internaly by TeX. |
| 359 |
Usually the same number is used by TeX for several |
| 360 |
closely related tasks. |
| 361 |
There is a special command code 101 which is used to |
| 362 |
for the time that is spend on system routines that are |
| 363 |
mapped to the system file as explained above. |
| 364 |
\item[2. time] |
| 365 |
The total time used for the command. |
| 366 |
\item[3. percent] |
| 367 |
The percentage of the total time measured used for the command. |
| 368 |
\item[4. count] |
| 369 |
The number of times this command was executed. |
| 370 |
\item[5. average] |
| 371 |
The average time needed to execute the command. |
| 372 |
This is simpy the value in column 2 divided by the value in column 4. |
| 373 |
\item[6. name] |
| 374 |
A verbal description of the command or commands that share this |
| 375 |
command code. |
| 376 |
\end{description} |
| 377 |
\item[\Prog{texprofile} \Opt{-R} \Opt{-m} \Opt{-n} \Arg{hello}] |
| 378 |
With the options \Opt{-R} \Opt{-m}, \Prog{texprofile} outputs the table |
| 379 |
of raw time measurements as observed by \Prog{texprof} optimized for machine |
| 380 |
readability. The option \Opt{-n} adds a column for the number |
| 381 |
of each time measurements. |
| 382 |
Because of the \Opt{-m} option, the table has no column headers. |
| 383 |
The table has 7 columns: |
| 384 |
\begin{description} |
| 385 |
\item[1. number] The number of the time measurment. |
| 386 |
These numbers are strictly increasing but not necessarily consecutive. |
| 387 |
They can be used to keep the measurements sorted in the order in which |
| 388 |
they were made. |
| 389 |
\item[2. file] The file number as explained above. |
| 390 |
\item[3. line] The line number as explained above. |
| 391 |
\item[4. time] The time interval in nano seconds. |
| 392 |
\item[5. command] The command name as given in column 6 of the previous example. |
| 393 |
\item[6. level ] The nesting level of the macro call stack. |
| 394 |
\item[7. macro] The macro name. |
| 395 |
\end{description} |
| 396 |
This table contains all the timing information gathered during the run |
| 397 |
of \Prog{texprof}. Some information about macro calls is contained in |
| 398 |
column 6. More information about macro calls could be added |
| 399 |
by using the \Opt{-s} option. The information about macro returns |
| 400 |
can be obtained from column 6. |
| 401 |
The table can be imported to a spread-sheet or a database for further |
| 402 |
analysis. |
| 403 |
\end{description} |
| 404 |
|
| 405 |
|
| 406 |
\section{Bugs} |
| 407 |
If the last command in a macro body is a macro call, we call this a tail call. |
| 408 |
If such a tail call reads ahead to scan the following input |
| 409 |
for possible arguments, the look-ahead mechaism of TeX might push further |
| 410 |
macros or new input files on TeX's input stack. |
| 411 |
These entries will remain on top of TeXprof's macro nesting stack, |
| 412 |
even if TeX backs up all these tokens on its input stack. |
| 413 |
This can cause an attribution of runtime to those entries as sub entries |
| 414 |
of the tail call. If this explanation sounds complicated to you, it is |
| 415 |
because the situation is indeed complicated. |
| 416 |
|
| 417 |
\section{See Also} |
| 418 |
\Cmd{texprof}{1} |
| 419 |
|
| 420 |
|
| 421 |
\section{Version} |
| 422 |
Version: \Version\ of \Date |
| 423 |
\begin{description} |
| 424 |
\item[Copyright] \copyright\ 2024, Martin Ruckert,\\ |
| 425 |
Hochschule München, Lothstrasse 64, D-80335 München |
| 426 |
|
| 427 |
\item[Distribution] |
| 428 |
\Prog{texprofile} is distributed with TeX Live. |
| 429 |
More recent versions might be found on GitHub |
| 430 |
\URL{https://github.com/ruckertm/HINT}. |
| 431 |
|
| 432 |
\item[License] This program can be redistributed and/or modified under the |
| 433 |
terms of the MIT/X11 license. |
| 434 |
\end{description} |
| 435 |
|
| 436 |
\section{Author} |
| 437 |
\noindent |
| 438 |
Martin Ruckert \\ |
| 439 |
Munich University of Applied Sciences \\ |
| 440 |
Email: \Email{[email protected]} \\ |
| 441 |
|
| 442 |
\end{document} |