1 # Copyright (C) 2013-2024 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.
32 def __init__(self
, append
):
33 """Constructor of Reporter.
35 attribute append is used to determine whether to append or
40 def report(self
, *args
):
41 raise NotImplementedError("Abstract Method:report.")
44 """Invoked when reporting is started."""
45 raise NotImplementedError("Abstract Method:start.")
48 """Invoked when reporting is done.
50 It must be overridden to do some cleanups, such as closing file
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
))
64 def report(self
, test_name
, measurement_name
, data_points
):
65 if len(data_points
) == 0:
67 "%s %s *no data recorded*\n" % (test_name
, measurement_name
)
70 average
= sum(data_points
) / len(data_points
)
71 data_min
= min(data_points
)
72 data_max
= max(data_points
)
73 self
.txt_sum
.write("%s %s %s\n" % (test_name
, measurement_name
, average
))
75 "%s %s %s, min %s, max %s, data %s\n"
76 % (test_name
, measurement_name
, average
, data_min
, data_max
, data_points
)
80 mode
= "a+" if self
.append
else "w"
81 self
.txt_sum
= open(SUM_FILE_NAME
, mode
)
82 self
.txt_log
= open(LOG_FILE_NAME
, mode
)