node-snp.lmt /size: 2403 b    last modification: 2021-10-28 13:51
1if 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
9if not nodes then
10    nodes = { } -- also loaded in mtx-timing
11end
12
13local snapshots = { }
14nodes.snapshots = snapshots
15
16local status    = status
17
18local nodeusage = nodes.pool and nodes.pool.usage
19local nodestock = nodes.pool and nodes.pool.stock
20local clock     = os.gettimeofday or os.clock -- should go in environment
21local lasttime  = clock()
22local samples   = { }
23
24function snapshots.takesample(comment)
25    if nodeusage then
26        local c = clock()
27        samples[#samples+1] = {
28            nodes            = nodeusage(),
29            stock            = nodestock(),
30            texcallbacks     = status.getcallbackstate(),
31            mpcallbacks      = mplib.getcallbackstate(),
32            backendcallbacks = backends.getcallbackstate(),
33            luavariables     = status.getluastate(),
34            texvariables     = status.gettexstate(),
35            comment          = comment,
36            variables        = {
37                lasttime = c,
38                elapsed  = c - lasttime,
39            },
40            memories         = {
41                pool      = status.getpoolstate(),
42                hash      = status.gethashstate(),
43                lookup    = status.getlookupstate(),
44                node      = status.getnodestate(),
45                token     = status.gettokenstate(),
46                buffer    = status.getbufferstate(),
47                input     = status.getinputstate(),
48                file      = status.getfilestate(),
49                nest      = status.getneststate(),
50                parameter = status.getparameterstate(),
51                save      = status.getsavestate(),
52                expand    = status.getexpandstate(),
53                read      = status.getreadstate(),
54                font      = status.getfontstate(),
55                language  = status.getlanguagestate(),
56                mark      = status.getmarkstate(),
57                sparse    = status.getsparsestate(),
58            },
59        }
60    end
61end
62
63function snapshots.getsamples()
64    return samples -- one return value !
65end
66
67function snapshots.resetsamples()
68    samples = { }
69end
70