node-snp.lua /size: 1552 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
node-snp
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to node-ini.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
if
not
nodes
then
10
nodes
=
{
}
-- also loaded in mtx-timing
11
end
12 13
local
snapshots
=
{
}
14
nodes
.
snapshots
=
snapshots
15 16
local
nodeusage
=
nodes
.
pool
and
nodes
.
pool
.
usage
17
local
clock
=
os
.
gettimeofday
or
os
.
clock
-- should go in environment
18
local
lasttime
=
clock
(
)
19
local
samples
=
{
}
20 21
local
parameters
=
{
22
"
cs_count
"
,
23
"
dyn_used
"
,
24
"
elapsed_time
"
,
25
"
luabytecode_bytes
"
,
26
"
luastate_bytes
"
,
27
"
max_buf_stack
"
,
28
"
obj_ptr
"
,
29
"
pdf_mem_ptr
"
,
30
"
pdf_mem_size
"
,
31
"
pdf_os_cntr
"
,
32
-- "pool_ptr", -- obsolete
33
"
str_ptr
"
,
34
}
35 36
function
snapshots
.
takesample
(
comment
)
37
if
nodeusage
then
38
local
c
=
clock
(
)
39
local
t
=
{
40
elapsed_time
=
c
-
lasttime
,
41
node_memory
=
nodeusage
(
)
,
42
comment
=
comment
,
43
}
44
for
i
=
1
,
#
parameters
do
45
local
parameter
=
parameters
[
i
]
46
local
ps
=
status
[
parameter
]
47
if
ps
then
48
t
[
parameter
]
=
ps
49
end
50
end
51
samples
[
#
samples
+
1
]
=
t
52
lasttime
=
c
53
end
54
end
55 56
function
snapshots
.
getsamples
(
)
57
return
samples
-- one return value !
58
end
59 60
function
snapshots
.
resetsamples
(
)
61
samples
=
{
}
62
end
63 64
function
snapshots
.
getparameters
(
)
65
return
parameters
66
end
67