disable stack inspection when setting option values

Inspecting the stack every time we create an Opt or call
set_defaults() is too expensive. This patch disables it but leaves the
code in place to make it easier for someone else to come along and
work on the performance issue without having to revert the patch
completely.

Change-Id: I25bd71ffa49f4232972370a35bf9040e7c45bf70
Addresses-Bug: #1759689
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-03-28 17:18:32 -04:00
parent e713fa9f59
commit b6cfa29055
2 changed files with 26 additions and 19 deletions

View File

@ -489,7 +489,7 @@ import copy
import errno
import functools
import glob
import inspect
# import inspect
import itertools
import logging
import os
@ -811,20 +811,23 @@ def _get_caller_detail(n=2):
:type n: int
:returns: str
"""
s = inspect.stack()[:n + 1]
try:
frame = s[n]
try:
return frame[1]
# WARNING(dhellmann): Using frame.lineno to include the
# line number in the return value causes some sort of
# memory or stack corruption that manifests in values not
# being cleaned up in the cfgfilter tests.
# return '%s:%s' % (frame[1], frame[2])
finally:
del frame
finally:
del s
return None
# FIXME(dhellmann): We need to look at the performance issues with
# doing this for every Opt instance.
# s = inspect.stack()[:n + 1]
# try:
# frame = s[n]
# try:
# return frame[1]
# # WARNING(dhellmann): Using frame.lineno to include the
# # line number in the return value causes some sort of
# # memory or stack corruption that manifests in values not
# # being cleaned up in the cfgfilter tests.
# # return '%s:%s' % (frame[1], frame[2])
# finally:
# del frame
# finally:
# del s
def set_defaults(opts, **kwargs):

View File

@ -70,7 +70,8 @@ class GetLocationTestCase(base.BaseTestCase):
cfg.Locations.opt_default,
loc.location,
)
self.assertIn('test_get_location.py', loc.detail)
self.assertIsNone(loc.detail)
# self.assertIn('test_get_location.py', loc.detail)
def test_set_default_on_config_opt(self):
self.conf.set_default('normal_opt', self.id())
@ -80,7 +81,8 @@ class GetLocationTestCase(base.BaseTestCase):
cfg.Locations.set_default,
loc.location,
)
self.assertIn('test_get_location.py', loc.detail)
self.assertIsNone(loc.detail)
# self.assertIn('test_get_location.py', loc.detail)
def test_set_defaults_func(self):
cfg.set_defaults([self.normal_opt], normal_opt=self.id())
@ -90,7 +92,8 @@ class GetLocationTestCase(base.BaseTestCase):
cfg.Locations.set_default,
loc.location,
)
self.assertIn('test_get_location.py', loc.detail)
self.assertIsNone(loc.detail)
# self.assertIn('test_get_location.py', loc.detail)
def test_set_override(self):
self.conf.set_override('normal_opt', self.id())
@ -100,7 +103,8 @@ class GetLocationTestCase(base.BaseTestCase):
cfg.Locations.set_override,
loc.location,
)
self.assertIn('test_get_location.py', loc.detail)
self.assertIsNone(loc.detail)
# self.assertIn('test_get_location.py', loc.detail)
def test_user_cli(self):
filename = self._write_opt_to_tmp_file(