cengal.hardware.info.cpu.versions.v_0.cpu

 1#!/usr/bin/env python
 2# coding=utf-8
 3
 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
 5# 
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9# 
10#     http://www.apache.org/licenses/LICENSE-2.0
11# 
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import cpuinfo
19
20"""
21Module Docstring
22Docstrings: http://www.python.org/dev/peps/pep-0257/
23"""
24
25__author__ = "ButenkoMS <gtalk@butenkoms.space>"
26__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
27__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
28__license__ = "Apache License, Version 2.0"
29__version__ = "4.4.1"
30__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
31__email__ = "gtalk@butenkoms.space"
32# __status__ = "Prototype"
33__status__ = "Development"
34# __status__ = "Production"
35
36
37def get_cpu_info()->dict:
38    return cpuinfo.get_cpu_info()
39
40
41def get_l2_cache_size()->int:
42    size_text = cpuinfo.get_cpu_info()['l2_cache_size']
43    size_text_list = size_text.split()
44    size_text_list_size = len(size_text_list)
45    size_text_number = None
46    size_text_dimension = None
47    if 0 == size_text_list_size:
48        return 0
49    elif 1 == size_text_list_size:
50        return int(size_text_list)
51    elif 2 == size_text_list_size:
52        size_text_number, size_text_dimension = size_text_list
53    else:
54        return 0
55    size_text_number = int(size_text_number)
56    size_text_dimension = size_text_dimension.lower()
57    factor = 1
58    if 'kb' == size_text_dimension:
59        factor = 1024
60    elif 'mb' == size_text_dimension:
61        factor = 1024**2
62    elif 'gb' == size_text_dimension:
63        factor = 1024**3  # :)
64    return size_text_number * factor
65
66
67def l2_cache_per_core()->int:
68    core_count = cpuinfo.get_cpu_info()['count']
69    if core_count:
70        return int(get_l2_cache_size() / core_count)
71    else:
72        return 0
def get_cpu_info() -> dict:
38def get_cpu_info()->dict:
39    return cpuinfo.get_cpu_info()
def get_l2_cache_size() -> int:
42def get_l2_cache_size()->int:
43    size_text = cpuinfo.get_cpu_info()['l2_cache_size']
44    size_text_list = size_text.split()
45    size_text_list_size = len(size_text_list)
46    size_text_number = None
47    size_text_dimension = None
48    if 0 == size_text_list_size:
49        return 0
50    elif 1 == size_text_list_size:
51        return int(size_text_list)
52    elif 2 == size_text_list_size:
53        size_text_number, size_text_dimension = size_text_list
54    else:
55        return 0
56    size_text_number = int(size_text_number)
57    size_text_dimension = size_text_dimension.lower()
58    factor = 1
59    if 'kb' == size_text_dimension:
60        factor = 1024
61    elif 'mb' == size_text_dimension:
62        factor = 1024**2
63    elif 'gb' == size_text_dimension:
64        factor = 1024**3  # :)
65    return size_text_number * factor
def l2_cache_per_core() -> int:
68def l2_cache_per_core()->int:
69    core_count = cpuinfo.get_cpu_info()['count']
70    if core_count:
71        return int(get_l2_cache_size() / core_count)
72    else:
73        return 0