[CalendarServer-changes] [6126] CalendarServer/trunk/contrib/performance
source_changes at macosforge.org
source_changes at macosforge.org
Wed Aug 18 17:28:02 PDT 2010
Revision: 6126
http://trac.macosforge.org/projects/calendarserver/changeset/6126
Author: exarkun at twistedmatrix.com
Date: 2010-08-18 17:28:02 -0700 (Wed, 18 Aug 2010)
Log Message:
-----------
watch a process for SQL statements it executes, then report them and how long they took
Added Paths:
-----------
CalendarServer/trunk/contrib/performance/sqlwatch
CalendarServer/trunk/contrib/performance/sqlwatch.py
Added: CalendarServer/trunk/contrib/performance/sqlwatch
===================================================================
--- CalendarServer/trunk/contrib/performance/sqlwatch (rev 0)
+++ CalendarServer/trunk/contrib/performance/sqlwatch 2010-08-19 00:28:02 UTC (rev 6126)
@@ -0,0 +1,3 @@
+#!/usr/bin/python
+from sqlwatch import main
+main()
Property changes on: CalendarServer/trunk/contrib/performance/sqlwatch
___________________________________________________________________
Added: svn:executable
+ *
Added: CalendarServer/trunk/contrib/performance/sqlwatch.py
===================================================================
--- CalendarServer/trunk/contrib/performance/sqlwatch.py (rev 0)
+++ CalendarServer/trunk/contrib/performance/sqlwatch.py 2010-08-19 00:28:02 UTC (rev 6126)
@@ -0,0 +1,65 @@
+
+import sys, os, signal, time
+from pprint import pprint
+
+from twisted.python.failure import Failure
+from twisted.internet.defer import Deferred, inlineCallbacks
+from twisted.internet import reactor
+
+from benchmark import DTraceCollector
+
+
+class Stop(Exception):
+ pass
+
+
+interrupted = 0.0
+def waitForInterrupt():
+ if signal.getsignal(signal.SIGINT) != signal.default_int_handler:
+ raise RuntimeError("Already waiting")
+
+ d = Deferred()
+ def fire(*ignored):
+ global interrupted
+ signal.signal(signal.SIGINT, signal.default_int_handler)
+ now = time.time()
+ if now - interrupted < 4:
+ reactor.callFromThread(lambda: d.errback(Failure(Stop())))
+ else:
+ interrupted = now
+ reactor.callFromThread(d.callback, None)
+ signal.signal(signal.SIGINT, fire)
+ return d
+
+
+ at inlineCallbacks
+def collect(pids):
+ while True:
+ dtrace = DTraceCollector("sql_measure.d", pids)
+ print 'Starting'
+ yield dtrace.start()
+ print 'Started'
+ try:
+ yield waitForInterrupt()
+ except Stop:
+ yield dtrace.stop()
+ break
+ print 'Stopping'
+ stats = yield dtrace.stop()
+ for s in stats:
+ if s.name == 'execute':
+ s.statements(stats[s])
+ print 'Stopped'
+
+
+def main():
+ pids = []
+ for pidfile in os.listdir(sys.argv[1]):
+ if pidfile.startswith('caldav-instance-'):
+ pidpath = os.path.join(sys.argv[1], pidfile)
+ pidtext = file(pidpath).read()
+ pid = int(pidtext)
+ pids.append(pid)
+ d = collect(pids)
+ d.addBoth(lambda ign: reactor.stop())
+ reactor.run(installSignalHandlers=False)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100818/74e46a77/attachment-0001.html>
More information about the calendarserver-changes
mailing list