]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.perf/lib/perftest/reporter.py
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.perf / lib / perftest / reporter.py
1 # Copyright (C) 2013-2015 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 class Reporter(object):
17 """Base class of reporter to report test results in a certain format.
18
19 Subclass, which is specific to a report format, should overwrite
20 methods report, start and end.
21 """
22
23 def __init__(self, append):
24 """Constructor of Reporter.
25
26 attribute append is used to determine whether to append or
27 overwrite log file.
28 """
29 self.append = append
30
31 def report(self, *args):
32 raise NotImplementedError("Abstract Method:report.")
33
34 def start(self):
35 """Invoked when reporting is started."""
36 raise NotImplementedError("Abstract Method:start.")
37
38 def end(self):
39 """Invoked when reporting is done.
40
41 It must be overridden to do some cleanups, such as closing file
42 descriptors.
43 """
44 raise NotImplementedError("Abstract Method:end.")
45
46 class TextReporter(Reporter):
47 """Report results in a plain text file 'perftest.log'."""
48
49 def __init__(self, append):
50 super (TextReporter, self).__init__(Reporter(append))
51 self.txt_log = None
52
53 def report(self, *args):
54 self.txt_log.write(' '.join(str(arg) for arg in args))
55 self.txt_log.write('\n')
56
57 def start(self):
58 if self.append:
59 self.txt_log = open ("perftest.log", 'a+');
60 else:
61 self.txt_log = open ("perftest.log", 'w');
62
63 def end(self):
64 self.txt_log.close ()