1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
if not modules then modules = { } end modules ['mtx-timing'] = {
version = 1.002,
comment = "companion to mtxrun.lua",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local format, gsub, concat = string.format, string.gsub, table.concat
dofile(resolvers.find_file("trac-tim.lua","tex"))
dofile(resolvers.find_file("trac-lmx.lua","tex"))
local meta = [[
beginfig(%s) ;
begingroup ;
save p, q, b, h, w ;
path p, q, b ; numeric h, w ;
linecap := butt ;
h := 100 ;
w := 800pt ;
p := %s ;
q := %s ;
p := p shifted -llcorner p ;
q := q shifted -llcorner q ;
q := q xstretched w ;
p := p xstretched w ;
b := boundingbox (llcorner p -- llcorner p shifted (w,h)) ;
draw b withcolor white withpen pencircle scaled 4pt ;
draw p withcolor red withpen pencircle scaled 4pt ;
draw q withcolor blue withpen pencircle scaled 2pt ;
endgroup ;
endfig ;
]]
local html_graphic = [[
<h1><a name='graphic-%s'>%s (red) %s (blue)</a></h1>
<table>
<tr>
<td>%s</td>
<td valign='top'>
min: %s<br/>
max: %s<br/>
pages: %s<br/>
average: %s<br/>
</td>
</tr>
</table>
<br/>
]]
local html_menu = [[
<a href='#graphic-%s'>%s</a>
]]
local directrun = true
function goodies.progress.make_svg(filename,other)
local metadata, menudata, c = { }, { }, 0
metadata[#metadata+1] = 'outputformat := "svg" ;'
for _, kind in pairs { "parameters", "nodes" } do
local mdk = { }
menudata[kind] = mdk
for n, name in pairs(goodies.progress[kind](filename)) do
local first = goodies.progress.path(filename,name)
local second = goodies.progress.path(filename,other)
c = c + 1
metadata[#metadata+1] = format(meta,c,first,second)
mdk[#mdk+1] = { name, c }
end
end
metadata[#metadata+1] = "end ."
metadata = concat(metadata,"\n\n")
if directrun then
dofile(resolvers.find_file("mlib-run.lua","tex"))
commands = commands or { }
commands.writestatus = logs.report
local result = metapost.directrun("metafun","timing data","svg",true,metadata)
return menudata, result
else
local mpname = file.replacesuffix(filename,"mp")
io.savedata(mpname,metadata)
os.execute(format("mpost --progname=context --mem=metafun.mem %s",mpname))
os.remove(mpname)
os.remove(file.removesuffix(filename).."-mpgraph.mpo") -- brr
os.remove(file.removesuffix(filename)..".log") -- brr
return menudata
end
end
function goodies.progress.makehtml(filename,other,menudata,metadata)
local graphics = { }
local result = { graphics = graphics }
for _, kind in pairs { "parameters", "nodes" } do
local md = menudata[kind]
local menu = { }
result[kind] = menu
for k, v in ipairs(md) do
local name, number = v[1], v[2]
local min = goodies.progress.bot(filename,name)
local max = goodies.progress.top(filename,name)
local pages = goodies.progress.pages(filename)
local average = math.round(max/pages)
if directrun then
local data = metadata[number]
menu[#menu+1] = format(html_menu,name,name)
graphics[#graphics+1] = format(html_graphic,name,name,other,data,min,max,pages,average)
else
local mpname = file.replacesuffix(filename,number)
local data = io.loaddata(mpname) or ""
-- data = gsub(data,"<!%-%-(.-)%-%->[\n\r]*","")
data = gsub(data,"<%?xml.->","")
menu[#menu+1] = format(html_menu,name,name)
graphics[#graphics+1] = format(html_graphic,name,name,other,data,min,max,pages,average)
os.remove(mpname)
end
end
end
return result
end
function goodies.progress.valid_file(name)
return name and name ~= "" and lfs.isfile(name .. "-luatex-progress.lut")
end
function goodies.progress.make_lmx_page(name,launch,remove)
local filename = name .. "-luatex-progress"
local other = "elapsed_time"
local template = 'context-timing.lmx'
lmx.variables['color-background-green'] = '#4F6F6F'
lmx.variables['color-background-blue'] = '#6F6F8F'
lmx.variables['color-background-yellow'] = '#8F8F6F'
lmx.variables['color-background-purple'] = '#8F6F8F'
lmx.variables['color-background-body'] = '#808080'
lmx.variables['color-background-main'] = '#3F3F3F'
lmx.variables['color-background-one'] = lmx.variables['color-background-green']
lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
lmx.variables['title-default'] = 'ConTeXt Timing Information'
lmx.variables['title'] = lmx.variables['title-default']
lmx.htmfile = function(name) return name .. "-timing.xhtml" end
lmx.lmxfile = function(name) return resolvers.find_file(name,'tex') end
lmx.set('title', format('ConTeXt Timing Information: %s',file.basename(name)))
lmx.set('color-background-one', lmx.get('color-background-green'))
lmx.set('color-background-two', lmx.get('color-background-blue'))
goodies.progress.convert(filename)
local menudata, metadata = goodies.progress.make_svg(filename,other)
local htmldata = goodies.progress.makehtml(filename,other,menudata,metadata)
lmx.set('parametersmenu', concat(htmldata.parameters, " "))
lmx.set('nodesmenu', concat(htmldata.nodes, " "))
lmx.set('graphics', concat(htmldata.graphics, "\n\n"))
if launch then
local htmfile = lmx.show(template)
if remove then
os.sleep(1) -- give time to launch
os.remove(htmfile)
end
else
lmx.make(template)
end
lmx.restore()
end
scripts = scripts or { }
scripts.timings = scripts.timings or { }
function scripts.timings.xhtml(filename)
if filename == "" then
logs.simple("provide filename")
elseif not goodies.progress.valid_file(filename) then
logs.simple("first run context again with the --timing option")
else
local basename = file.removesuffix(filename)
local launch = environment.argument("launch")
local remove = environment.argument("remove")
goodies.progress.make_lmx_page(basename,launch,remove)
end
end
logs.extendbanner("ConTeXt Timing Tools 0.1",true)
messages.help = [[
--xhtml make xhtml file
--launch launch after conversion
--remove remove after launching
]]
if environment.argument("xhtml") then
scripts.timings.xhtml(environment.files[1] or "")
else
logs.help(messages.help)
end
|