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 = { }
11end
12
13local snapshots = { }
14nodes.snapshots = snapshots
15
16local nodeusage = nodes.pool and nodes.pool.usage
17local clock = os.gettimeofday or os.clock
18local lasttime = clock()
19local samples = { }
20
21local 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
33 "str_ptr",
34}
35
36function 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
54end
55
56function snapshots.getsamples()
57 return samples
58end
59
60function snapshots.resetsamples()
61 samples = { }
62end
63
64function snapshots.getparameters()
65 return parameters
66end
67 |