Skip to content

Commit fc479c4

Browse files
committed
pbench-metadata-log changes to record iterations
The benchmark scripts record their iterations in a temp file. pbench-metadata-log uses that to add an iterations entry to the metadata log. pbench-add-metalog-option is a generic script that is used for that purpose, but it can add an arbitrary option to an arbitrary section of the metadata log. Modify unit tests and add a new one to test this functionality.
1 parent 1d3508a commit fc479c4

File tree

18 files changed

+181
-89
lines changed

18 files changed

+181
-89
lines changed

agent/bench-scripts/test-bin/ssh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
echo "$0 $*" >> $_testlog
44

5-
if [[ "$4" == "netstat" && "$5" == "-tlpn" ]]; then
6-
echo "tcp 0 0 0.0.0.0:21000 0.0.0.0:* LISTEN 5830/uperf"
7-
fi
8-
95
while true ;do
106
case $1 in
117
-o)
@@ -21,6 +17,14 @@ while true ;do
2117
done
2218
remote=$1
2319

20+
if [[ "$2" == "netstat" && "$3" == "-tlnp" ]]; then
21+
echo "tcp 0 0 0.0.0.0:21000 0.0.0.0:* LISTEN 5830/uperf"
22+
fi
23+
24+
if [[ "$2" == "hostname" && "$3" == "-s" ]]; then
25+
echo "$remote"
26+
fi
27+
2428
if [[ "$remote" == "fubar" ]] ;then
2529
exit 255
2630
else

agent/util-scripts/gold/pbench-metadata-log/test-01.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ config:
1515
date: 1900-01-01_00:00:00
1616
rpm-version:
1717

18-
[tools]
19-
hosts: testhost
20-
21-
[tools/testhost]
22-
mpstat: --interval="10"
23-
2418
[run]
2519
controller: testhost.example.com
2620
--- pbench tree state

agent/util-scripts/gold/pbench-metadata-log/test-02.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ rpm-version:
3939

4040
[tools]
4141
hosts: testhost
42+
group: default
4243

4344
[tools/testhost]
4445
iostat: --interval=3

agent/util-scripts/gold/pbench-metadata-log/test-03.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ rpm-version:
4848

4949
[tools]
5050
hosts: testhost dhcp31-174 perf104
51+
group: default
5152

5253
[tools/testhost]
5354
iostat: --interval=3
@@ -74,6 +75,8 @@ grep: /var/tmp/pbench-test-utils/pbench/pbench.log: No such file or directory
7475
--- pbench.log file contents
7576
+++ test-execution.log file contents
7677
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/yum list installed pbench-agent
78+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -n dhcp31-174 hostname -s
79+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -n perf104 hostname -s
7780
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no dhcp31-174 /bin/ls /var/tmp/pbench-test-utils/pbench/tools-default
7881
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no perf104 /bin/ls /var/tmp/pbench-test-utils/pbench/tools-default
7982
--- test-execution.log file contents

agent/util-scripts/gold/pbench-metadata-log/test-04.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ rpm-version:
4343

4444
[tools]
4545
hosts: testhost
46+
group: default
4647

