[CalendarServer-changes] [13774] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 17 12:55:36 PDT 2014


Revision: 13774
          http://trac.calendarserver.org//changeset/13774
Author:   cdaboo at apple.com
Date:     2014-07-17 12:55:36 -0700 (Thu, 17 Jul 2014)
Log Message:
-----------
Additional sqlusage tests. Add profile wrapper functions.

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/sqlusage/requests/invite.py
    CalendarServer/trunk/contrib/performance/sqlusage/sqlusage.py

Added Paths:
-----------
    CalendarServer/trunk/calendarserver/profiling.py

Added: CalendarServer/trunk/calendarserver/profiling.py
===================================================================
--- CalendarServer/trunk/calendarserver/profiling.py	                        (rev 0)
+++ CalendarServer/trunk/calendarserver/profiling.py	2014-07-17 19:55:36 UTC (rev 13774)
@@ -0,0 +1,59 @@
+##
+# Copyright (c) 2014 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.
+##
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+import cProfile as profile
+import pstats
+
+def profile_method():
+    """
+    Decorator to profile a function
+    """
+
+    def wrapper(method):
+        def inner(*args, **kwargs):
+            prof = profile.Profile()
+            prof.enable()
+            result = method(*args, **kwargs)
+            prof.disable()
+
+            stats = pstats.Stats(prof)
+            stats.sort_stats('cumulative').print_stats()
+
+            return result
+        return inner
+    return wrapper
+
+
+def profile_inline_callback():
+    """
+    Decorator to profile an inlineCallback function
+    """
+
+    def wrapper(method):
+        @inlineCallbacks
+        def inner(*args, **kwargs):
+            prof = profile.Profile()
+            prof.enable()
+            result = yield method(*args, **kwargs)
+            prof.disable()
+
+            stats = pstats.Stats(prof)
+            stats.sort_stats('cumulative').print_stats()
+
+            returnValue(result)
+        return inner
+    return wrapper

Modified: CalendarServer/trunk/contrib/performance/sqlusage/requests/invite.py
===================================================================
--- CalendarServer/trunk/contrib/performance/sqlusage/requests/invite.py	2014-07-17 19:04:53 UTC (rev 13773)
+++ CalendarServer/trunk/contrib/performance/sqlusage/requests/invite.py	2014-07-17 19:55:36 UTC (rev 13774)
@@ -45,22 +45,29 @@
 BEGIN:VEVENT
 DTSTAMP:20051222T205953Z
 CREATED:20060101T150000Z
-DTSTART;TZID=US/Eastern:%d0101T100000
+DTSTART;TZID=US/Eastern:{year}0101T100000
 DURATION:PT1H
-SUMMARY:event 1
-UID:invite-ics
+SUMMARY:event {count}
+UID:invite-{count}-ics
 ORGANIZER:mailto:user02 at example.com
 ATTENDEE:mailto:user02 at example.com
-ATTENDEE:mailto:user01 at example.com
+{attendees}
 END:VEVENT
 END:VCALENDAR
 """.replace("\n", "\r\n")
 
+ATTENDEE = "ATTENDEE:mailto:user%02d at example.com"
+
 class InviteTest(HTTPTestBase):
     """
     A PUT operation (invite)
     """
 
+    def __init__(self, label, sessions, logFilePath, logFilePrefix, count):
+        super(InviteTest, self).__init__(label, sessions, logFilePath, logFilePrefix)
+        self.count = count
+
+
     def doRequest(self):
         """
         Execute the actual HTTP request.
@@ -69,7 +76,12 @@
         # Invite as user02
         now = DateTime.getNowUTC()
         href = joinURL(self.sessions[1].calendarHref, "organizer.ics")
-        self.sessions[1].writeData(URL(path=href), ICAL % (now.getYear() + 1,), "text/calendar")
+        attendees = "\r\n".join(["ATTENDEE:mailto:user01 at example.com"] + [ATTENDEE % (ctr + 3,) for ctr in range(self.count - 1)])
+        self.sessions[1].writeData(
+            URL(path=href),
+            ICAL.format(year=now.getYear() + 1, count=self.count, attendees=attendees),
+            "text/calendar",
+        )
 
 
     def cleanup(self):

Modified: CalendarServer/trunk/contrib/performance/sqlusage/sqlusage.py
===================================================================
--- CalendarServer/trunk/contrib/performance/sqlusage/sqlusage.py	2014-07-17 19:04:53 UTC (rev 13773)
+++ CalendarServer/trunk/contrib/performance/sqlusage/sqlusage.py	2014-07-17 19:55:36 UTC (rev 13774)
@@ -123,7 +123,8 @@
             QueryTest("q-1" if self.compact else "query-1", sessions, self.logFilePath, "event", 1),
             QueryTest("q-10" if self.compact else "query-10", sessions, self.logFilePath, "event", 10),
             PutTest("put", sessions, self.logFilePath, "event"),
-            InviteTest("invite", sessions, self.logFilePath, "event"),
+            InviteTest("invite-1", sessions, self.logFilePath, "event", 1),
+            InviteTest("invite-5", sessions, self.logFilePath, "event", 5),
         ]
         self.requestLabels = [request.label for request in requests]
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140717/d4ae4d89/attachment-0001.html>


More information about the calendarserver-changes mailing list