diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-03-09 15:00:41 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-03-09 15:00:41 -0700 |
commit | 7a7f497b483cd65e340064f23ed1c73425ecba0a (patch) | |
tree | d5c99ea22a1e10300d06165f8ac96df6b0dc59e1 /test/functional/legacy/memory_usage_spec.lua | |
parent | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (diff) | |
parent | ade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff) | |
download | rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.gz rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.tar.bz2 rneovim-7a7f497b483cd65e340064f23ed1c73425ecba0a.zip |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpost
Diffstat (limited to 'test/functional/legacy/memory_usage_spec.lua')
-rw-r--r-- | test/functional/legacy/memory_usage_spec.lua | 68 |
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) |