98d4b8fb587405cbcb7026d9325d14b38db42655
[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 # Measure compute capacity and scale of a host
13
14 set -e
15
16 # run capacity test
17 run_capacity()
18 {
19     # Number of CPUs
20     CPU=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
21     # Number of physical cores in a single CPU
22     CORE=$(grep 'core id' /proc/cpuinfo | sort -u | wc -l)
23     # Total physical core number
24     CORES=$[$CPU * $CORE]
25     # Number of logical cores
26     THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
27     # Total memory size
28     MEMORY=$(grep 'MemTotal' /proc/meminfo | sort -u)
29     ME=$(echo $MEMORY | awk '/ /{printf "%s %s", $2, $3}')
30     # Cache size per CPU
31     CACHE=$(grep 'cache size' /proc/cpuinfo | sort -u)
32     CA=$(echo $CACHE | awk '/ /{printf "%s", $4}')
33     CACHES=$[$CA * $CPU]
34 }
35
36 # write the result to stdout in json format
37 output_json()
38 {
39     echo -e "{ \
40         \"Cpu_number\":\"$CPU\", \
41         \"Core_number\":\"$CORES\", \
42         \"Thread_number\":\"$THREAD\", \
43         \"Memory_size\": \"$ME\", \
44         \"Cache_size\": \"$CACHES KB\" \
45     }"
46 }
47
48 main()
49 {
50     run_capacity
51
52     output_json
53 }
54
55 main