2
# Copyright (c) 2011 Apple Inc. All rights reserved.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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.
18
from contrib.performance.stats import mean, median
20
class SummarizingMixin(object):
21
def printHeader(self, fields):
23
Print a header for the summarization data which will be reported.
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
32
for (label, width) in fields:
33
format.append('%%%ds' % (width,))
35
print ' '.join(format) % tuple(labels)
38
def _summarizeData(self, operation, data):
42
for (success, duration) in data:
47
durations.append(duration)
49
return operation, len(data), failed, threesec, mean(durations), median(durations)
52
def _printRow(self, formats, values):
53
format = ' '.join(formats)
57
def printData(self, formats, perOperationTimes):
59
Print one or more rows of data with the given formatting.
61
@param formats: A C{list} of C{str} giving formats into which each
62
data field will be interpolated.
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.
68
for method, data in perOperationTimes:
69
self._printRow(formats, self._summarizeData(method, data))