Merge "KVMFORNFV: Suppress tracing with breaktrace option "
[yardstick.git] / yardstick / benchmark / scenarios / compute / computecapacity.bash
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # compute capacity and scale of a host
13
14 set -e
15
16 # run capacity test
17 run_capacity()
18 {
19     #parameter used for HT(Hyper-Thread) check
20     HT_Para=2
21     # Number of CPUs
22     CPU=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
23     # Number of physical cores in a single CPU
24     CORE=$(grep 'core id' /proc/cpuinfo | sort -u | wc -l)
25     # Total physical core number
26     CORES=$[$CPU * $CORE]
27     # Number of logical cores
28     THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
29     # Total memory size
30     MEMORY=$(grep 'MemTotal' /proc/meminfo | sort -u)
31     ME=$(echo $MEMORY | awk '/ /{printf "%s %s", $2, $3}')
32     # Cache size per CPU
33     CACHE=$(grep 'cache size' /proc/cpuinfo | sort -u)
34     CA=$(echo $CACHE | awk '/ /{printf "%s", $4}')
35     CACHES=$[$CA * $CPU]
36     HT_Value=$[$HT_Para * $CORES]
37     if [ $HT_Value -eq $THREAD ]; then
38         HT_OPEN=1
39     else
40         HT_OPEN=0
41     fi
42 }
43
44 # write the result to stdout in json format
45 output_json()
46 {
47     echo -e "{ \
48         \"Cpu_number\":\"$CPU\", \
49         \"Core_number\":\"$CORES\", \
50         \"Thread_number\":\"$THREAD\", \
51         \"Memory_size\": \"$ME\", \
52         \"Cache_size\": \"$CACHES KB\", \
53         \"HT_Open\": \"$HT_OPEN\" \
54     }"
55 }
56
57 main()
58 {
59     run_capacity
60
61     output_json
62 }
63
64 main