Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / 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
22     def __init__(self, path="/etc/vstf/perf/",
23                  filename="sw_perf.cpu-settings",
24                  mode=sets.SETS_SINGLE):
25         super(CpuSettings, self).__init__(path, filename, mode)
26
27     def _register_func(self):
28         super(CpuSettings, self)._register_func()
29         body = set(
30             self._fset['affctl'].keys()
31         )
32         LOG.debug(body)
33         for item in body:
34             item = item.encode()
35             func_name = "set_%s" % item
36             setattr(
37                 self,
38                 func_name,
39                 self._setting_file(
40                     func_name,
41                     self._mset['affctl'],
42                     self._fset['affctl'],
43                     item))
44             func_name = "mset_%s" % item
45             setattr(
46                 self,
47                 func_name,
48                 self._setting_memory(
49                     func_name,
50                     self._mset['affctl'],
51                     item))
52
53         LOG.debug(self.__dict__)
54
55     def sinput(self, info=None):
56         if raw_choice("if set cpu affability by affctl"):
57             affctl = self.raw_affctl(info)
58             self.set_affctl(affctl)
59
60         print "%s set finish: " % self._filename
61         print "+++++++++++++++++++++++++++++++++++++++++"
62         pprint.pprint(self.settings, indent=4)
63         print "+++++++++++++++++++++++++++++++++++++++++"
64
65     @deco.vstf_input('policy', types=int)
66     def raw_affctl(self, info):
67         print info
68         print "---------------------------------------"
69         print "Please vstf set cpu affctl params like:"
70         print "    'policy': 2,"
71         print "---------------------------------------"
72
73
74 def unit_test():
75     from vstf.common.log import setup_logging
76     setup_logging(
77         level=logging.DEBUG,
78         log_file="/var/log/vstf/vstf-cpu-settings.log",
79         clevel=logging.INFO)
80
81 if __name__ == '__main__':
82     unit_test()