incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [31/36] git commit: [#6388] start capturing verbose logging in perf script
Date Fri, 20 Dec 2013 18:50:57 GMT
[#6388] start capturing verbose logging in perf script


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

Branch: refs/heads/db/6388
Commit: bdde98d915897858bf7ab34144bde99b8d5a747a
Parents: 3b37e87
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Dec 18 22:39:51 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Dec 20 17:41:29 2013 +0000

----------------------------------------------------------------------
 scripts/perf/call_count.py | 46 ++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bdde98d9/scripts/perf/call_count.py
----------------------------------------------------------------------
diff --git a/scripts/perf/call_count.py b/scripts/perf/call_count.py
index 2b8e15c..718f5b0 100755
--- a/scripts/perf/call_count.py
+++ b/scripts/perf/call_count.py
@@ -18,10 +18,15 @@
 #       under the License.
 
 import json
-from pprint import pprint
+import logging
+import random
+import string
 
 from pylons import tmpl_context as c
 from testfixtures import LogCapture
+from mock import patch
+import timermiddleware
+from ming.odm import ThreadLocalODMSession
 
 from allura import model as M
 from allura.lib.helpers import push_config
@@ -35,16 +40,22 @@ def main():
     test = TestController()
     setup(test)
     url = generate_wiki_thread(test)
-    load_page(test, url)
-    load_page(test, url)
+    ThreadLocalODMSession.close_all()  # make sure ODM sessions won't get re-used
     load_page(test, url)
     test.tearDown()
 
 
 def setup(test):
     # includes setting up mim
-    with patch_middleware_config({'stats.sample_rate': 1}):
-       test.setUp()
+    with patch_middleware_config({'stats.sample_rate': 1,
+                                  'stats.debug_line_length': 1000,
+                                  }), \
+         patch('timermiddleware.log.isEnabledFor', return_value=True):  # can't set this
via logging configuration since setUp() will load a logging config and then start using it
before we have a good place to tweak it
+        test.setUp()
+
+    tmw_log = logging.getLogger('timermiddleware')
+    tmw_log.disabled = 0  # gets disabled when .ini file is loaded; dumb.
+    tmw_log.setLevel(logging.DEBUG)
 
 
 def generate_wiki_thread(test):
@@ -65,16 +76,31 @@ def generate_wiki_thread(test):
         with push_config(c, user=M.User.query.get(username='test-user')):
             thread.add_post(text='I disagree')
 
+    ThreadLocalODMSession.flush_all()
+
     url = '/p/test/wiki/_discuss/thread/{}/'.format(thread._id)
     return url
 
 
-def load_page(test, url):
-    with LogCapture('stats') as l:
-        print url, test.app.get(url, extra_environ=dict(username='*anonymous')).status
-    for r in l.records:
-        timings = json.loads(r.message)
+def load_page(test, url, verbose=False, debug_html=False):
+
+    with LogCapture('stats') as stats, LogCapture('timermiddleware') as calls:
+        resp = test.app.get(url, extra_environ=dict(username='*anonymous'))
+        print url, resp.status
+        if debug_html:
+            debug_filename = 'call-{}.html'.format(''.join([random.choice(string.ascii_letters
+ string.digits) for n in xrange(10)]))
+            with open(debug_filename, 'w') as out:
+                out.write(resp.body)
+            print debug_filename
+
+    if verbose:
+        for r in calls.records:
+            print r.getMessage()
+
+    for r in stats.records:
+        timings = json.loads(r.getMessage())
         print json.dumps(timings['call_counts'])
 
+
 if __name__ == '__main__':
     main()


Mime
View raw message