Merge "framework: Add reworked framework to repo"
[vswitchperf.git] / core / collector_controller.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 """CollectorController class
16 """
17 from core.results.results import IResults
18
19 class CollectorController(IResults):
20     """Class which defines a collector controller object.
21
22     Used to set-up and control a collector provider.
23     """
24
25     def __init__(self, collector_class):
26         """Sets up the prerequisites for the Collector.
27
28         :param collector_class: the Collector class to be used.
29         """
30         self._collector = collector_class()
31         self._results = []
32
33     def log_mem_stats(self):
34         """Log memory stats.
35         """
36         self._results.append(self._collector.log_mem_stats())
37
38     def log_cpu_stats(self):
39         """Log CPU stats.
40         """
41         self._results.append(self._collector.log_cpu_stats())
42
43     def get_results(self):
44         """Return collected CPU and memory stats.
45
46         Implements IResults i/f, see IResults for details.
47         """
48         return self._results
49
50     def print_results(self):
51         """Prints collected CPU and memory stats.
52
53         Implements IResults i/f, see IResults for details.
54         """
55         print(self._results)