~ubuntu-branches/ubuntu/utopic/calendarserver/utopic

« back to all changes in this revision

Viewing changes to contrib/performance/loadtest/logger.py

  • Committer: Package Import Robot
  • Author(s): Rahul Amaram
  • Date: 2012-05-29 18:12:12 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120529181212-mxjdfncopy6vou0f
Tags: 3.2+dfsg-1
* New upstream release
* Moved from using cdbs to dh sequencer
* Modified calenderserver init.d script based on /etc/init.d/skeleton script
* Removed ldapdirectory.patch as the OpenLDAP directory service has been 
  merged upstream
* Moved package to section "net" as calendarserver is more service than 
  library (Closes: #665859)
* Changed Architecture of calendarserver package to any as the package
  now includes compiled architecture dependent Python extensions
* Unowned files are no longer left on the system upon purging
  (Closes: #668731)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##
 
2
# Copyright (c) 2011 Apple Inc. All rights reserved.
 
3
#
 
4
# Licensed under the Apache License, Version 2.0 (the "License");
 
5
# you may not use this file except in compliance with the License.
 
6
# You may obtain a copy of the License at
 
7
#
 
8
# http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
# Unless required by applicable law or agreed to in writing, software
 
11
# distributed under the License is distributed on an "AS IS" BASIS,
 
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
#
 
16
##
 
17
 
 
18
from contrib.performance.stats import mean, median
 
19
 
 
20
class SummarizingMixin(object):
 
21
    def printHeader(self, fields):
 
22
        """
 
23
        Print a header for the summarization data which will be reported.
 
24
 
 
25
        @param fields: A C{list} of two-tuples.  Each tuple describes one
 
26
            column in the summary.  The first element gives a label to appear
 
27
            at the top of the column.  The second element gives the width of
 
28
            the column.
 
29
        """
 
30
        format = []
 
31
        labels = []
 
32
        for (label, width) in fields:
 
33
            format.append('%%%ds' % (width,))
 
34
            labels.append(label)
 
35
        print ' '.join(format) % tuple(labels)
 
36
 
 
37
 
 
38
    def _summarizeData(self, operation, data):
 
39
        failed = 0
 
40
        threesec = 0
 
41
        durations = []
 
42
        for (success, duration) in data:
 
43
            if not success:
 
44
                failed += 1
 
45
            if duration > 3:
 
46
                threesec += 1
 
47
            durations.append(duration)
 
48
 
 
49
        return operation, len(data), failed, threesec, mean(durations), median(durations)
 
50
 
 
51
 
 
52
    def _printRow(self, formats, values):
 
53
        format = ' '.join(formats)
 
54
        print format % values
 
55
 
 
56
 
 
57
    def printData(self, formats, perOperationTimes):
 
58
        """
 
59
        Print one or more rows of data with the given formatting.
 
60
 
 
61
        @param formats: A C{list} of C{str} giving formats into which each
 
62
            data field will be interpolated.
 
63
 
 
64
        @param perOperationTimes: A C{list} of all of the data to summarize.
 
65
            Each element is a two-tuple of whether the operation succeeded
 
66
            (C{True} if so, C{False} if not) and how long the operation took.
 
67
        """
 
68
        for method, data in perOperationTimes:
 
69
            self._printRow(formats, self._summarizeData(method, data))