aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/memory_usage_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
commitc324271b99eee4c621463f368914d57cd729bd9c (patch)
tree5d979d333a2d5f9c080991d5482fd5916f8579c6 /test/functional/legacy/memory_usage_spec.lua
parent931bffbda3668ddc609fc1da8f9eb576b170aa52 (diff)
parentade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff)
downloadrneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.gz
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.bz2
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.zip
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'test/functional/legacy/memory_usage_spec.lua')
-rw-r--r--test/functional/legacy/memory_usage_spec.lua68
1 files changed, 38 insertions, 30 deletions
diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua
index 5f722e5190..a05e9fdf57 100644
--- a/test/functional/legacy/memory_usage_spec.lua
+++ b/test/functional/legacy/memory_usage_spec.lua
@@ -19,7 +19,10 @@ if is_asan() then
return
elseif is_os('win') then
if is_ci('github') then
- pending('Windows runners in Github Actions do not have a stable environment to estimate memory usage', function() end)
+ pending(
+ 'Windows runners in Github Actions do not have a stable environment to estimate memory usage',
+ function() end
+ )
return
elseif eval("executable('wmic')") == 0 then
pending('missing "wmic" command', function() end)
@@ -34,9 +37,9 @@ local monitor_memory_usage = {
memory_usage = function(self)
local handle
if is_os('win') then
- handle = io.popen('wmic process where processid=' ..self.pid..' get WorkingSetSize')
+ handle = io.popen('wmic process where processid=' .. self.pid .. ' get WorkingSetSize')
else
- handle = io.popen('ps -o rss= -p '..self.pid)
+ handle = io.popen('ps -o rss= -p ' .. self.pid)
end
return tonumber(handle:read('*a'):match('%d+'))
end,
@@ -49,7 +52,7 @@ local monitor_memory_usage = {
table.insert(self.hist, val)
ok(#self.hist > 20)
local result = {}
- for key,value in ipairs(self.hist) do
+ for key, value in ipairs(self.hist) do
if value ~= self.hist[key + 1] then
table.insert(result, value)
end
@@ -60,7 +63,7 @@ local monitor_memory_usage = {
end)
end,
dump = function(self)
- return 'max: '..self.max ..', last: '..self.last
+ return 'max: ' .. self.max .. ', last: ' .. self.last
end,
monitor_memory_usage = function(self, pid)
local obj = {
@@ -72,12 +75,13 @@ local monitor_memory_usage = {
setmetatable(obj, { __index = self })
obj:op()
return obj
- end
+ end,
}
-setmetatable(monitor_memory_usage,
-{__call = function(self, pid)
- return monitor_memory_usage.monitor_memory_usage(self, pid)
-end})
+setmetatable(monitor_memory_usage, {
+ __call = function(self, pid)
+ return monitor_memory_usage.monitor_memory_usage(self, pid)
+ end,
+})
describe('memory usage', function()
local tmpfile = 'X_memory_usage'
@@ -101,46 +105,51 @@ describe('memory usage', function()
--[[
Case: if a local variable captures a:000, funccall object will be free
just after it finishes.
- ]]--
+ ]]
+ --
it('function capture vargs', function()
local pid = eval('getpid()')
local before = monitor_memory_usage(pid)
- write_file(tmpfile, [[
+ write_file(
+ tmpfile,
+ [[
func s:f(...)
let x = a:000
endfunc
for _ in range(10000)
call s:f(0)
endfor
- ]])
+ ]]
+ )
-- TODO: check_result fails if command() is used here. Why? #16064
- feed_command('source '..tmpfile)
+ feed_command('source ' .. tmpfile)
poke_eventloop()
local after = monitor_memory_usage(pid)
-- Estimate the limit of max usage as 2x initial usage.
-- The lower limit can fluctuate a bit, use 97%.
- check_result({before=before, after=after},
- pcall(ok, before.last * 97 / 100 < after.max))
- check_result({before=before, after=after},
- pcall(ok, before.last * 2 > after.max))
+ check_result({ before = before, after = after }, pcall(ok, before.last * 97 / 100 < after.max))
+ check_result({ before = before, after = after }, pcall(ok, before.last * 2 > after.max))
-- In this case, garbage collecting is not needed.
-- The value might fluctuate a bit, allow for 3% tolerance below and 5% above.
-- Based on various test runs.
local lower = after.last * 97 / 100
local upper = after.last * 105 / 100
- check_result({before=before, after=after}, pcall(ok, lower < after.max))
- check_result({before=before, after=after}, pcall(ok, after.max < upper))
+ check_result({ before = before, after = after }, pcall(ok, lower < after.max))
+ check_result({ before = before, after = after }, pcall(ok, after.max < upper))
end)
--[[
Case: if a local variable captures l: dict, funccall object will not be
free until garbage collector runs, but after that memory usage doesn't
increase so much even when rerun Xtest.vim since system memory caches.
- ]]--
+ ]]
+ --
it('function capture lvars', function()
local pid = eval('getpid()')
local before = monitor_memory_usage(pid)
- write_file(tmpfile, [[
+ write_file(
+ tmpfile,
+ [[
if !exists('s:defined_func')
func s:f()
let x = l:
@@ -150,13 +159,14 @@ describe('memory usage', function()
for _ in range(10000)
call s:f()
endfor
- ]])
- feed_command('source '..tmpfile)
+ ]]
+ )
+ feed_command('source ' .. tmpfile)
poke_eventloop()
local after = monitor_memory_usage(pid)
for _ = 1, 3 do
-- TODO: check_result fails if command() is used here. Why? #16064
- feed_command('source '..tmpfile)
+ feed_command('source ' .. tmpfile)
poke_eventloop()
end
local last = monitor_memory_usage(pid)
@@ -167,10 +177,8 @@ describe('memory usage', function()
local upper_multiplier = is_os('freebsd') and 19 or 12
local lower = before.last * 8 / 10
local upper = load_adjust((after.max + (after.last - before.last)) * upper_multiplier / 10)
- check_result({before=before, after=after, last=last},
- pcall(ok, lower < last.last))
- check_result({before=before, after=after, last=last},
- pcall(ok, last.last < upper))
+ check_result({ before = before, after = after, last = last }, pcall(ok, lower < last.last))
+ check_result({ before = before, after = after, last = last }, pcall(ok, last.last < upper))
end)
it('releases memory when closing windows when folds exist', function()
@@ -205,6 +213,6 @@ describe('memory usage', function()
-- but is small enough that if memory were not released (prior to PR #14884), the test
-- would fail.
local upper = before.last * 1.10
- check_result({before=before, after=after}, pcall(ok, after.last <= upper))
+ check_result({ before = before, after = after }, pcall(ok, after.last <= upper))
end)
end)