summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2014-05-08 22:42:21 -0500
committerDean Troyer <dtroyer@gmail.com>2014-07-08 02:04:00 -0500
commit4844a257790deef231176557776754dde929f840 (patch)
tree8055c40ae007029eb73900088c007b5c0553984c /openstackclient/common
parentea938e8ddfa0f5f8832e09d61537f1e81e3121e9 (diff)
downloadpython-openstackclient-4844a257790deef231176557776754dde929f840.tar.gz
Add basic timing support
Add support for --timing options. Use cliff via a pseudo-command 'Timing' to support multiple outputformats. If an output format other than the default 'table' is selected use CSV since the timing data is in list form. Will pick up timing data for any client object that has a method similar to novaclient's get_timings(). TODO: * Stop instantiating all of the clientmanager client objects just to check for timing data. Descriptor magic required? Change-Id: I7f1076b7a250fba6a8b24b2ae9353a7f51b792b2
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/clientmanager.py5
-rw-r--r--openstackclient/common/timing.py44
2 files changed, 47 insertions, 2 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py
index b310f3ac..a2f85aff 100644
--- a/openstackclient/common/clientmanager.py
+++ b/openstackclient/common/clientmanager.py
@@ -49,7 +49,7 @@ class ClientManager(object):
user_domain_id=None, user_domain_name=None,
project_domain_id=None, project_domain_name=None,
region_name=None, api_version=None, verify=True,
- trust_id=None):
+ trust_id=None, timing=None):
self._token = token
self._url = url
self._auth_url = auth_url
@@ -67,6 +67,7 @@ class ClientManager(object):
self._api_version = api_version
self._trust_id = trust_id
self._service_catalog = None
+ self.timing = timing
# verify is the Requests-compatible form
self._verify = verify
@@ -116,7 +117,7 @@ def get_extension_modules(group):
setattr(
ClientManager,
- ep.name,
+ module.API_NAME,
ClientCache(
getattr(sys.modules[ep.module_name], 'make_client', None)
),
diff --git a/openstackclient/common/timing.py b/openstackclient/common/timing.py
new file mode 100644
index 00000000..1c94682c
--- /dev/null
+++ b/openstackclient/common/timing.py
@@ -0,0 +1,44 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+
+"""Timing Implementation"""
+
+import logging
+
+from cliff import lister
+
+
+class Timing(lister.Lister):
+ """Show timing data"""
+
+ log = logging.getLogger(__name__ + '.Timing')
+
+ def take_action(self, parsed_args):
+ self.log.debug('take_action(%s)' % parsed_args)
+
+ column_headers = (
+ 'URL',
+ 'Seconds',
+ )
+
+ results = []
+ total = 0.0
+ for url, start, end in self.app.timing_data:
+ seconds = end - start
+ total += seconds
+ results.append((url, seconds))
+ results.append(('Total', total))
+ return (
+ column_headers,
+ results,
+ )