[CalendarServer-changes] [6581] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Nov 9 13:14:26 PST 2010
Revision: 6581
http://trac.macosforge.org/projects/calendarserver/changeset/6581
Author: exarkun at twistedmatrix.com
Date: 2010-11-09 13:14:22 -0800 (Tue, 09 Nov 2010)
Log Message:
-----------
Re-enable cProfile-based profiling
Update the profiler-related options with which `twistd` is invoked to work with the currently
used version of Twisted. Also add a custom cProfile-based CPU time profiler and use that. Also
start the master (or Single) process with profiling options to allow profiling without slaves.
Modified Paths:
--------------
CalendarServer/trunk/bin/caldavd
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/run
Added Paths:
-----------
CalendarServer/trunk/calendarserver/tap/profiling.py
Modified: CalendarServer/trunk/bin/caldavd
===================================================================
--- CalendarServer/trunk/bin/caldavd 2010-11-09 18:46:08 UTC (rev 6580)
+++ CalendarServer/trunk/bin/caldavd 2010-11-09 21:14:22 UTC (rev 6581)
@@ -111,7 +111,8 @@
'g') groupname="-g ${OPTARG}"; ;;
'P') plugin_name="${OPTARG}"; ;;
't') service_type="-o ProcessType=${OPTARG}"; ;;
- 'p') profile="-o Profiling/Enabled=True -o Profiling/BaseDirectory=${OPTARG}"; ;;
+ 'p') twistd_profile="--profiler=cprofile-cpu --profile=${OPTARG}/master.pstats --savestats";
+ profile="-o Profiling/Enabled=True -o Profiling/BaseDirectory=${OPTARG}"; ;;
'R') twistd_reactor="--reactor=${OPTARG}"; child_reactor="-o Twisted/reactor=${OPTARG}"; ;;
esac;
done;
@@ -122,4 +123,4 @@
export PYTHONPATH
-exec "${python}" "${twistdpath}" ${twistd_reactor} ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${errorlogenabled} ${profile} ${child_reactor};
+exec "${python}" "${twistdpath}" ${twistd_profile} ${twistd_reactor} ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${errorlogenabled} ${profile} ${child_reactor};
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2010-11-09 18:46:08 UTC (rev 6580)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2010-11-09 21:14:22 UTC (rev 6581)
@@ -71,6 +71,8 @@
from twistedcaldav.upgrade import upgradeData
from txdav.base.datastore.subpostgres import PostgresService
+import calendarserver.tap.profiling # Imported for side-effect
+
from calendarserver.tap.util import pgServiceFromConfig
from txdav.base.datastore.asyncsqlpool import ConnectionPool
@@ -1173,7 +1175,7 @@
"--profile=%s/%s.pstats"
% (config.Profiling.BaseDirectory, self.getName())
)
- args.extend(("--savestats", "--nothotshot"))
+ args.extend(("--savestats", "--profiler", "cprofile-cpu"))
args.extend([
"--reactor=%s" % (config.Twisted.reactor,),
Added: CalendarServer/trunk/calendarserver/tap/profiling.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/profiling.py (rev 0)
+++ CalendarServer/trunk/calendarserver/tap/profiling.py 2010-11-09 21:14:22 UTC (rev 6581)
@@ -0,0 +1,49 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import time
+
+from twisted.application.app import CProfileRunner, AppProfiler
+
+class CProfileCPURunner(CProfileRunner):
+ """
+ Runner for the cProfile module which uses C{time.clock} to measure
+ CPU usage instead of the default wallclock time.
+ """
+
+ def run(self, reactor):
+ """
+ Run reactor under the cProfile profiler.
+ """
+ try:
+ import cProfile, pstats
+ except ImportError, e:
+ self._reportImportError("cProfile", e)
+
+ p = cProfile.Profile(time.clock)
+ p.runcall(reactor.run)
+ if self.saveStats:
+ p.dump_stats(self.profileOutput)
+ else:
+ stream = open(self.profileOutput, 'w')
+ s = pstats.Stats(p, stream=stream)
+ s.strip_dirs()
+ s.sort_stats(-1)
+ s.print_stats()
+ stream.close()
+
+
+AppProfiler.profilers["cprofile-cpu"] = CProfileCPURunner
Modified: CalendarServer/trunk/run
===================================================================
--- CalendarServer/trunk/run 2010-11-09 18:46:08 UTC (rev 6580)
+++ CalendarServer/trunk/run 2010-11-09 21:14:22 UTC (rev 6581)
@@ -87,7 +87,7 @@
'R') reactor="-R ${OPTARG}"; ;;
't') service_type="${OPTARG}"; ;;
'K') read_key="${OPTARG}"; ;;
- 'S') profile="--profiler cprofile -p ${OPTARG}"; ;;
+ 'S') profile="-p ${OPTARG}"; ;;
'g') do_get="true" ; do_setup="false"; do_run="false"; ;;
's') do_get="true" ; do_setup="true" ; do_run="false"; ;;
'p') do_get="false"; do_setup="false"; do_run="false"; print_path="true"; ;;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101109/3837e76a/attachment-0001.html>
More information about the calendarserver-changes
mailing list