4748
[tools/testhost]
4849
iostat: --interval=3
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
+++ Running test-21 pbench-metadata-log
2+
--- Finished test-21 pbench-metadata-log (status=0}
3+
+++ pbench tree state
4+
/var/tmp/pbench-test-utils/pbench
5+
/var/tmp/pbench-test-utils/pbench/metadata.log
6+
/var/tmp/pbench-test-utils/pbench/tmp
7+
/var/tmp/pbench-test-utils/pbench/tmp/pbench.iterations
8+
/var/tmp/pbench-test-utils/pbench/tools-default
9+
/var/tmp/pbench-test-utils/pbench/tools-default/iostat
10+
/var/tmp/pbench-test-utils/pbench/tools-default/mpstat
11+
/var/tmp/pbench-test-utils/pbench/tools-default/perf
12+
/var/tmp/pbench-test-utils/pbench/tools-default/pidstat
13+
/var/tmp/pbench-test-utils/pbench/tools-default/proc-interrupts
14+
/var/tmp/pbench-test-utils/pbench/tools-default/proc-vmstat
15+
/var/tmp/pbench-test-utils/pbench/tools-default/sar
16+
/var/tmp/pbench-test-utils/pbench/tools-default/turbostat
17+
/var/tmp/pbench-test-utils/pbench/tools-default/iostat:
18+
--interval=3
19+
/var/tmp/pbench-test-utils/pbench/tools-default/mpstat:
20+
--interval=3
21+
/var/tmp/pbench-test-utils/pbench/tools-default/perf:
22+
--record-opts=-a -freq=100
23+
--record-opts=--call-graph
24+
--record-opts=--event=branch-misses
25+
--record-opts=--event=cache-misses
26+
--record-opts=--event=instructions
27+
/var/tmp/pbench-test-utils/pbench/tools-default/pidstat:
28+
--interval=3
29+
/var/tmp/pbench-test-utils/pbench/tools-default/proc-interrupts:
30+
--interval=3
31+
/var/tmp/pbench-test-utils/pbench/tools-default/proc-vmstat:
32+
--interval=3
33+
/var/tmp/pbench-test-utils/pbench/tools-default/sar:
34+
--interval=3
35+
/var/tmp/pbench-test-utils/pbench/tools-default/turbostat:
36+
--interval=3
37+
/var/tmp/pbench-test-utils/pbench/tmp/pbench.iterations:
38+
iter1
39+
iter2
40+
iter3
41+
--- pbench tree state
42+
+++ metadata.log file contents
43+
/var/tmp/pbench-test-utils/pbench/metadata.log:[pbench]
44+
/var/tmp/pbench-test-utils/pbench/metadata.log:name = pbench
45+
/var/tmp/pbench-test-utils/pbench/metadata.log:script =
46+
/var/tmp/pbench-test-utils/pbench/metadata.log:config =
47+
/var/tmp/pbench-test-utils/pbench/metadata.log:date = 1900-01-01_00:00:00
48+
/var/tmp/pbench-test-utils/pbench/metadata.log:rpm-version =
49+
/var/tmp/pbench-test-utils/pbench/metadata.log:iterations = iter1, iter2, iter3
50+
/var/tmp/pbench-test-utils/pbench/metadata.log:
51+
/var/tmp/pbench-test-utils/pbench/metadata.log:[tools]
52+
/var/tmp/pbench-test-utils/pbench/metadata.log:hosts = testhost
53+
/var/tmp/pbench-test-utils/pbench/metadata.log:group = default
54+
/var/tmp/pbench-test-utils/pbench/metadata.log:
55+
/var/tmp/pbench-test-utils/pbench/metadata.log:[tools/testhost]
56+
/var/tmp/pbench-test-utils/pbench/metadata.log:iostat = --interval=3
57+
/var/tmp/pbench-test-utils/pbench/metadata.log:mpstat = --interval=3
58+
/var/tmp/pbench-test-utils/pbench/metadata.log:perf = --record-opts=-a -freq=100 --record-opts=--call-graph --record-opts=--event=branch-misses --record-opts=--event=cache-misses --record-opts=--event=instructions
59+
/var/tmp/pbench-test-utils/pbench/metadata.log:pidstat = --interval=3
60+
/var/tmp/pbench-test-utils/pbench/metadata.log:proc-interrupts = --interval=3
61+
/var/tmp/pbench-test-utils/pbench/metadata.log:proc-vmstat = --interval=3
62+
/var/tmp/pbench-test-utils/pbench/metadata.log:sar = --interval=3
63+
/var/tmp/pbench-test-utils/pbench/metadata.log:turbostat = --interval=3
64+
/var/tmp/pbench-test-utils/pbench/metadata.log:
65+
/var/tmp/pbench-test-utils/pbench/metadata.log:[run]
66+
/var/tmp/pbench-test-utils/pbench/metadata.log:controller = testhost.example.com
67+
/var/tmp/pbench-test-utils/pbench/metadata.log:start_run = 1900-01-01T00:00:00.000000
68+
/var/tmp/pbench-test-utils/pbench/metadata.log:end_run = 1900-01-01T00:00:00.000000
69+
/var/tmp/pbench-test-utils/pbench/metadata.log:
70+
--- metadata.log file contents
71+
+++ pbench.log file contents
72+
grep: /var/tmp/pbench-test-utils/pbench/pbench.log: No such file or directory
73+
--- pbench.log file contents
74+
+++ test-execution.log file contents
75+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/yum list installed pbench-agent
76+
--- test-execution.log file contents
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env python2
2+
3+
# Usage: pbench-add-metalog-option <options.file> <metadata log file> <option>
4+
5+
# Add an option to the [pbench] section of the metadata.log file.
6+
# E.g. using an 'iterations' arg for the option
7+
#
8+
# iterations: 1-iter, 2-iter, 3-iter
9+
#
10+
# where the iterations are in the <iterations.file>, one iteration per line.
11+
12+
import sys
13+
try:
14+
# python3
15+
from configparser import SafeConfigParser
16+
except:
17+
from ConfigParser import SafeConfigParser
18+
19+
def main(ifile, lfile, section):
20+
config = SafeConfigParser()
21+
config.read(lfile)
22+
# python3
23+
# config['pbench']['iterations'] = ', '.join(open(ifile).read().split())
24+
config.set('pbench', section, ', '.join(open(ifile).read().split()))
25+
config.write(open(lfile, "w"))
26+
27+
if __name__ == '__main__':
28+
ifile = sys.argv[1]
29+
lfile = sys.argv[2]
30+
section = sys.argv[3]
31+
status = main(ifile, lfile, section)
32+
sys.exit(status)
33+

