forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
memprof: introduce the
--human-readable
option
Prior to this patch, memprof could report only the raw amount of bytes, which is hard to read. This patch adds the `--human-readable` CLI option to the memprof parser, so the memory is reported in KiB, MiB, or GiB, depending on what's the biggest reasonable unit. This patch also refactors the options mechanism for parser, so all of the options are passed into parser's modules as a single config table instead of being handled individually. Part of tarantool/tarantool#5994
- Loading branch information
1 parent
26f8841
commit aac00cb
Showing
3 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
test/tarantool-tests/gh-5994-memprof-human-readable.test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
local tap = require('tap') | ||
local test = tap.test('gh-5994-memprof-human-readable'):skipcond({ | ||
['Profile tools are implemented for x86_64 only'] = jit.arch ~= 'x86' and | ||
jit.arch ~= 'x64', | ||
['Profile tools are implemented for Linux only'] = jit.os ~= 'Linux', | ||
-- XXX: Tarantool integration is required to run this test properly. | ||
-- luacheck: no global | ||
['No profile tools CLI option integration'] = _TARANTOOL, | ||
}) | ||
|
||
local utils = require('utils') | ||
local TMP_BINFILE_MEMPROF = utils.tools.profilename('memprofdata.tmp.bin') | ||
local PARSE_CMD = utils.exec.luacmd(arg) .. ' -tm ' | ||
|
||
local function generate_output(bytes) | ||
local res, err = misc.memprof.start(TMP_BINFILE_MEMPROF) | ||
-- Should start successfully. | ||
assert(res, err) | ||
|
||
-- luacheck: no unused | ||
local _ = string.rep('_', bytes) | ||
|
||
res, err = misc.memprof.stop() | ||
-- Should stop successfully. | ||
assert(res, err) | ||
end | ||
|
||
local TEST_SET = { | ||
{ | ||
bytes = 2049, | ||
match = '%dB', | ||
hr = false, | ||
name = 'non-human-readable mode is correct' | ||
}, | ||
{ | ||
bytes = 100, | ||
match = '%dB', | ||
hr = true, | ||
name = 'human-readable mode: bytes' | ||
}, | ||
{ | ||
bytes = 2560, | ||
match = '%d+%.%d%dKiB', | ||
hr = true, | ||
name = 'human-readable mode: float' | ||
}, | ||
{ | ||
bytes = 2048, | ||
match = '%dKiB', | ||
hr = true, | ||
name = 'human-readable mode: KiB' | ||
}, | ||
{ | ||
bytes = 1024 * 1024, | ||
match = '%dMiB', | ||
hr = true, | ||
name = 'human-readable mode: MiB' | ||
}, | ||
-- XXX: The test case for GiB is not implemented because it is | ||
-- OOM-prone for non-GC64 builds. | ||
} | ||
|
||
test:plan(#TEST_SET) | ||
|
||
for _, params in ipairs(TEST_SET) do | ||
generate_output(params.bytes) | ||
local cmd = PARSE_CMD .. (params.hr and ' --human-readable ' or '') | ||
local output = io.popen(cmd .. TMP_BINFILE_MEMPROF):read('*all') | ||
test:like(output, params.match, params.name) | ||
end | ||
|
||
os.remove(TMP_BINFILE_MEMPROF) | ||
test:done(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters