##// END OF EJS Templates
core: added more accurate time measurement for called functions
marcink -
r3853:5f8c0244 default
parent child Browse files
Show More
@@ -130,7 +130,7 b' def pre_request(worker, req):'
130 def post_request(worker, req, environ, resp):
130 def post_request(worker, req, environ, resp):
131 total_time = time.time() - worker.start_time
131 total_time = time.time() - worker.start_time
132 worker.log.debug(
132 worker.log.debug(
133 "GNCRN POST WORKER [cnt:%s]: %s %s resp: %s, Load Time: %.3fs",
133 "GNCRN POST WORKER [cnt:%s]: %s %s resp: %s, Load Time: %.4fs",
134 worker.nr, req.method, req.path, resp.status_code, total_time)
134 worker.nr, req.method, req.path, resp.status_code, total_time)
135
135
136
136
@@ -101,7 +101,7 b' def search(request, apiuser, search_quer'
101 searcher.cleanup()
101 searcher.cleanup()
102
102
103 if not search_result['error']:
103 if not search_result['error']:
104 data['execution_time'] = '%s results (%.3f seconds)' % (
104 data['execution_time'] = '%s results (%.4f seconds)' % (
105 search_result['count'],
105 search_result['count'],
106 search_result['runtime'])
106 search_result['runtime'])
107 else:
107 else:
@@ -169,7 +169,7 b' class RepoFeedView(RepoAppView):'
169 else:
169 else:
170 mime_type, feed = generate_atom_feed(*args)
170 mime_type, feed = generate_atom_feed(*args)
171
171
172 log.debug('Repo ATOM feed computed in %.3fs',
172 log.debug('Repo ATOM feed computed in %.4fs',
173 inv_context_manager.compute_time)
173 inv_context_manager.compute_time)
174
174
175 response = Response(feed)
175 response = Response(feed)
@@ -235,7 +235,7 b' class RepoFeedView(RepoAppView):'
235 else:
235 else:
236 mime_type, feed = generate_rss_feed(*args)
236 mime_type, feed = generate_rss_feed(*args)
237 log.debug(
237 log.debug(
238 'Repo RSS feed computed in %.3fs', inv_context_manager.compute_time)
238 'Repo RSS feed computed in %.4fs', inv_context_manager.compute_time)
239
239
240 response = Response(feed)
240 response = Response(feed)
241 response.content_type = mime_type
241 response.content_type = mime_type
@@ -98,7 +98,7 b' class RepoSummaryView(RepoAppView):'
98 instance = generate_repo_readme(*args)
98 instance = generate_repo_readme(*args)
99
99
100 log.debug(
100 log.debug(
101 'Repo readme generated and computed in %.3fs',
101 'Repo readme generated and computed in %.4fs',
102 inv_context_manager.compute_time)
102 inv_context_manager.compute_time)
103 return instance
103 return instance
104
104
@@ -88,7 +88,7 b' def perform_search(request, tmpl_context'
88 search_tags = searcher.extract_search_tags(search_query)
88 search_tags = searcher.extract_search_tags(search_query)
89
89
90 if not search_result['error']:
90 if not search_result['error']:
91 execution_time = '%s results (%.3f seconds)' % (
91 execution_time = '%s results (%.4f seconds)' % (
92 search_result['count'],
92 search_result['count'],
93 search_result['runtime'])
93 search_result['runtime'])
94 elif not errors:
94 elif not errors:
@@ -762,7 +762,7 b' def authenticate(username, password, env'
762 plugin_user = compute_auth('auth', plugin.name, username, (password or ''))
762 plugin_user = compute_auth('auth', plugin.name, username, (password or ''))
763
763
764 auth_time = time.time() - start
764 auth_time = time.time() - start
765 log.debug('Authentication for plugin `%s` completed in %.3fs, '
765 log.debug('Authentication for plugin `%s` completed in %.4fs, '
766 'expiration time of fetched cache %.1fs.',
766 'expiration time of fetched cache %.1fs.',
767 plugin.get_id(), auth_time, cache_ttl)
767 plugin.get_id(), auth_time, cache_ttl)
768
768
@@ -1233,7 +1233,7 b' class AuthUser(object):'
1233 for k in result:
1233 for k in result:
1234 result_repr.append((k, len(result[k])))
1234 result_repr.append((k, len(result[k])))
1235 total = time.time() - start
1235 total = time.time() - start
1236 log.debug('PERMISSION tree for user %s computed in %.3fs: %s',
1236 log.debug('PERMISSION tree for user %s computed in %.4fs: %s',
1237 user, total, result_repr)
1237 user, total, result_repr)
1238
1238
1239 return result
1239 return result
@@ -2402,7 +2402,7 b' class Repository(Base, BaseModel):'
2402 instance = get_instance_cached(*args)
2402 instance = get_instance_cached(*args)
2403
2403
2404 log.debug(
2404 log.debug(
2405 'Repo instance fetched in %.3fs', inv_context_manager.compute_time)
2405 'Repo instance fetched in %.4fs', inv_context_manager.compute_time)
2406 return instance
2406 return instance
2407
2407
2408 def _get_instance(self, cache=True, config=None):
2408 def _get_instance(self, cache=True, config=None):
@@ -2425,7 +2425,7 b' class Repository(Base, BaseModel):'
2425 instance = get_instance_cached(*args)
2425 instance = get_instance_cached(*args)
2426
2426
2427 log.debug(
2427 log.debug(
2428 'Repo instance fetched in %.3fs', inv_context_manager.compute_time)
2428 'Repo instance fetched in %.4fs', inv_context_manager.compute_time)
2429 return instance
2429 return instance
2430
2430
2431 def _get_instance(self, cache=True, config=None):
2431 def _get_instance(self, cache=True, config=None):
@@ -2425,7 +2425,7 b' class Repository(Base, BaseModel):'
2425 instance = get_instance_cached(*args)
2425 instance = get_instance_cached(*args)
2426
2426
2427 log.debug(
2427 log.debug(
2428 'Repo instance fetched in %.3fs', inv_context_manager.compute_time)
2428 'Repo instance fetched in %.4fs', inv_context_manager.compute_time)
2429 return instance
2429 return instance
2430
2430
2431 def _get_instance(self, cache=True, config=None):
2431 def _get_instance(self, cache=True, config=None):
@@ -1178,7 +1178,7 b' def cache_diff(cached_diff_file, diff, c'
1178 log.warn('Failed to save cache', exc_info=True)
1178 log.warn('Failed to save cache', exc_info=True)
1179 _cleanup_cache_file(cached_diff_file)
1179 _cleanup_cache_file(cached_diff_file)
1180
1180
1181 log.debug('Saved diff cache under %s in %.3fs', cached_diff_file, time.time() - start)
1181 log.debug('Saved diff cache under %s in %.4fs', cached_diff_file, time.time() - start)
1182
1182
1183
1183
1184 def load_cached_diff(cached_diff_file):
1184 def load_cached_diff(cached_diff_file):
@@ -1221,7 +1221,7 b' def load_cached_diff(cached_diff_file):'
1221 _cleanup_cache_file(cached_diff_file)
1221 _cleanup_cache_file(cached_diff_file)
1222 return default_struct
1222 return default_struct
1223
1223
1224 log.debug('Loaded diff cache from %s in %.3fs', cached_diff_file, time.time() - start)
1224 log.debug('Loaded diff cache from %s in %.4fs', cached_diff_file, time.time() - start)
1225
1225
1226 return data
1226 return data
1227
1227
@@ -45,7 +45,7 b' class RequestWrapperTween(object):'
45 end = time.time()
45 end = time.time()
46 total = end - start
46 total = end - start
47 log.info(
47 log.info(
48 'IP: %s %s Request to %s time: %.3fs [%s]',
48 'IP: %s %s Request to %s time: %.4fs [%s]',
49 get_ip_addr(request.environ), request.environ.get('REQUEST_METHOD'),
49 get_ip_addr(request.environ), request.environ.get('REQUEST_METHOD'),
50 safe_str(get_access_path(request.environ)), total,
50 safe_str(get_access_path(request.environ)), total,
51 get_user_agent(request. environ)
51 get_user_agent(request. environ)
@@ -354,7 +354,7 b' class SimpleVCS(object):'
354 'vcs_permissions', plugin_id, action, user.user_id, repo_name, ip_addr)
354 'vcs_permissions', plugin_id, action, user.user_id, repo_name, ip_addr)
355
355
356 auth_time = time.time() - start
356 auth_time = time.time() - start
357 log.debug('Permissions for plugin `%s` completed in %.3fs, '
357 log.debug('Permissions for plugin `%s` completed in %.4fs, '
358 'expiration time of fetched cache %.1fs.',
358 'expiration time of fetched cache %.1fs.',
359 plugin_id, auth_time, cache_ttl)
359 plugin_id, auth_time, cache_ttl)
360
360
@@ -251,7 +251,7 b' class InvalidationContext(object):'
251 result = heavy_compute(*args)
251 result = heavy_compute(*args)
252
252
253 compute_time = inv_context_manager.compute_time
253 compute_time = inv_context_manager.compute_time
254 log.debug('result computed in %.3fs', compute_time)
254 log.debug('result computed in %.4fs', compute_time)
255
255
256 # To send global invalidation signal, simply run
256 # To send global invalidation signal, simply run
257 CacheKey.set_invalidate(invalidation_namespace)
257 CacheKey.set_invalidate(invalidation_namespace)
@@ -289,7 +289,8 b' class InvalidationContext(object):'
289 log.debug('Fetched cache obj %s using %s cache key.', cache_obj, self.cache_key)
289 log.debug('Fetched cache obj %s using %s cache key.', cache_obj, self.cache_key)
290 invalidation_namespace = invalidation_namespace or self.invalidation_namespace
290 invalidation_namespace = invalidation_namespace or self.invalidation_namespace
291 if not cache_obj:
291 if not cache_obj:
292 cache_obj = CacheKey(self.cache_key, cache_args=invalidation_namespace)
292 new_cache_args = invalidation_namespace
293 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args)
293 return cache_obj
294 return cache_obj
294
295
295 def __enter__(self):
296 def __enter__(self):
@@ -158,7 +158,8 b' class GitCommit(base.BaseCommit):'
158
158
159 @LazyProperty
159 @LazyProperty
160 def branch(self):
160 def branch(self):
161 branches = safe_unicode(self._remote.branch(self.raw_id))
161 branches = self._remote.branch(self.raw_id)
162
162 if branches:
163 if branches:
163 # actually commit can have multiple branches in git
164 # actually commit can have multiple branches in git
164 return safe_unicode(branches[0])
165 return safe_unicode(branches[0])
@@ -154,7 +154,7 b' class RemoteRepo(object):'
154 self.url, name, args, context_uid)
154 self.url, name, args, context_uid)
155 result = _remote_call(self.url, payload, EXCEPTIONS_MAP, self._session)
155 result = _remote_call(self.url, payload, EXCEPTIONS_MAP, self._session)
156 if self._call_with_logging:
156 if self._call_with_logging:
157 log.debug('Call %s@%s took: %.3fs. wire_context: %s',
157 log.debug('Call %s@%s took: %.4fs. wire_context: %s',
158 self.url, name, time.time()-start, context_uid)
158 self.url, name, time.time()-start, context_uid)
159 return result
159 return result
160
160
@@ -2481,7 +2481,7 b' class Repository(Base, BaseModel):'
2481 else:
2481 else:
2482 instance = get_instance_cached(*args)
2482 instance = get_instance_cached(*args)
2483
2483
2484 log.debug('Repo instance fetched in %.3fs', inv_context_manager.compute_time)
2484 log.debug('Repo instance fetched in %.4fs', inv_context_manager.compute_time)
2485 return instance
2485 return instance
2486
2486
2487 def _get_instance(self, cache=True, config=None, repo_state_uid=None):
2487 def _get_instance(self, cache=True, config=None, repo_state_uid=None):
@@ -242,7 +242,7 b' class SettingsModel(BaseModel):'
242 region.invalidate()
242 region.invalidate()
243
243
244 result = _get_all_settings('rhodecode_settings', key)
244 result = _get_all_settings('rhodecode_settings', key)
245 log.debug('Fetching app settings for key: %s took: %.3fs', key,
245 log.debug('Fetching app settings for key: %s took: %.4fs', key,
246 inv_context_manager.compute_time)
246 inv_context_manager.compute_time)
247
247
248 return result
248 return result
@@ -43,7 +43,7 b' def main(server, repeat, pages):'
43 t = timeit.Timer(stmt=stmt, setup="import requests")
43 t = timeit.Timer(stmt=stmt, setup="import requests")
44
44
45 result = t.repeat(repeat=repeat, number=1)
45 result = t.repeat(repeat=repeat, number=1)
46 print(" %.3f (min) - %.3f (max) - %.3f (avg)\n" %
46 print(" %.4f (min) - %.4f (max) - %.4f (avg)\n" %
47 (min(result), max(result), sum(result) / len(result)))
47 (min(result), max(result), sum(result) / len(result)))
48
48
49
49
@@ -198,6 +198,6 b" if __name__ == '__main__':"
198 print('take {}'.format(i))
198 print('take {}'.format(i))
199 test_clone_with_credentials(repo=sys.argv[1], method=METHOD,
199 test_clone_with_credentials(repo=sys.argv[1], method=METHOD,
200 seq=seq, backend=backend)
200 seq=seq, backend=backend)
201 print('time taken %.3f' % (time.time() - s))
201 print('time taken %.4f' % (time.time() - s))
202 except Exception as e:
202 except Exception as e:
203 sys.exit('stop on %s' % e)
203 sys.exit('stop on %s' % e)
General Comments 0
You need to be logged in to leave comments. Login now