Debian Codegraph @

texmf-dist/tex/generic/pgf/libraries/pgflibraryprofiler.code.tex

raw
1 %--------------------------------------------
2 %
3 % TeX profiling library
4 %
5 % Copyright 2018 by Christian Feuersänger.
6 %
7 % This program is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % This program is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %
20 %--------------------------------------------
21
22 \pgfutil@ifundefined{pdfelapsedtime}{%
23 % Ok, \pdfelapsedtime is not defined.
24 % Maybe we run luatex?
25 \pgfutil@ifluatex
26 % Yes. So we emulate the primitive by a macro.
27 % (see http://tex.stackexchange.com/q/32507/8425)
28 \def\pgfutil@pdfelapsedtime{%
29 \numexpr\pgfutil@directlua{%
30 tex.print(math.floor((os.clock())*65536+0.5))}\relax}
31 \else
32 % Raise an error
33 \pgferror{%
34 Library 'profiler' can only be used with pdftex Rev. >= 1.671
35 because it needs the \string\pdfelapsedtime\space command or
36 with luatex}%
37 \global\let\pgfutil@pdfelapsedtime=\c@pgf@counta
38 \fi}{%
39 % We run pdftex. That's ok.
40 \let\pgfutil@pdfelapsedtime\pdfelapsedtime}%
41
42
43 % Defines a new profiler entry named `#1'.
44 %
45 % This allocates a set of counters.
46 \def\pgfprofilenew#1{%
47 \pgfutil@ifundefined{c@pgfprofile@elapsedtotal@#1}{%
48 \expandafter\gdef\csname c@pgfprofile@elapsedtotal@#1\endcsname{0}%
49 \expandafter\gdef\csname c@pgfprofile@elapsedself@#1\endcsname{0}%
50 \expandafter\gdef\csname c@pgfprofile@numinvocations@#1\endcsname{0}%
51 \expandafter\gdef\csname c@pgfprofile@subtractforself@#1\endcsname{0}%
52 \expandafter\gdef\csname c@pgfprofile@semaphor@#1\endcsname{0}%
53 \expandafter\gdef\csname c@pgfprofile@elapsed@at@start@#1\endcsname{0}%
54 \pgfprofile@all@registered@list@add{#1}%
55 }{%
56 % it is already defined and registered. Shouldn't hurt, might
57 % even be a good feature.
58 }%
59 }%
60
61 \def\pgfprofile@TeX@DIALECT@toenvironment@begin#1{\csname #1\endcsname}%
62 \def\pgfprofile@TeX@DIALECT@toenvironment@end#1{\csname end#1\endcsname}%
63
64 \def\pgfprofile@@to@pgfretval#1{%
65 \expandafter\let\expandafter\pgfretval#1%
66 }%
67
68 % Defines a new profiler entry for the environment `#1'.
69 %
70 % This calls \pgfprofilenew and handles the begin/end of the
71 % environment automatically.
72 %
73 % #1 the environment name (a string)
74 %
75 % Optionally in square brackets: the profiler entry name
76 % \pgfprofilenewforenvironment{<environment name>}
77 % \pgfprofilenewforenvironment[<profiler entry name>]{<environment name>}
78 \def\pgfprofilenewforenvironment{\pgfutil@ifnextchar[{\pgfprofilenewforenvironment@}{\pgfprofilenewforenvironment@[]}}%
79 \def\pgfprofilenewforenvironment@[#1]#2{%
80 \expandafter\pgfprofile@@to@pgfretval\pgfprofile@TeX@DIALECT@toenvironment@begin{#2}%
81 \ifx\pgfretval\relax
82 \pgferror{\string\pgfprofilenewforenvironment{#2} doesn't work: the environment `#2' is (not yet?) known or not known in this context}{}%
83 \else
84 \expandafter\global\expandafter\let\csname pgfprofile@orig@begin@#2\endcsname=\pgfretval
85 \expandafter\pgfprofile@@to@pgfretval\pgfprofile@TeX@DIALECT@toenvironment@end{#2}%
86 \expandafter\global\expandafter\let\csname pgfprofile@orig@end@#2\endcsname=\pgfretval
87 %
88 \def\pgfprofile@temp{#1}%
89 \ifx\pgfprofile@temp\pgfutil@empty
90 \pgfprofilenewforenvironment@@{\pgfprofileenv #2}{#2}%
91 \else
92 \pgfprofilenewforenvironment@@{#1}{#2}%
93 \fi
94 \fi
95 }%
96 \def\pgfprofilenewforenvironment@@#1#2{%
97 \pgfprofilenew{#1}%
98 \expandafter\expandafter\expandafter\gdef\pgfprofile@TeX@DIALECT@toenvironment@begin{#2}{%
99 \pgfprofilestart{#1}%
100 \csname pgfprofile@orig@begin@#2\endcsname
101 }%
102 \expandafter\expandafter\expandafter\gdef\pgfprofile@TeX@DIALECT@toenvironment@end{#2}{%
103 \csname pgfprofile@orig@end@#2\endcsname
104 \pgfprofileend{#1}%
105 }%
106 }%
107
108
109 \def\pgfprofilecs{<CS>}%
110 \def\pgfprofileenv{<ENV>}%
111
112 % Defines a new profiler entry for the control sequence '#1'.
113 %
114 % This calls \pgfprofilenew and enhances the control sequence with
115 % support for timings.
116 %
117 % #1: the control sequence (with backslash!)
118 % #2: the number of arguments (see below).
119 %
120 % The following commands are supported:
121 % - commands which take one (optional) argument in square brackets,
122 % - commands which take one (optional) argument in square brackets
123 % followed by one optional argument which has to be delimited with
124 % curly braces (use an empty argument for '#2' in this case),
125 % - commands which take one (optional) argument in square brackets
126 % and *exactly* #2 arguments afterwards.
127 \def\pgfprofilenewforcommand{\pgfutil@ifnextchar[{\pgfprofilenewforcommand@}{\pgfprofilenewforcommand@[]}}%
128 \def\pgfprofilenewforcommand@[#1]#2#3{%
129 \def\pgfprofile@temp{#3}%
130 \ifx\pgfprofile@temp\pgfutil@empty
131 \pgfprofilenewforcommandpattern[#1]{#2}{<autocheck>}{}%
132 \else
133 \ifcase#3\relax
134 \pgfprofilenewforcommandpattern[#1]{#2}{}{}%
135 \or
136 \pgfprofilenewforcommandpattern[#1]{#2}{##1}{{##1}}%
137 \or
138 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2}{{##1}{##2}}%
139 \or
140 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2##3}{{##1}{##2}{##3}}%
141 \or
142 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2##3##4}{{##1}{##2}{##3}{##4}}%
143 \or
144 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2##3##4##5}{{##1}{##2}{##3}{##4}{##5}}%
145 \or
146 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2##3##4##5##6}{{##1}{##2}{##3}{##4}{##5}{##6}}%
147 \or
148 \pgfprofilenewforcommandpattern[#1]{#2}{##1##2##3##4##5##6##7}{{##1}{##2}{##3}{##4}{##5}{##6}{##7}}%
149 \else
150 \pgferror{library 'profiler' can't replace control sequences with '#3' arguments automatically, sorry.}{}%
151 \fi
152 \fi
153 }%
154
155 % \pgfprofilenewforcommandpattern[<profile entry name>]{<\CS>}{<definition pattern>}{<invocation pattern>}
156 %
157 % example:
158 % \pgfprofilenewforcommandpattern{\pgfqkeys}{##1##2}{{##1}{##2}}
159 %
160 % \def\mymacro##1\to##2\in##3{ .... }
161 % \pgfprofilenewforcommandpattern{\mymacro}{##1\to##2\in##3}{{##1}\to{##2}\in{##3}}
162 \def\pgfprofilenewforcommandpattern{\pgfutil@ifnextchar[{\pgfprofilenewforcommandpattern@}{\pgfprofilenewforcommandpattern@[]}}%
163 \def\pgfprofilenewforcommandpattern@[#1]#2#3#4{%
164 \def\pgfprofile@known{1}%
165 \ifx#2\undefined
166 \def\pgfprofile@known{0}%
167 \else
168 \ifx#2\relax
169 \def\pgfprofile@known{0}%
170 \fi
171 \fi
172 \if\pgfprofile@known0%
173 \pgferror{\string\pgfprofilenewforcommandpattern{\string#2} doesn't work: the command `\string#2' is (not yet?) known or not known in this context}%
174 \else
175 \begingroup
176 \pgfprofile@cs@to@name{#2}%
177 \let\pgfprofilenew@cmdname=\pgfretval
178 %
179 \def\pgfprofile@temp{#1}%
180 \ifx\pgfprofile@temp\pgfutil@empty
181 \edef\pgfprofilenew@profilerentryname{\pgfprofilecs\pgfprofilenew@cmdname}%
182 \else
183 \edef\pgfprofilenew@profilerentryname{#1}%
184 \fi
185 \expandafter\global\expandafter\let\csname pgfprofile@name@for@\pgfprofilenew@cmdname\endcsname=\pgfprofilenew@profilerentryname
186 \pgfprofilenew{\pgfprofilenew@profilerentryname}%
187 \expandafter\gdef\csname b@pgfprofile@show@\pgfprofilenew@profilerentryname\endcsname{0}%
188 %
189 \expandafter\global\expandafter\let\csname pgfprofile@orig@\pgfprofilenew@cmdname\endcsname=#2%
190 \toks0={#3}%
191 \edef\pgfprofile@temp{\the\toks0}%%
192 \def\pgfprofile@tempb{<autocheck>}%
193 \ifx\pgfprofile@temp\pgfprofile@tempb
194 \expandafter\global\expandafter\let\csname pgfprofile@repl@\pgfprofilenew@cmdname\endcsname=\pgfprofileinvokecommand@uptoonearg
195 \else
196 \expandafter\gdef\csname pgfprofile@repl@\pgfprofilenew@cmdname\endcsname#3{%
197 \pgfprofile@invokeorig{#4}%
198 }%
199 \fi
200 \xdef#2{\noexpand\pgfprofileinvokecommand{\pgfprofilenew@cmdname}}%
201 \endgroup
202 \fi
203 }%
204
205 \def\pgfprofileshowinvocationsfor#1{%
206 \pgfutil@ifundefined{b@pgfprofile@show@#1}{%
207 \pgferror{\string\pgfprofileshowinvocationsfor{#1} doesn't work: the argument is no profiler entry}%
208 }{%
209 \expandafter\gdef\csname b@pgfprofile@show@#1\endcsname{1}%
210 \expandafter\gdef\csname b@pgfprofile@show@edef@#1\endcsname{0}%
211 }%
212 }%
213 \def\pgfprofileshowinvocationsexpandedfor#1{%
214 \pgfutil@ifundefined{b@pgfprofile@show@#1}{%
215 \pgferror{\string\pgfprofileshowinvocationsfor{#1} doesn't work: the argument is no profiler entry}%
216 }{%
217 \expandafter\gdef\csname b@pgfprofile@show@#1\endcsname{1}%
218 \expandafter\gdef\csname b@pgfprofile@show@edef@#1\endcsname{1}%
219 }%
220 }%
221
222 \def\pgfprofile@no@optional@arg@text{<noarg>}%
223 \def\pgfprofileinvokecommand#1{%
224 \pgfutil@ifnextchar[{\pgfprofileinvokecommand@{#1}}{\pgfprofileinvokecommand@{#1}[<noarg>]}%
225 }%
226 \def\pgfprofileinvokecommand@#1[#2]{%
227 \def\pgfprofileinvokecommand@cs{#1}%
228 \def\pgfprofileinvokecommand@optarg{#2}%
229 \edef\pgfprofileinvokecommand@profilerentryname{\csname pgfprofile@name@for@#1\endcsname}%
230 \csname pgfprofile@repl@#1\endcsname%
231 }%
232
233 % #1 contains ALL arguments, including any braces.
234 \def\pgfprofile@invokeorig#1{%
235 % re-insert the control sequence name and the optional argument:
236 % this wasn't possible directly.
237 \begingroup
238 \toks1=\expandafter{\pgfprofileinvokecommand@optarg}%
239 \toks2={#1}%
240 \toks3=\expandafter{\csname pgfprofile@orig@\pgfprofileinvokecommand@cs\endcsname}%
241 %
242 \ifx\pgfprofileinvokecommand@optarg\pgfprofile@no@optional@arg@text
243 % no [] argument after original command:
244 \xdef\pgfprofile@invokeorig@doitfinally{\the\toks3 \the\toks2 }%%
245 \else
246 \xdef\pgfprofile@invokeorig@doitfinally{\the\toks3[\the\toks1]\the\toks2 }%
247 \fi
248 \if1\csname b@pgfprofile@show@\pgfprofileinvokecommand@profilerentryname\endcsname
249 \pgfprofile@orig@show
250 \fi
251 \endgroup
252 \edef\pgfprofile@temp{{\pgfprofileinvokecommand@cs}{\pgfprofileinvokecommand@profilerentryname}}%
253 \expandafter\pgfprofile@invokeorig@\pgfprofile@temp%
254 }%
255 \def\pgfprofile@orig@show{%
256 \toks4=\expandafter{\csname\pgfprofileinvokecommand@cs\endcsname}%
257 \ifx\pgfprofileinvokecommand@optarg\pgfprofile@no@optional@arg@text
258 \def\pgfprofile@orig@show@args{\the\toks2 }%
259 \else
260 \def\pgfprofile@orig@show@args{[\the\toks1] \the\toks2 }%
261 \fi
262 \if1\csname b@pgfprofile@show@edef@\pgfprofileinvokecommand@profilerentryname\endcsname
263 \edef\pgfprofile@orig@show@args{\pgfprofile@orig@show@args}%
264 \edef\pgfprofile@orig@show@args{\pgfprofile@orig@show@args}%
265 \fi
266 \pgf@typeout{pgflibraryprofiler: calling
267 \#\csname c@pgfprofile@numinvocations@\pgfprofileinvokecommand@profilerentryname\endcsname\space
268 (\the\toks4 \pgfprofile@orig@show@args)}%
269 }%
270
271 % #1: control sequence name (without backslash)
272 % #2: profiler entry name
273 \def\pgfprofile@invokeorig@#1#2{%
274 % this check should avoid save stack impact
275 \pgfprofileifisrunning{#2}{%
276 \pgfprofile@invokeorig@doitfinally%
277 }{%
278 \pgfprofilestart{#2}%
279 \pgfprofile@invokeorig@doitfinally%
280 \pgfprofileend{#2}%
281 }%
282 }%
283
284
285 \def\pgfprofileinvokecommand@uptoonearg{%
286 \pgfutil@ifnextchar\bgroup{\pgfprofileinvokecommand@onearg}{\pgfprofileinvokecommand@noarg}%
287 }%
288 \def\pgfprofileinvokecommand@onearg#1{%
289 \pgfprofile@invokeorig{{#1}}%
290 }%
291 \def\pgfprofileinvokecommand@noarg{%
292 \pgfprofile@invokeorig{}%
293 }%
294
295
296
297 % Starts / Resumes timing of the profiler entry named `#1'.
298 %
299 % The timing will continue until \pgfprofileend{#1} is called.
300 %
301 % Nested calls of \pgfprofilestart{#1} (with the same argument) will
302 % result in the same result as if just one \pgfprofilestart command
303 % has been issued.
304 \def\pgfprofilestart#1{%
305 \pgfprofileifisrunning{#1}{%
306 \relax
307 }{%
308 \expandafter\xdef\csname c@pgfprofile@elapsed@at@start@#1\endcsname{\the\pgfutil@pdfelapsedtime}%
309 \expandafter\gdef\csname c@pgfprofile@subtractforself@#1\endcsname{0}%
310 \pgfprofile@advance{c@pgfprofile@numinvocations@#1}{1}%
311 \pgfprofilestackpush{#1}%
312 }%
313 \pgfprofile@advance{c@pgfprofile@semaphor@#1}{1}%
314 }%
315
316 % Stops / Interrupts timing of the profiler entry named `#1'.
317 \def\pgfprofileend#1{%
318 \pgfprofile@advance{c@pgfprofile@semaphor@#1}{-1}%
319 \pgfprofileifisrunning{#1}{%
320 \relax
321 }{%
322 \begingroup
323 \c@pgf@countb=\pgfutil@pdfelapsedtime\relax
324 \advance\c@pgf@countb by-\csname c@pgfprofile@elapsed@at@start@#1\endcsname\relax
325 %
326 \pgfprofilestackpop\pgfretval
327 \edef\pgfprofile@temp{#1}%
328 \ifx\pgfprofile@temp\pgfretval
329 \else
330 \pgf@typeout{pgflibraryprofiler WARNING: possible error in self time computation...}%
331 \fi
332 \pgfprofilestackifempty{%
333 \relax
334 }{%
335 \pgfprofilestacktop\pgfretval
336 \pgfprofile@advance{c@pgfprofile@subtractforself@\pgfretval}{\c@pgf@countb}%
337 }%
338 %
339 \pgfprofile@advance{c@pgfprofile@elapsedtotal@#1}{\c@pgf@countb}%
340 \advance\c@pgf@countb by-\csname c@pgfprofile@subtractforself@#1\endcsname\relax
341 \pgfprofile@advance{c@pgfprofile@elapsedself@#1}{\c@pgf@countb}%
342 \endgroup
343 }%
344 }%
345
346 % invokes '#2' if '#1' is currently running and '#3' if not.
347 \def\pgfprofileifisrunning#1#2#3{%
348 \ifnum\csname c@pgfprofile@semaphor@#1\endcsname=0 \def\pgfprofileifisrunning@next{#3}\else \def\pgfprofileifisrunning@next{#2}\fi
349 \pgfprofileifisrunning@next
350 }%
351
352 % Sets the profiler entry whose total time is used to compute all
353 % other relative times.
354 \def\pgfprofilesetrel#1{\edef\pgfprofile@rel{#1}}%
355
356 % Stops all running timings and postprocesses them.
357 \def\pgfprofilepostprocess{%
358 \begingroup
359 %
360 % prepare files.
361 \c@pgf@countb=\time
362 \divide\c@pgf@countb by60
363 \c@pgf@countd=\c@pgf@countb
364 \multiply\c@pgf@countd by60
365 \c@pgf@countc=\time
366 \advance\c@pgf@countc by-\c@pgf@countd
367 \immediate\openout\w@pgf@writea=\jobname.profiler.\the\year-\pgfprofiletotwodigitstr\month-\pgfprofiletotwodigitstr\day_\pgfprofiletotwodigitstr\c@pgf@countb h_\pgfprofiletotwodigitstr\c@pgf@countc m.dat
368 \immediate\write\w@pgf@writea{%
369 \pgfprofile@percent relative values are measured against the totaltime of `\pgfprofile@rel'.%
370 }%
371 \pgf@typeout{pgflibraryprofiler: relative values are measured against the totaltime of `\pgfprofile@rel'.}%
372 \immediate\write\w@pgf@writea{%
373 profilerentry\pgfprofile@TAB
374 totaltime[s]\pgfprofile@TAB
375 totaltime[percent]\pgfprofile@TAB
376 selftime[s]\pgfprofile@TAB
377 selftime[percent]\pgfprofile@TAB
378 numinvocations\pgfprofile@TAB}%
379 %
380 %
381 % compute main time and prepare computation of relative times:
382 \pgfprofileifisrunning{\pgfprofile@rel}{%
383 \pgfprofileend{\pgfprofile@rel}%
384 }{}%
385 \pgf@xa=\csname c@pgfprofile@elapsedtotal@\pgfprofile@rel\endcsname sp
386 \edef\pgfprofiletotaltime{\pgf@sys@tonumber\pgf@xa}%
387 \pgfmathreciprocal@{\pgfprofiletotaltime}%
388 \let\pgfprofiletotaltime@inv=\pgfmathresult
389 %
390 % postprocess each of them:
391 \pgfprofile@all@registered@list@foreach{%
392 \pgfprofileifisrunning{##1}{%
393 \pgfprofileend{##1}%
394 }{}%
395 \pgfprofilepostprocess@single{##1}%
396 }%
397 \immediate\write\w@pgf@writea{%
398 \pgfprofile@percent\space vim: ts=40 nowrap nostartofline
399 }%
400 \immediate\closeout\w@pgf@writea
401 \endgroup
402 }%
403
404 {%
405 \catcode`\[=1 %
406 \catcode`\]=2 %
407 \catcode`\{=12 %
408 \catcode`\}=12 %
409 \catcode`\^^I=12
410 \gdef\pgfprofile@lbrace[{]%
411 \gdef\pgfprofile@rbrace[}]%
412 \gdef\pgfprofile@TAB[^^I]%
413 ]
414 {
415 \catcode`\%=12 \gdef\pgfprofile@percent{%}}
416
417 \def\pgfprofilepostprocess@single#1{%
418 \begingroup
419 \pgf@xa=\csname c@pgfprofile@elapsedtotal@#1\endcsname sp
420 \pgf@xb=\csname c@pgfprofile@elapsedself@#1\endcsname sp
421 \pgf@ya=\pgfprofiletotaltime@inv\pgf@xa
422 \pgf@yb=\pgfprofiletotaltime@inv\pgf@xb
423 \multiply\pgf@ya by100
424 \multiply\pgf@yb by100
425 \edef\pgfprofilecur@total{\pgf@sys@tonumber\pgf@xa}%
426 \edef\pgfprofilecur@self{\pgf@sys@tonumber\pgf@xb}%
427 \edef\pgfprofilecur@total@rel{\pgf@sys@tonumber\pgf@ya}%
428 \edef\pgfprofilecur@self@rel{\pgf@sys@tonumber\pgf@yb}%
429 \pgf@typeout{
430 pgflibraryprofiler(#1)
431 \pgfprofile@lbrace
432 total time=\pgfprofilecur@total sec; (\pgfprofilecur@total@rel\pgfprofile@percent)
433 self time=\pgfprofilecur@self sec; (\pgfprofilecur@self@rel\pgfprofile@percent)
434 invocations=\csname c@pgfprofile@numinvocations@#1\endcsname;
435 \pgfprofile@rbrace
436 }%
437 \immediate\write\w@pgf@writea{%
438 #1\pgfprofile@TAB
439 \pgfprofilecur@total\pgfprofile@TAB
440 \pgfprofilecur@total@rel\pgfprofile@TAB
441 \pgfprofilecur@self\pgfprofile@TAB
442 \pgfprofilecur@self@rel\pgfprofile@TAB
443 \csname c@pgfprofile@numinvocations@#1\endcsname\pgfprofile@TAB
444 }%
445 \endgroup
446 }%
447 % Invokes '#2' for each element of the command separated list '#1'.
448 % the current list element is available as '#1' inside of '#2'.
449 \long\def\pgfprofileforeachentryinCSV#1#2{%
450 \long\def\pgfprofileinvokeforeach@@##1{#2}%
451 \pgfprofileforeachentryinCSVisterminated@loop#1,\pgfeov
452 }%
453 \long\def\pgfprofileforeachentryinCSVisterminated@loop{%
454 \pgfutil@ifnextchar\pgfeov{\pgfutil@gobble}{\pgfprofileforeachentryinCSV@next}%
455 }%
456 \long\def\pgfprofileforeachentryinCSV@next#1,{%
457 \pgfprofileinvokeforeach@@{#1}%
458 \pgfprofileforeachentryinCSVisterminated@loop%
459 }%
460
461 \xdef\pgfprofile@all@registered@list{}%
462 \xdef\pgfprofile@currently@running@list{}%
463
464 \def\pgfprofile@all@registered@list@add#1{%
465 \ifx\pgfprofile@all@registered@list\pgfutil@empty
466 \xdef\pgfprofile@all@registered@list{#1}%
467 \else
468 \xdef\pgfprofile@all@registered@list{\pgfprofile@all@registered@list,#1}%
469 \fi
470 }%
471
472 \def\pgfprofile@all@registered@list@foreach#1{%
473 \expandafter\pgfprofileforeachentryinCSV\expandafter{\pgfprofile@all@registered@list}{#1}%
474 }%
475
476 \def\pgfprofile@advance#1#2{%
477 \begingroup
478 \c@pgf@counta=\csname #1\endcsname\relax
479 \advance\c@pgf@counta by#2\relax
480 \expandafter\xdef\csname #1\endcsname{\the\c@pgf@counta}%
481 \endgroup
482 }%
483
484 \def\pgfprofile@cs@to@name@#1#2\relax{\def\pgfretval{#2}}
485
486 % defines '\pgfretval' to be the control sequences name of '#1' *without* the backslash.
487 \def\pgfprofile@cs@to@name#1{%
488 \expandafter\pgfprofile@cs@to@name@\string#1\relax
489 }%
490
491 \newcount\c@pgfprofile@stacktop
492
493 \c@pgfprofile@stacktop=-1
494 \def\pgfprofilestackpush#1{%
495 \global\advance\c@pgfprofile@stacktop by1
496 \expandafter\xdef\csname pgfprofile@stack@\the\c@pgfprofile@stacktop\endcsname{#1}%
497 }%
498 % pops the current stack top to macro #1
499 \def\pgfprofilestackpop#1{%
500 \pgfprofilestacktop#1%
501 \global\advance\c@pgfprofile@stacktop by-1
502 }%
503 % returns the stack's top to macro #1
504 \def\pgfprofilestacktop#1{%
505 \expandafter\let\expandafter#1\csname pgfprofile@stack@\the\c@pgfprofile@stacktop\endcsname
506 }%
507 \def\pgfprofilestackifempty#1#2{%
508 \ifnum\c@pgfprofile@stacktop<0 #1\else #2\fi
509 }%
510
511
512 \def\pgfprofiletotwodigitstr#1{\ifnum#1<10 0\the#1\else\the#1\fi}%
513
514 \pgfprofilenew{main job}%
515 \pgfprofilestart{main job}%
516 \expandafter\xdef\csname c@pgfprofile@elapsed@at@start@main job\endcsname{0}%
517 \pgfprofilesetrel{main job}%
518
519 \pgfutil@ifundefined{AtEndDocument}{%
520 % no latex. ok.
521 }{%
522 % do latex specific stuff:
523 \pgfprofilenew{preamble}
524 \pgfprofilestart{preamble}
525 \expandafter\xdef\csname c@pgfprofile@elapsed@at@start@preamble\endcsname{0}%
526 \AtBeginDocument{\pgfprofileend{preamble}}%
527 %
528 \AtEndDocument{\pgfprofilepostprocess}%
529 }%
530 \endinput