Merge "Tools: Improve Stability."
[vswitchperf.git] / collector / collector.py
1 # Copyright 2015 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """Abstract "system metrics logger" model.
16 """
17
18 class ICollector(object):
19     """This is an abstract class for system metrics loggers.
20     """
21
22     def start(self):
23         """Starts data collection. This method must be non-blocking.
24         It means, that collector must be executed as a background process.
25
26         Where implemented, this function should raise an exception on
27         failure.
28         """
29         raise NotImplementedError('Please call an implementation.')
30
31     def stop(self):
32         """Stops data collection.
33
34         Where implemented, this function should raise an exception on
35         failure.
36         """
37         raise NotImplementedError('Please call an implementation.')
38
39     def get_results(self):
40         """Returns collected results.
41
42         Where implemented, this function should raise an exception on
43         failure.
44         """
45         raise NotImplementedError('Please call an implementation.')
46
47     def print_results(self):
48         """Logs collected results.
49
50         Where implemented, this function should raise an exception on
51         failure.
52         """
53         raise NotImplementedError('Please call an implementation.')
54
55     def __enter__(self):
56         """Starts up collection of statistics
57         """
58         self.start()
59
60     def __exit__(self, type_, value, traceback):
61         """Stops collection of statistics
62         """
63         self.stop()