JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / settings / cpu_settings.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import logging
11 import pprint
12
13 import vstf.controller.settings.settings as sets
14 import vstf.common.decorator as deco
15 from vstf.common.input import raw_choice
16
17 LOG = logging.getLogger(__name__)
18
19
20 class CpuSettings(sets.Settings):
21     def __init__(self, path="/etc/vstf/perf/",
22                  filename="sw_perf.cpu-settings",
23                  mode=sets.SETS_SINGLE):
24         super(CpuSettings, self).__init__(path, filename, mode)
25
26     def _register_func(self):
27         super(CpuSettings, self)._register_func()
28         body = set(
29             self._fset['affctl'].keys()
30         )
31         LOG.debug(body)
32         for item in body:
33             item = item.encode()
34             func_name = "set_%s" % item
35             setattr(self, func_name, self._setting_file(func_name, self._mset['affctl'], self._fset['affctl'], item))
36             func_name = "mset_%s" % item
37             setattr(self, func_name, self._setting_memory(func_name, self._mset['affctl'], item))
38
39         LOG.debug(self.__dict__)
40
41     def sinput(self, info=None):
42         if raw_choice("if set cpu affability by affctl"):
43             affctl = self.raw_affctl(info)
44             self.set_affctl(affctl)
45
46         print "%s set finish: " % self._filename
47         print "+++++++++++++++++++++++++++++++++++++++++"
48         pprint.pprint(self.settings, indent=4)
49         print "+++++++++++++++++++++++++++++++++++++++++"
50
51     @deco.vstf_input('policy', types=int)
52     def raw_affctl(self, info):
53         print info
54         print "---------------------------------------"
55         print "Please vstf set cpu affctl params like:"
56         print "    'policy': 2,"
57         print "---------------------------------------"
58
59
60 def unit_test():
61     from vstf.common.log import setup_logging
62     setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-cpu-settings.log", clevel=logging.INFO)
63
64 if __name__ == '__main__':
65     unit_test()
66