From c0585eba4c5f7531fbbfc570adf0adbe5812bc47 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 16 Sep 2014 12:17:53 +1000 Subject: Add support for OSprofiler To be able to create profiling traces for Heat, the client should be able to send special HTTP header that contains trace info. Change-Id: I2ff833fac2dfe3bb0fcbd6a31c210db2935b72f1 Closes-bug: #1363782 --- heatclient/shell.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'heatclient/shell.py') diff --git a/heatclient/shell.py b/heatclient/shell.py index 264a824..f26863c 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -34,9 +34,11 @@ from heatclient import client as heat_client from heatclient.common import utils from heatclient import exc from heatclient.openstack.common.gettextutils import _ +from heatclient.openstack.common import importutils from heatclient.openstack.common import strutils logger = logging.getLogger(__name__) +osprofiler_profiler = importutils.try_import("osprofiler.profiler") class HeatShell(object): @@ -283,6 +285,18 @@ class HeatShell(object): self._append_global_identity_args(parser) + if osprofiler_profiler: + parser.add_argument('--profile', + metavar='HMAC_KEY', + help='HMAC key to use for encrypting context ' + 'data for performance profiling of operation. ' + 'This key should be the value of HMAC key ' + 'configured in osprofiler middleware in heat, ' + 'it is specified in the paste configuration ' + '(/etc/heat/api-paste.ini). ' + 'Without the key, profiling will not be ' + 'triggered even if osprofiler is enabled ' + 'on server side.') return parser def get_subcommand_parser(self, version): @@ -585,8 +599,18 @@ class HeatShell(object): client = heat_client.Client(api_version, endpoint, **kwargs) + profile = osprofiler_profiler and options.profile + if profile: + osprofiler_profiler.init(options.profile) + args.func(client, args) + if profile: + trace_id = osprofiler_profiler.get().get_base_id() + print("Trace ID: %s" % trace_id) + print("To display trace use next command:\n" + "osprofiler trace show --html %s " % trace_id) + def do_bash_completion(self, args): """Prints all of the commands and options to stdout. -- cgit v1.2.1