本文整理汇总了Python中qutebrowser.utils.debug.log_time函数的典型用法代码示例。如果您正苦于以下问题:Python log_time函数的具体用法?Python log_time怎么用?Python log_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_url_completion
def _init_url_completion():
"""Initialize the URL completion model."""
log.completion.debug("Initializing URL completion.")
with debug.log_time(log.completion, 'URL completion init'):
model = _init_model(urlmodel.UrlCompletionModel,
dumb_sort=Qt.DescendingOrder)
_instances[usertypes.Completion.url] = model
示例2: action
def action():
with debug.log_time(log.init, 'Import old history file to sqlite'):
try:
self._read(path)
except ValueError as ex:
message.error('Failed to import history: {}'.format(ex))
else:
self._write_backup(path)
示例3: _update_completion
def _update_completion(self):
"""Check if completions are available and activate them."""
if self._ignore_change:
log.completion.debug("Ignoring completion update because "
"ignore_change is True.")
self._ignore_change = False
return
completion = self.parent()
if self._cmd.prefix() != ':':
# This is a search or gibberish, so we don't need to complete
# anything (yet)
# FIXME complete searches
# https://github.com/qutebrowser/qutebrowser/issues/32
completion.set_model(None)
self._last_completion_func = None
return
before_cursor, pattern, after_cursor = self._partition()
log.completion.debug("Updating completion: {} {} {}".format(
before_cursor, pattern, after_cursor))
pattern = pattern.strip("'\"")
func = self._get_new_completion(before_cursor, pattern)
if func is None:
log.completion.debug('Clearing completion')
completion.set_model(None)
self._last_completion_func = None
return
if func != self._last_completion_func:
self._last_completion_func = func
args = (x for x in before_cursor[1:] if not x.startswith('-'))
with debug.log_time(log.completion,
'Starting {} completion'.format(func.__name__)):
info = CompletionInfo(config=config.instance,
keyconf=config.key_instance)
model = func(*args, info=info)
with debug.log_time(log.completion, 'Set completion model'):
completion.set_model(model)
completion.set_pattern(pattern)
示例4: test_logger
def test_logger(self, caplog):
"""Test with an explicit logger instead of a name."""
logger_name = 'qt-tests'
with caplog.at_level(logging.DEBUG, logger_name):
with debug.log_time(logging.getLogger(logger_name)):
pass
assert len(caplog.records) == 1
示例5: removeRows
def removeRows(self, row, _count, _parent=None):
"""Override QAbstractItemModel::removeRows to re-run sql query."""
# re-run query to reload updated table
with debug.log_time('sql', 'Re-running completion query post-delete'):
self._query.run()
self.setQuery(self._query.query)
while self.rowCount() < row:
self.fetchMore()
return True
示例6: set_pattern
def set_pattern(self, pattern):
"""Set the pattern on the underlying model."""
if not self.model():
return
self.pattern = pattern
with debug.log_time(log.completion, 'Set pattern {}'.format(pattern)):
self.model().set_pattern(pattern)
self.selectionModel().clear()
self._maybe_update_geometry()
self._maybe_show()
示例7: historyContains
def historyContains(self, url_string):
"""Called by WebKit to determine if a URL is contained in the history.
Args:
url_string: The URL (as string) to check for.
Return:
True if the url is in the history, False otherwise.
"""
with debug.log_time('sql', 'historyContains'):
return url_string in self._history
示例8: action
def action():
with debug.log_time(log.init, 'Import old history file to sqlite'):
try:
self._read(path)
except ValueError as ex:
message.error('Failed to import history: {}'.format(ex))
else:
bakpath = path + '.bak'
message.info('History import complete. Moving {} to {}'
.format(path, bakpath))
os.rename(path, bakpath)
示例9: _init_late_modules
def _init_late_modules(args):
"""Initialize modules which can be inited after the window is shown."""
log.init.debug("Reading web history...")
reader = objreg.get("web-history").async_read()
with debug.log_time(log.init, "Reading history"):
while True:
QApplication.processEvents()
try:
next(reader)
except StopIteration:
break
except (OSError, UnicodeDecodeError) as e:
error.handle_fatal_exc(e, args, "Error while initializing!", pre_text="Error while initializing")
sys.exit(usertypes.Exit.err_init)
示例10: set_pattern
def set_pattern(self, pattern):
"""Set the pattern used to filter results.
Args:
pattern: string pattern to filter by.
"""
# escape to treat a user input % or _ as a literal, not a wildcard
pattern = pattern.replace('%', '\\%')
pattern = pattern.replace('_', '\\_')
words = ['%{}%'.format(w) for w in pattern.split(' ')]
# build a where clause to match all of the words in any order
# given the search term "a b", the WHERE clause would be:
# (url LIKE '%a%' OR title LIKE '%a%') AND
# (url LIKE '%b%' OR title LIKE '%b%')
where_clause = ' AND '.join(
"(url LIKE :{val} escape '\\' OR title LIKE :{val} escape '\\')"
.format(val=i) for i in range(len(words)))
# replace ' in timestamp-format to avoid breaking the query
timestamp_format = config.val.completion.timestamp_format or ''
timefmt = ("strftime('{}', last_atime, 'unixepoch', 'localtime')"
.format(timestamp_format.replace("'", "`")))
try:
if (not self._query or
len(words) != len(self._query.bound_values())):
# if the number of words changed, we need to generate a new
# query otherwise, we can reuse the prepared query for
# performance
self._query = sql.Query(' '.join([
"SELECT url, title, {}".format(timefmt),
"FROM CompletionHistory",
# the incoming pattern will have literal % and _ escaped we
# need to tell SQL to treat '\' as an escape character
'WHERE ({})'.format(where_clause),
self._atime_expr(),
"ORDER BY last_atime DESC",
]), forward_only=False)
with debug.log_time('sql', 'Running completion query'):
self._query.run(**{
str(i): w for i, w in enumerate(words)})
except sql.KnownError as e:
# Sometimes, the query we built up was invalid, for example,
# due to a large amount of words.
# Also catches failures in the DB we can't solve.
message.error("Error with SQL query: {}".format(e.text()))
return
self.setQuery(self._query.query)
示例11: test_duration
def test_duration(self, caplog):
logger_name = 'qt-tests'
with caplog.at_level(logging.DEBUG, logger_name):
with debug.log_time(logger_name, action='foobar'):
time.sleep(0.1)
assert len(caplog.records) == 1
pattern = re.compile(r'^Foobar took ([\d.]*) seconds\.$')
match = pattern.match(caplog.records[0].msg)
assert match
duration = float(match.group(1))
assert 0 < duration < 30
示例12: set_pattern
def set_pattern(self, val):
"""Setter for pattern.
Invalidates the filter and re-sorts the model.
Args:
val: The value to set.
"""
with debug.log_time(log.completion, 'Setting filter pattern'):
self.pattern = val
val = re.escape(val)
val = val.replace(r'\ ', r'.*')
self.pattern_re = re.compile(val, re.IGNORECASE)
self.invalidate()
sortcol = 0
self.sort(sortcol)
示例13: test_duration
def test_duration(self, caplog):
logger_name = "qt-tests"
with caplog.atLevel(logging.DEBUG, logger_name):
with debug.log_time(logger_name, action="foobar"):
time.sleep(0.1)
records = caplog.records()
assert len(records) == 1
pattern = re.compile(r"^Foobar took ([\d.]*) seconds\.$")
match = pattern.match(records[0].msg)
assert match
duration = float(match.group(1))
assert 0 < duration < 30
示例14: set_pattern
def set_pattern(self, val):
"""Setter for pattern.
Invalidates the filter and re-sorts the model.
Args:
val: The value to set.
"""
with debug.log_time(log.completion, "Setting filter pattern"):
# empty value clears cache (not necessary for correctness, but
# helps with keeping memory requirements relatively low)
if not val:
self.srcmodel.filtered_out_cache = {}
self.pattern = val
self.invalidate()
sortcol = 0
self.sort(sortcol)
示例15: test_log_time
def test_log_time(caplog):
"""Test if log_time logs properly."""
logger_name = 'qt-tests'
with caplog.atLevel(logging.DEBUG, logger=logger_name):
with debug.log_time(logging.getLogger(logger_name), action='foobar'):
time.sleep(0.1)
records = caplog.records()
assert len(records) == 1
pattern = re.compile(r'^Foobar took ([\d.]*) seconds\.$')
match = pattern.match(records[0].msg)
assert match
duration = float(match.group(1))
assert 0.08 <= duration <= 0.12