m-timing.mkiv /size: 3831 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=m-timing,
3%D        version=2007.12.23,
4%D          title=\CONTEXT\ Modules,
5%D       subtitle=Timing,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\ifdefined\ShowNamedUsage \endinput \fi
15
16%D Written at the end of 2007, this module is dedicated to Taco. Reaching this
17%D point in \LUATEX\ was a non trivial effort. By visualizing a bit what happens
18%D when pages come out of \LUATEX, you may get an idea what is involved. It took
19%D much time an dedication to reach this point in the development. Add to that
20%D those daily Skype intense discussion, testing and debugging moments. Time flies
21%D but progress is impressive. The motto of this module could be: what you see
22%D is what you get. An there is much more to come \unknown.
23
24% \usemodule[timing]
25% \setupcolors[state=start]
26% \starttext
27%     \dorecurse{200}{\input tufte \par} \ShowUsage{}
28% \stoptext
29
30\definecolor[usage:line] [darkred]
31\definecolor[usage:time] [darkblue]
32\definecolor[usage:frame][darkgray]
33
34\ctxloadluafile{trac-tim}
35
36\startluacode
37local progress = moduledata.progress
38
39function progress.show(filename,parameters,nodes,other)
40    for n, name in pairs(parameters or progress.parameters()) do
41        context.ShowNamedUsage(filename or progress.defaultfilename,name,other or "")
42    end
43    for n, name in pairs(nodes or progress.nodes(filename)) do
44        context.ShowNamedUsage(filename or progress.defaultfilename,name,other or "")
45    end
46end
47\stopluacode
48
49% \everyfirstshipout
50
51\startnotmode[no-timing]
52    \appendtoks\ctxlua{moduledata.progress.store()}\to\everystarttext
53    \appendtoks\ctxlua{moduledata.progress.store()}\to\everyshipout
54    \ctxlua{luatex.registerstopactions(function() moduledata.progress.save() end)}
55\stopnotmode
56
57\unexpanded\def\ShowNamedUsage#1#2#3%
58  {\setbox\scratchbox\vbox\bgroup
59    \startMPcode
60      begingroup ; save p, q, b, h, w ;
61      path p, q, b ; numeric h, w ;
62      p := \cldcontext{moduledata.progress.path("#1","#2")} ;
63    % p := p shifted -llcorner p ;
64      if bbwidth(p) > 0 :
65        h := 100 ; w := 2 * h ;
66        w := \the\textwidth-3pt ; % correct for pen
67        p := p xstretched w ;
68        b := boundingbox (llcorner p -- llcorner p shifted (w,h)) ;
69        pickup pencircle scaled 3pt ; linecap := butt ;
70        draw b withcolor \MPcolor{usage:frame} ;
71        draw p withcolor \MPcolor{usage:line} ;
72        if ("#3" <> "") and ("#3" <> "#2") :
73          q := \cldcontext{moduledata.progress.path("#1","#3")} ;
74        % q := q shifted -llcorner q ;
75          if bbwidth(q) > 1 :
76            q := q xstretched w ;
77            pickup pencircle scaled 1.5pt ; linecap := butt ;
78            draw q withcolor \MPcolor{usage:time} ;
79          fi ;
80        fi ;
81      fi ;
82      endgroup ;
83   \stopMPcode
84   \egroup
85   \scratchdimen\wd\scratchbox
86   \ifdim\scratchdimen>\zeropoint
87     \startlinecorrection
88         \box\scratchbox \endgraf
89         \hbox to \scratchdimen{\tttf\strut\detokenize{#2}\hss
90          min:\cldcontext{moduledata.progress.bot("#1","\detokenize{#2}")}, %
91          max:\cldcontext{moduledata.progress.top("#1","\detokenize{#2}")}, %
92          pages:\cldcontext{moduledata.progress.pages("#1")}%
93         }%
94     \stoplinecorrection
95   \fi}
96
97\unexpanded\def\LoadUsage      #1{\ctxlua{moduledata.progress.convert("#1")}}
98\unexpanded\def\ShowUsage      #1{\ctxlua{moduledata.progress.show("#1",nil,nil,"elapsed_time")}}
99\unexpanded\def\ShowMemoryUsage#1{\ctxlua{moduledata.progress.show("#1",nil,{}, "elapsed_time")}}
100\unexpanded\def\ShowNodeUsage  #1{\ctxlua{moduledata.progress.show("#1",{},nil, "elapsed_time")}}
101
102\endinput
103