Skip to content

Commit ca88d61

Browse files
committed
Fix line numbers in Lua code example - 3
1 parent 64d2c9a commit ca88d61

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

doc/tooling/luajit_memprof.rst

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ Below is a chunk of Lua code named ``test.lua`` to illustrate this.
4545
.. code-block:: lua
4646
:linenos:
4747
48-
-- Prevent allocations on traces.
49-
jit.off()
50-
local str, err = misc.memprof.start("memprof_new.bin")
51-
-- Lua doesn't create a new frame to call string.rep, and all allocations
52-
-- are attributed not to the append() function but to the parent scope.
53-
local function append(str, rep)
54-
return string.rep(str, rep)
55-
end
48+
-- Prevent allocations on traces.
49+
jit.off()
50+
local str, err = misc.memprof.start("memprof_new.bin")
51+
-- Lua doesn't create a new frame to call string.rep, and all allocations
52+
-- are attributed not to the append() function but to the parent scope.
53+
local function append(str, rep)
54+
return string.rep(str, rep)
55+
end
5656
57-
local t = {}
58-
for i = 1, 1e4 do
59-
-- table.insert is the built-in function and all corresponding
60-
-- allocations are reported in the scope of the main chunk.
61-
table.insert(t,
62-
append('q', i)
63-
)
64-
end
65-
local str, err = misc.memprof.stop()
57+
local t = {}
58+
for i = 1, 1e4 do
59+
-- table.insert is the built-in function and all corresponding
60+
-- allocations are reported in the scope of the main chunk.
61+
table.insert(t,
62+
append('q', i)
63+
)
64+
end
65+
local str, err = misc.memprof.stop()
6666
6767
The Lua code for starting the profiler -- as in line 3 in the ``test.lua`` example above -- is:
6868

@@ -322,31 +322,31 @@ console for a running instance.
322322
.. code-block:: lua
323323
:linenos:
324324
325-
local fiber = require "fiber"
326-
local log = require "log"
325+
local fiber = require "fiber"
326+
local log = require "log"
327327
328-
fiber.create(function()
329-
fiber.name("memprof")
328+
fiber.create(function()
329+
fiber.name("memprof")
330330
331-
collectgarbage() -- Collect all objects already dead
332-
log.warn("start of profile")
331+
collectgarbage() -- Collect all objects already dead
332+
log.warn("start of profile")
333333
334-
local st, err = misc.memprof.start(FILENAME)
335-
if not st then
336-
log.error("failed to start profiler: %s", err)
337-
end
334+
local st, err = misc.memprof.start(FILENAME)
335+
if not st then
336+
log.error("failed to start profiler: %s", err)
337+
end
338338
339-
fiber.sleep(TIME)
339+
fiber.sleep(TIME)
340340
341-
collectgarbage()
342-
st, err = misc.memprof.stop()
341+
collectgarbage()
342+
st, err = misc.memprof.stop()
343343
344-
if not st then
345-
log.error("profiler on stop error: %s", err)
346-
end
344+
if not st then
345+
log.error("profiler on stop error: %s", err)
346+
end
347347
348-
log.warn("end of profile")
349-
end)
348+
log.warn("end of profile")
349+
end)
350350
351351
where:
352352

@@ -369,37 +369,37 @@ investigated with the help of the memory profiler reports.
369369
.. code-block:: lua
370370
:linenos:
371371
372-
-- Prevent allocations on new traces.
373-
jit.off()
372+
-- Prevent allocations on new traces.
373+
jit.off()
374374
375-
local function concat(a)
376-
local nstr = a.."a"
377-
return nstr
378-
end
375+
local function concat(a)
376+
local nstr = a.."a"
377+
return nstr
378+
end
379379
380-
local function format(a)
381-
local nstr = string.format("%sa", a)
382-
return nstr
383-
end
380+
local function format(a)
381+
local nstr = string.format("%sa", a)
382+
return nstr
383+
end
384384
385-
collectgarbage()
385+
collectgarbage()
386386
387-
local binfile = "/tmp/memprof_"..(arg[0]):match("([^/]*).lua")..".bin"
387+
local binfile = "/tmp/memprof_"..(arg[0]):match("([^/]*).lua")..".bin"
388388
389-
local st, err = misc.memprof.start(binfile)
390-
assert(st, err)
389+
local st, err = misc.memprof.start(binfile)
390+
assert(st, err)
391391
392-
-- Payload.
393-
for i = 1, 10000 do
394-
local f = format(i)
395-
local c = concat(i)
396-
end
397-
collectgarbage()
392+
-- Payload.
393+
for i = 1, 10000 do
394+
local f = format(i)
395+
local c = concat(i)
396+
end
397+
collectgarbage()
398398
399-
local st, err = misc.memprof.stop()
400-
assert(st, err)
399+
local st, err = misc.memprof.stop()
400+
assert(st, err)
401401
402-
os.exit()
402+
os.exit()
403403
404404
When you run this code :ref:`in Tarantool <profiler_usage_generate>` and
405405
then :ref:`parse <profiler_usage_parse_command>` the binary memory profile

0 commit comments

Comments
 (0)