diff options
author | ZhiQiang Fan <zhiqiang.fan@huawei.com> | 2015-03-18 17:37:54 +0800 |
---|---|---|
committer | ZhiQiang Fan <aji.zqfan@gmail.com> | 2015-03-21 19:27:36 +0800 |
commit | 1c39f8fabf8ed44e0de563893d5813be1bf7b5e3 (patch) | |
tree | 8541d5c851e705749e0628ab6a5e39fb53facb28 /novaclient/utils.py | |
parent | 8679eedb8352630012202c12a9c9acf8757802a5 (diff) | |
download | python-novaclient-1c39f8fabf8ed44e0de563893d5813be1bf7b5e3.tar.gz |
Don't record time when self.timing is False
The expected behavior is when timing is True, then we record each
request's time, then we should call reset_timings() to release memory.
However, the shell, client.{HTTPClient,SessionClient} will record each
request's time no matter what timing is set, then after long running
time in service like ceilometer-agent-compute, the memory keeps increasing.
We'd better not record request's time when timing is set to False.
Users are not responiable to call reset_timings() when they don't want
timing functionality.
Change-Id: I3e7d2fadf9a21be018781d528a1b6562228da6dd
Closes-Bug: #1433491
Diffstat (limited to 'novaclient/utils.py')
-rw-r--r-- | novaclient/utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/novaclient/utils.py b/novaclient/utils.py index 289321c1..2cf4fc61 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -11,9 +11,11 @@ # License for the specific language governing permissions and limitations # under the License. +import contextlib import json import re import textwrap +import time import uuid from oslo.serialization import jsonutils @@ -339,3 +341,23 @@ def validate_flavor_metadata_keys(keys): 'numbers, spaces, underscores, periods, colons and ' 'hyphens.') raise exceptions.CommandError(msg % key) + + +@contextlib.contextmanager +def record_time(times, enabled, *args): + """Record the time of a specific action. + + :param times: A list of tuples holds time data. + :type times: list + :param enabled: Whether timing is enabled. + :type enabled: bool + :param *args: Other data to be stored besides time data, these args + will be joined to a string. + """ + if not enabled: + yield + else: + start = time.time() + yield + end = time.time() + times.append((' '.join(args), start, end)) |