-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcpu.sh
More file actions
122 lines (110 loc) · 2.42 KB
/
cpu.sh
File metadata and controls
122 lines (110 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Copyright 2018 Juliano Santos [SHAMAN]
#
# This file is part of bashsrc.
#
# bashsrc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# bashsrc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bashsrc. If not, see <http://www.gnu.org/licenses/>.
[ -v __CPU_SH__ ] && return 0
readonly __CPU_SH__=1
source builtin.sh
# .FUNCTION cpu.getinfo <cpuinfo[map]> -> [bool]
#
# Obtem informações do processador,
#
# == EXEMPLO ==
#
# source cpu.sh
#
# # Inicializa o map
# declare -A info=()
#
# # Obtendo informações.
# cpu.getinfo info
#
# # Listando informações.
# echo ${info[processor[0]]}
# echo ${info[model_name[0]]}
# echo ${info[cpu_mhz[0]]}
# echo ---
# echo ${info[processor[1]]}
# echo ${info[model_name[1]]}
# echo ${info[cpu_mhz[1]]}
#
# == SAÍDA ==
#
# 0
# Intel(R) Core(TM) i5-3330 CPU @ 3.00GHz
# 1961.110
# ---
# 1
# Intel(R) Core(TM) i5-3330 CPU @ 3.00GHz
# 1875.432
#
function cpu.getinfo()
{
getopt.parse 1 "cpuinfo:map:$1" "${@:2}"
local __flag__ __value__ __info__
local __i__=-1
local -n __ref__=$1
# Inicializar.
__ref__=() || return 1
while IFS=':' read __flag__ __value__; do
__flag__=${__flag__//@($'\t')}
__flag__=${__flag__// /_}
__flag__=${__flag__,,}
__value__=${__value__##+( )}
case $__flag__ in
processor) ((++__i__));;
'') continue;;
esac
# Atribui o valor da chave.
__ref__[$__flag__[$__i__]]=$__value__
done < /proc/cpuinfo || error.error "'/proc/cpuinfo' não foi possível ler o arquivo"
return $?
}
# .MAP cpuinfo
#
# Chaves:
#
# address_sizes[N]
# apicid[N]
# bogomips[N]
# bugs[N]
# cache_alignment[N]
# cache_size[N]
# clflush_size[N]
# core_id[N]
# cpu_cores[N]
# cpu_family[N]
# cpuid_level[N]
# cpu_mhz[N]
# flags[N]
# fpu[N]
# fpu_exception[N
# initial_apicid[N]
# microcode[N]
# model[N]
# model_name[N]
# physical_id[N]
# power_management[N]
# processor[N]
# siblings[N]
# stepping[N]
# vendor_id[N]
# wp[N]
#
# > 'N' é o índice do elemento.
#
readonly -f cpu.getinfo
# /* _CPU_SH__ */