[CalendarServer-changes] [6136] CalendarServer/trunk/contrib/performance
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 19 14:19:45 PDT 2010
Revision: 6136
http://trac.macosforge.org/projects/calendarserver/changeset/6136
Author: exarkun at twistedmatrix.com
Date: 2010-08-19 14:19:44 -0700 (Thu, 19 Aug 2010)
Log Message:
-----------
handle True/False in normalization as well
Modified Paths:
--------------
CalendarServer/trunk/contrib/performance/stats.py
CalendarServer/trunk/contrib/performance/test_stats.py
Modified: CalendarServer/trunk/contrib/performance/stats.py
===================================================================
--- CalendarServer/trunk/contrib/performance/stats.py 2010-08-19 20:15:39 UTC (rev 6135)
+++ CalendarServer/trunk/contrib/performance/stats.py 2010-08-19 21:19:44 UTC (rev 6136)
@@ -47,6 +47,13 @@
class SQLDuration(_Statistic):
commands = ['summarize', 'statements']
+ def _is_literal(self, token):
+ if sqlparse.tokens.is_token_subtype(token.ttype, sqlparse.tokens.Literal):
+ return True
+ if token.ttype == sqlparse.tokens.Keyword and token.value in (u'True', u'False'):
+ return True
+ return False
+
def _substitute(self, expression, replacement):
try:
expression.tokens
@@ -54,7 +61,7 @@
return
for i, token in enumerate(expression.tokens):
- if sqlparse.tokens.is_token_subtype(token.ttype, sqlparse.tokens.Literal):
+ if self._is_literal(token):
expression.tokens[i] = replacement
elif token.is_whitespace():
expression.tokens[i] = sqlparse.sql.Token('Whitespace', ' ')
@@ -90,12 +97,17 @@
byTime = []
for statement, times in statements.iteritems():
- byTime.append((sum(times), statement))
+ byTime.append((sum(times), len(times), statement))
byTime.sort()
byTime.reverse()
- for (time, statement) in byTime:
- print time / NANO * 1000, 'ms:', statement
+ if byTime:
+ header = '%10s %10s %10s %s'
+ row = '%10.5f %10.5f %10d %s'
+ print header % ('TOTAL MS', 'PERCALL MS', 'NCALLS', 'STATEMENT')
+ for (time, count, statement) in byTime:
+ time = time / NANO * 1000
+ print row % (time, time / count, count, statement)
class Bytes(_Statistic):
pass
Modified: CalendarServer/trunk/contrib/performance/test_stats.py
===================================================================
--- CalendarServer/trunk/contrib/performance/test_stats.py 2010-08-19 20:15:39 UTC (rev 6135)
+++ CalendarServer/trunk/contrib/performance/test_stats.py 2010-08-19 21:19:44 UTC (rev 6136)
@@ -19,3 +19,9 @@
self.stat.normalize('SELECT foo + 1 FROM bar'),
'SELECT foo + ? FROM bar')
+
+ def test_normalize_boolean(self):
+ self.assertEquals(
+ self.stat.normalize('SELECT foo FROM bar WHERE True'),
+ 'SELECT foo FROM bar WHERE ?')
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100819/e79c791b/attachment-0001.html>
More information about the calendarserver-changes
mailing list