blob: d49638fe319afa6b7d64f0782c79e4712b0a9afd (
plain)
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
|
#!/bin/bash
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
# compute capacity and scale of a host
set -e
# run capacity test
run_capacity()
{
#parameter used for HT(Hyper-Thread) check
HT_Para=2
# Number of CPUs
CPU=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
# Number of physical cores in a single CPU
CORE=$(grep 'core id' /proc/cpuinfo | sort -u | wc -l)
# Total physical core number
CORES=$[$CPU * $CORE]
# Number of logical cores
THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
# Total memory size
MEMORY=$(grep 'MemTotal' /proc/meminfo | sort -u | awk '{print $2}')
# Cache size per CPU
CACHE=$(grep 'cache size' /proc/cpuinfo | sort -u | awk '{print $4}')
CACHES=$[$CACHE * $CPU]
HT_Value=$[$HT_Para * $CORES]
if [ $HT_Value -eq $THREAD ]; then
HT_OPEN=1
else
HT_OPEN=0
fi
}
# write the result to stdout in json format
output_json()
{
echo -e "{ \
\"Cpu_number\":\"$CPU\", \
\"Core_number\":\"$CORES\", \
\"Thread_number\":\"$THREAD\", \
\"Memory_size\": \"$MEMORY\", \
\"Cache_size\": \"$CACHES\", \
\"HT_Open\": \"$HT_OPEN\" \
}"
}
main()
{
run_capacity
output_json
}
main
|