3b1ed4ec3e
1.As mentioned in [1], we should avoid using six.iteritems to achieve iterators. We can use dict.items instead, as it will return iterators in PY3 as well. And dict.items/keys will more readable. 2.In py2, the performance about list should be negligible, see the link [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: Iff88f55dc51981ce502d7d3e67c467242980f20c
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
# Copyright 2016 - Brocade Communications Systems, Inc.
|
|
#
|
|
# 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.
|
|
|
|
import copy
|
|
import datetime
|
|
import json
|
|
|
|
from oslo_config import cfg
|
|
from oslo_log import log as logging
|
|
import osprofiler.profiler
|
|
import osprofiler.web
|
|
|
|
|
|
PROFILER_LOG = logging.getLogger(cfg.CONF.profiler.profiler_log_name)
|
|
|
|
|
|
def log_to_file(info, context=None):
|
|
attrs = [
|
|
str(info['timestamp']),
|
|
info['base_id'],
|
|
info['parent_id'],
|
|
info['trace_id'],
|
|
info['name']
|
|
]
|
|
|
|
if 'info' in info and 'db' in info['info']:
|
|
db_info = copy.deepcopy(info['info']['db'])
|
|
|
|
db_info['params'] = {
|
|
k: str(v) if isinstance(v, datetime.datetime) else v
|
|
for k, v in db_info.get('params', {}).items()
|
|
}
|
|
|
|
attrs.append(json.dumps(db_info))
|
|
|
|
PROFILER_LOG.info(' '.join(attrs))
|
|
|
|
|
|
def setup(binary, host):
|
|
if cfg.CONF.profiler.enabled:
|
|
osprofiler.notifier.set(log_to_file)
|
|
osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
|