Merge "Migrate timecost decorator to neutron-lib"

This commit is contained in:
Zuul 2020-06-02 22:26:30 +00:00 committed by Gerrit Code Review
commit b91f9fc0cf
2 changed files with 27 additions and 0 deletions

View File

@ -16,9 +16,16 @@ import decimal
import random
import weakref
from oslo_log import log as logging
from oslo_utils import timeutils
from oslo_utils import uuidutils
from neutron_lib._i18n import _
LOG = logging.getLogger(__name__)
def parse_mappings(mapping_list, unique_values=True, unique_keys=True):
"""Parse a list of mapping strings into a dictionary.
@ -198,3 +205,17 @@ def resolve_ref(ref):
if isinstance(ref, weakref.ref):
ref = ref()
return ref
def timecost(f):
call_id = uuidutils.generate_uuid()
message_base = ("Time-cost: call %(call_id)s function %(fname)s ") % {
"call_id": call_id, "fname": f.__name__}
end_message = (message_base + "took %(seconds).3fs seconds to run")
@timeutils.time_it(LOG, message=end_message, min_duration=None)
def wrapper(*args, **kwargs):
LOG.debug(message_base + "start")
ret = f(*args, **kwargs)
return ret
return wrapper

View File

@ -0,0 +1,6 @@
---
features:
- |
The ``timecost`` decorator is available in ``neutron_lib.utils.helpers``
now. This permits functions to be decorated with functionality that will
emit a debug log with the time it took to execute the function.