agent/util-scripts/pbench-metadata-log

Lines changed: 37 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -62,76 +62,28 @@ function usage {
6262
}
6363

6464
function metadata_log_tools {
65-
log=$1
65+
local log=$1
6666

67-
if [ -d $pbench_run/tools-$group ] ;then
68-
metadata_log_tools_dir $log
69-
else
70-
metadata_log_tools_file $log
71-
fi
72-
}
73-
74-
function metadata_log_tools_file {
75-
# This is provided for backwards compatibility.
76-
# v0.35 introduced the tools-<group> directory: if that
77-
# directory exists, we assume that it is authoritative.
78-
# If it does not, we fall back to the tools.<group> file.
79-
80-
# Get the remotes from the local tools.$group file
81-
# then get the remote tools.$group files for each remote
82-
83-
remotes="$(grep @ $pbench_run/tools.$group | sed 's/.*@//
67+
# get the remotes from the local tools-$group directory
68+
# then get the remote tools-$group dirs for each remote
69+
local remotes="$(/bin/ls $pbench_run/tools-$group/ 2> /dev/null | grep @ | sed 's/.*@//
8470
s/:[^:]*$//' | tr '\n' ' ')"
85-
86-
# check if the local tools.$group file includes any local tools
87-
local=0
88-
if grep -v @ $pbench_run/tools.$group > /dev/null 2>&1 ;then
89-
local=1
90-
fi
9171

92-
# if yes ...
93-
if [ $local == 1 ] ;then
94-
cat >> $log <<EOF
95-
[tools]
96-
hosts: $hostname $remotes
97-
98-
[tools/$hostname]
99-
$(cat $pbench_run/tools.$group)
100-
101-
EOF
102-
else
103-
# just remotes
104-
if [ ! -z "$remotes" ] ;then
105-
cat >> $log <<EOF
106-
[tools]
107-
hosts: $remotes
108-
109-
EOF
110-
fi
111-
fi
112-
72+
# the remotes may have different names than what the controller uses,
73+
# so go ask them - the names of the remotes in the metadata log have to
74+
# agree with the names of the remotes used when postprocessing the tool
75+
# results, otherwise the indexing will fail.
76+
local rems=""
11377
for remote in $remotes ;do
114-
cat >> $log <<EOF
115-
[tools/$remote]
116-
$(ssh $ssh_opts $remote cat $pbench_run/tools.$group)
117-
118-
EOF
78+
# if the ssh fails, just leave the name alone
79+
rem=$(ssh $ssh_opts -n $remote hostname -s 2>/dev/null || echo $remote)
80+
rems="$rems $rem"
11981
done
120-
}
121-
122-
function metadata_log_tools_dir {
123-
# we have a tools-<group> dir.
124-
125-
log=$1
126-
# get the remotes from the local tools-$group directory
127-
# then get the remote tools-$group dirs for each remote
128-
129-
remotes="$(ls $pbench_run/tools-$group/ | grep @ | sed 's/.*@//
130-
s/:[^:]*$//' | tr '\n' ' ')"
82+
remotes=$rems
13183

13284
# check if the local tools-$group directory includes any local tools
13385
local=0
134-
if /bin/ls $pbench_run/tools-$group | grep -q -v "^remote@" ;then
86+
if /bin/ls $pbench_run/tools-$group 2> /dev/null | grep -q -v "^remote@" ;then
13587
local=1
13688
fi
13789

@@ -140,10 +92,11 @@ s/:[^:]*$//' | tr '\n' ' ')"
14092
cat >> $log <<EOF
14193
[tools]
14294
hosts: $hostname $remotes
95+
group: $group
14396
14497
[tools/$hostname]
14598
EOF
146-
for tool in $(/bin/ls $pbench_run/tools-$group) ;do
99+
for tool in $(/bin/ls $pbench_run/tools-$group 2> /dev/null) ;do
147100
# add the options with a space in front, effectively making them continuation
148101
# lines as far the python config module is concerned.
149102
echo $tool: $(cat $pbench_run/tools-$group/$tool | sed 's/^/ /')
@@ -155,6 +108,7 @@ EOF
155108
cat >> $log <<EOF
156109
[tools]
157110
hosts: $remotes
111+
group: $group
158112
159113
EOF
160114
fi
@@ -172,12 +126,13 @@ EOF
172126
}
173127

