ignore invalid DOF provider sections
[binutils-gdb.git] / gdb / testsuite / gdb.perf / lib / perftest / reporter.py
blob646051e22529ae0cb390ca067207006097cd6d0a
1 # Copyright (C) 2013-2015 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Text reports are written here.
17 # This is the perftest counterpart to gdb.sum.
18 SUM_FILE_NAME = "perftest.sum"
20 # Raw data that went into the report is written here.
21 # This is the perftest counterpart to gdb.log.
22 LOG_FILE_NAME = "perftest.log"
25 class Reporter(object):
26 """Base class of reporter to report test results in a certain format.
28 Subclass, which is specific to a report format, should overwrite
29 methods report, start and end.
30 """
32 def __init__(self, append):
33 """Constructor of Reporter.
35 attribute append is used to determine whether to append or
36 overwrite log file.
37 """
38 self.append = append
40 def report(self, *args):
41 raise NotImplementedError("Abstract Method:report.")
43 def start(self):
44 """Invoked when reporting is started."""
45 raise NotImplementedError("Abstract Method:start.")
47 def end(self):
48 """Invoked when reporting is done.
50 It must be overridden to do some cleanups, such as closing file
51 descriptors.
52 """
53 raise NotImplementedError("Abstract Method:end.")
56 class TextReporter(Reporter):
57 """Report results in a plain text file 'perftest.log'."""
59 def __init__(self, append):
60 super (TextReporter, self).__init__(Reporter(append))
61 self.txt_sum = None
62 self.txt_log = None
64 def report(self, test_name, measurement_name, data_points):
65 if len(data_points) == 0:
66 self.txt_sum.write("%s %s *no data recorded*\n" % (
67 test_name, measurement_name))
68 return
69 average = sum(data_points) / len(data_points)
70 data_min = min(data_points)
71 data_max = max(data_points)
72 self.txt_sum.write("%s %s %s\n" % (
73 test_name, measurement_name, average))
74 self.txt_log.write("%s %s %s, min %s, max %s, data %s\n" % (
75 test_name, measurement_name, average, data_min, data_max,
76 data_points))
78 def start(self):
79 mode = "a+" if self.append else "w"
80 self.txt_sum = open (SUM_FILE_NAME, mode);
81 self.txt_log = open (LOG_FILE_NAME, mode);
83 def end(self):
84 self.txt_sum.close ()
85 self.txt_log.close ()