incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [22/50] git commit: [#6699] make instrumentation extensible; refine mongo instrumentation
Date Thu, 26 Sep 2013 18:29:40 GMT
[#6699] make instrumentation extensible; refine mongo instrumentation


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d22e7983
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d22e7983
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d22e7983

Branch: refs/heads/tv/6612
Commit: d22e79832940794c04cd5e187442bb5e46dd7c4e
Parents: f236c14
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Mon Sep 23 17:00:37 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Tue Sep 24 04:01:56 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/custom_middleware.py | 51 +++++------------------------
 Allura/docs/extending.rst              |  1 +
 ForgeGit/forgegit/git_main.py          | 13 ++++++++
 ForgeGit/setup.py                      |  4 +++
 ForgeSVN/forgesvn/svn_main.py          | 11 ++++++-
 ForgeSVN/setup.py                      |  4 +++
 6 files changed, 41 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index d4652ab..c942474 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -23,6 +23,7 @@ from contextlib import contextmanager
 import tg
 import pkg_resources
 from paste import fileapp
+from paste.deploy.converters import aslist
 from pylons import tmpl_context as c
 from pylons.util import call_wsgi_application
 from timermiddleware import Timer, TimerMiddleware
@@ -180,10 +181,10 @@ class AlluraTimerMiddleware(TimerMiddleware):
         import socket
         import urllib2
 
-        return self.scm_lib_timers() + self.repo_impl_timers() + [
+        return self.entry_point_timers() + [
             Timer('jinja', jinja2.Template, 'render', 'stream', 'generate'),
             Timer('markdown', markdown.Markdown, 'convert'),
-            Timer('ming', ming.odm.odmsession.ODMCursor, 'next'),
+            Timer('ming', ming.odm.odmsession.ODMCursor, 'next'),  # FIXME: this may captures
timings ok, but is misleading for counts
             Timer('ming', ming.odm.odmsession.ODMSession, 'flush', 'find',
                 'get'),
             Timer('ming', ming.schema.Document, 'validate',
@@ -194,8 +195,7 @@ class AlluraTimerMiddleware(TimerMiddleware):
             Timer('mongo', pymongo.collection.Collection, 'count', 'find',
                 'find_one'),
             Timer('mongo', pymongo.cursor.Cursor, 'count', 'distinct',
-                'explain', 'hint', 'limit', 'next', 'rewind', 'skip',
-                'sort', 'where'),
+                '_refresh'),
             # urlopen and socket io may or may not overlap partially
             Timer('render', genshi.Stream, 'render'),
             Timer('repo.Blob.{method_name}', allura.model.repo.Blob, '*'),
@@ -210,6 +210,7 @@ class AlluraTimerMiddleware(TimerMiddleware):
             Timer('template', genshi.template.Template, '_prepare', '_parse',
                 'generate'),
             Timer('urlopen', urllib2, 'urlopen'),
+            Timer('base_repo_tool.{method_name}', allura.model.repository.RepositoryImplementation,
'last_commit_ids'),
             Timer('_diffs_copied', allura.model.repo.Commit, '_diffs_copied'),
             Timer('sequencematcher.{method_name}', allura.model.repo.SequenceMatcher, 'ratio',
'quick_ratio', 'real_quick_ratio'),
             Timer('unified_diff', allura.model.repo, 'unified_diff'),
@@ -220,43 +221,9 @@ class AlluraTimerMiddleware(TimerMiddleware):
             stat_record.add('request_category', c.app.config.tool_name.lower())
         return stat_record
 
-    def scm_lib_timers(self):
+    def entry_point_timers(self):
         timers = []
-        with pass_on_exc(ImportError):
-            import forgesvn
-            timers.append(Timer('svn_lib.{method_name}', forgesvn.model.svn.SVNLibWrapper,
'checkout', 'add',
-                        'checkin', 'info2', 'log', 'cat', 'list'))
-        with pass_on_exc(ImportError):
-            import git
-            import forgegit
-            timers.append(Timer('git_lib.{method_name}', git.Repo, 'rev_parse', 'iter_commits',
'commit'))
-            timers.append(Timer('git_lib.{method_name}', forgegit.model.git_repo.GitLibCmdWrapper,
'log'))
-        with pass_on_exc(ImportError):
-            import mercurial.hg
-            timers.append(Timer('hg_lib.{method_name}', mercurial.hg.localrepo.localrepository,
'heads',
-                'branchtags', 'tags'))
-            timers.append(Timer('hg_lib.{method_name}', mercurial.cmdutil, 'walkchangerevs'))
+        for ep in h.iter_entry_points('allura.timers'):
+            func = ep.load()
+            timers += aslist(func())
         return timers
-
-    def repo_impl_timers(self):
-        timers= []
-        from allura.model.repository import Repository, RepositoryImplementation
-        timers.append(Timer('base_tool.{method_name}', RepositoryImplementation, 'last_commit_ids'))
-        with pass_on_exc(ImportError):
-            from forgegit.model.git_repo import GitImplementation
-            timers.append(Timer('git_tool.{method_name}', GitImplementation, '*'))
-        with pass_on_exc(ImportError):
-            from forgesvn.model.svn import SVNImplementation
-            timers.append(Timer('svn_tool.{method_name}', SVNImplementation, '*'))
-        with pass_on_exc(ImportError):
-            from forgehg.model.hg import HgImplementation
-            timers.append(Timer('hg_tool.{method_name}', HgImplementation, '*'))
-        return timers
-
-
-@contextmanager
-def pass_on_exc(exc):
-    try:
-        yield
-    except exc:
-        pass

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/Allura/docs/extending.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/extending.rst b/Allura/docs/extending.rst
index 5458b69..c241d5f 100644
--- a/Allura/docs/extending.rst
+++ b/Allura/docs/extending.rst
@@ -34,6 +34,7 @@ The available extension points for Allura are:
 * :class:`allura.lib.spam.SpamFilter`
 * ``site_stats`` in the root API data.  Docs in :class:`allura.controllers.rest.RestController`
 * :mod:`allura.lib.package_path_loader` (for overriding templates)
+* ``[allura.timers]`` functions which return a list or single :class:`timermiddleware.Timer`
which will be included in stats.log timings
 
 A listing of available 3rd-party extensions is at https://forge-allura.apache.org/p/allura/wiki/Extensions/
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/ForgeGit/forgegit/git_main.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index 2ba63bc..1d11e41 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -23,6 +23,8 @@ from pylons import tmpl_context as c
 
 from ming.utils import LazyProperty
 from ming.orm.ormsession import ThreadLocalORMSession
+from timermiddleware import Timer
+import git
 
 # Pyforge-specific imports
 import allura.tasks.repo_tasks
@@ -106,3 +108,14 @@ class ForgeGitApp(RepositoryApp):
                 cloned_from_url=init_from_url)
         else:
             allura.tasks.repo_tasks.init.post()
+
+
+def git_timers():
+    return [
+        Timer('git_lib.{method_name}', git.Repo, 'rev_parse', 'iter_commits', 'commit'),
+        Timer('git_lib.{method_name}', GM.git_repo.GitLibCmdWrapper, 'log'),
+    ]
+
+
+def forgegit_timers():
+    return Timer('git_tool.{method_name}', GM.git_repo.GitImplementation, '*')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/ForgeGit/setup.py
----------------------------------------------------------------------
diff --git a/ForgeGit/setup.py b/ForgeGit/setup.py
index 0f6274d..3d14ef3 100644
--- a/ForgeGit/setup.py
+++ b/ForgeGit/setup.py
@@ -42,5 +42,9 @@ setup(name='ForgeGit',
       # -*- Entry points: -*-
       [allura]
       Git=forgegit.git_main:ForgeGitApp
+
+      [allura.timers]
+      git = forgegit.git_main:git_timers
+      forgegit = forgegit.git_main:forgegit_timers
       """,
       )

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/ForgeSVN/forgesvn/svn_main.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/svn_main.py b/ForgeSVN/forgesvn/svn_main.py
index 03b1b7f..bee61b3 100644
--- a/ForgeSVN/forgesvn/svn_main.py
+++ b/ForgeSVN/forgesvn/svn_main.py
@@ -18,13 +18,13 @@
 #-*- python -*-
 import logging
 from pylons import tmpl_context as c
-from pylons import request
 
 # Non-stdlib imports
 from ming.utils import LazyProperty
 from ming.orm.ormsession import ThreadLocalORMSession
 from tg import expose, redirect, validate, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
+from timermiddleware import Timer
 
 # Pyforge-specific imports
 import allura.tasks.repo_tasks
@@ -169,3 +169,12 @@ class SVNImportController(BaseController):
                 c.user, self.app.repo, 'error',
                 text="Can't import into non empty repository.")
         redirect(c.project.url() + 'admin/tools')
+
+
+def svn_timers():
+    return Timer('svn_lib.{method_name}', SM.svn.SVNLibWrapper, 'checkout', 'add',
+                 'checkin', 'info2', 'log', 'cat', 'list')
+
+
+def forgesvn_timers():
+    return Timer('svn_tool.{method_name}', SM.svn.SVNImplementation, '*')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d22e7983/ForgeSVN/setup.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/setup.py b/ForgeSVN/setup.py
index 2ee8d2e..d3b1154 100644
--- a/ForgeSVN/setup.py
+++ b/ForgeSVN/setup.py
@@ -51,5 +51,9 @@ setup(name='ForgeSVN',
       # -*- Entry points: -*-
       [allura]
       SVN=forgesvn.svn_main:ForgeSVNApp
+
+      [allura.timers]
+      svn = forgesvn.svn_main:svn_timers
+      forgesvn = forgesvn.svn_main:forgesvn_timers
       """,
       )


Mime
View raw message