174128
function metadata_log_start {
175-
dir=$1
176-
ts=$2
177-
log=$dir/metadata.log
129+
local dir=$1
130+
local group=$2
131+
local ts=$3
132+
local log=$dir/metadata.log
178133

179134
if [ -z "$ts" ] ;then
180-
ts=$(date --utc '+%F_%H:%M:%S.%N')
135+
ts=$(timestamp)
181136
fi
182137
cat > $log <<EOF
183138
[pbench]
@@ -188,7 +143,7 @@ date: $date
188143
rpm-version: $(yum list installed pbench-agent 2>/dev/null | tail -n 1 | awk '{print $2}')
189144
190145
EOF
191-
metadata_log_tools $log
146+
metadata_log_tools $log $group
192147
cat >> $log <<EOF
193148
[run]
194149
controller: $full_hostname
@@ -197,21 +152,22 @@ EOF
197152
}
198153

199154
function metadata_log_end {
200-
dir=$1
201-
int=$2
202-
log=$dir/metadata.log
155+
local dir=$1
156+
local group=$2
157+
local int=$3
158+
local log=$dir/metadata.log
203159

204160
if [ ! -f $log ] ;then
205161
# Somehow, metadata_log_start was never called !?!?
206162
# Call it explicitly.
207163
# Manufacture a start_run timestamp and pass it
208164
# explicitly. The manufactured stamp is the date that
209165
# the base file calculates (now in UTC).
210-
start_ts=$date
211-
metadata_log_start $dir $start_ts
166+
local start_ts=$(timestamp)
167+
metadata_log_start $dir $group $start_ts
212168
fi
213169
if ! grep -q end_run $log ;then
214-
echo "end_run: $(date --utc '+%F_%H:%M:%S.%N')" >> $log
170+
echo "end_run: $(timestamp)" >> $log
215171
fi
216172
if [ "$int" == "int" ] ;then
217173
echo "run_interrupted: true" >> $log
@@ -221,13 +177,17 @@ function metadata_log_end {
221177
mkdir -p $dir
222178
case $1 in
223179
beg)
224-
metadata_log_start $dir
180+
metadata_log_start $dir $group
225181
;;
226182
end)
227-
metadata_log_end $dir
183+
metadata_log_end $dir $group
184+
name=$(basename $dir)
185+
if [ -f $pbench_tmp/$name.iterations ] ;then
186+
pbench-add-metalog-option $pbench_tmp/$name.iterations $dir/metadata.log iterations
187+
fi
228188
;;
229189
int)
230-
metadata_log_end $dir int
190+
metadata_log_end $dir $group int
231191
;;
232192
*)
233193
usage
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
iter1
2+
iter2
3+
iter3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--interval=3

0 commit comments

Comments
 (0)