Skip to content

Commit 02431ee

Browse files
author
bcbrock
committed
Busywork updates 9/22/2016
Several changes are required due to the removal of the /devops route from the REST API. The major change here is the conversion of the Tcl ::fabric package to use the /chaincode route instead of /devops. Several other enhancements and bug fixes are also inclued: 1) Fixes FAB-139 (Timer overflow) 2) Fixes FAB-414 (Additional timestamp for all TX committed) Tcl support for reading /proc/<PID>/stat was added. This allows more statistics to be printed after the Busywork run (e.g., user + system time and CPU utilization). /proc/<PID>/stat fields can also be accessed for the peers now by way of the 'busy' command, which was also enhanced with 'ps' and 'pid' subcommands. The 'pprofClient' was updated to support Go 1.7 naming conventions for pprof files. The -privacy flag was added to 'userModeNetwork'. Removed trailing whitespace from all modified files. Change-Id: Ie8d2cc95fb6e7384ce3fbb4d19949d14ec19ddc7 Signed-off-by: Bishop Brock <[email protected]>
1 parent 519e8e8 commit 02431ee

File tree

6 files changed

+393
-171
lines changed

6 files changed

+393
-171
lines changed

tools/busywork/bin/busy

+78-31
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/tclsh
22

33
# Copyright IBM Corp. 2016. All Rights Reserved.
4-
#
4+
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
77
# You may obtain a copy of the License at
8-
#
8+
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing, software
1212
# distributed under the License is distributed on an "AS IS" BASIS,
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,18 +19,18 @@ set usage {
1919

2020
The 'busy' script runs commands on one or more peers in a busywork network,
2121
printing the salient portion of the response on stdout. 'busy' can be seen as
22-
an easier-to-use version of the Hyperledger fabric command-line-interface
23-
(CLI) in that 'busy' takes care of various kinds of bookkeeping and
24-
boilerplate code behind the scenes. 'busy' is probably best used as a tool for
25-
small scipts, or for issuing a few interactive commands to a peer
26-
network. Alhough complex test scripts could be implemented entirely as 'busy'
27-
calls, the performance of a test implemented this way would likely suffer from
28-
the process-creation overhead of each 'busy' invocation.
22+
an easier-to-use, enhanced version of the Hyperledger fabric
23+
command-line-interface (CLI) in that 'busy' takes care of various kinds of
24+
bookkeeping and boilerplate code behind the scenes. 'busy' is probably best
25+
used as a tool for small scipts, or for issuing a few interactive commands to
26+
a peer network. Alhough complex test scripts could be implemented entirely as
27+
'busy' calls, the performance of a test implemented this way would likely
28+
suffer from the process-creation overhead of each 'busy' invocation.
2929

3030
If the 'busy' command targets a single peer (see below) then the response from
31-
that peer is printed. If multiple peers are targeted, then the results are
32-
collected and printed as a JSON object, where each result is keyed by the peer
33-
name, e.g.,
31+
or for that peer is printed. If multiple peers are targeted, then the results
32+
are collected and printed as a JSON object, where each result is keyed by the
33+
peer name, e.g.,
3434

3535
{
3636
"vp0" : <VP0 response>,
@@ -39,8 +39,8 @@ name, e.g.,
3939
"vp<N>" : <VP<N> response>
4040
}
4141

42-
Use -json to force results from operations on a single peer to print as a JSON
43-
object.
42+
Include the -json option to force results from operations on a single peer to
43+
print as a JSON object.
4444

4545
'busy' is only supported for peer networks described by a 'network' file in
4646
the BUSYWORK_HOME directory. The <peers> to target are named by the peer IDs
@@ -76,6 +76,9 @@ The following command and argument forms are supported:
7676

7777
ping <peers> <user-chaincode-id>
7878

79+
pid <peers>
80+
ps <peers> <List of ps display keywords>
81+
7982
The 'network' and 'chaincodes' commands simply print the current 'network' and
8083
'chaincodes' files respectively from the implied $BUSYWORK_HOME.
8184

@@ -110,6 +113,17 @@ queries fail. If the ping query succeeds then the output of the ping queries
110113
is returned. This function currently assumes that the chaincode implments a
111114
'ping' query function with no parameters.
112115

116+
The 'pid' command simply returns the PID of each of the <peers>.
117+
118+
The 'ps' command is used to obtain 'ps' information from one or more
119+
peers. For each peer implied by the <peers> specification, the result returned
120+
is the result from executing 'ps' as follows, where <pid> is the PID of each
121+
of the <peers>:
122+
123+
ps -p <pid> -ww --noheader -o <List of ps display keywords>
124+
125+
Note that leading/trailing whitespace is removed from the result.
126+
113127
Examples:
114128

115129
busy chaincodes
@@ -124,6 +138,9 @@ Examples:
124138

125139
busy ping "*" cc2
126140

141+
busy pid vp0
142+
busy ps vp0 etime,cputime
143+
127144
Optional arguments, with defaults after the colon:
128145

129146
-h | -help | --help : N/A
@@ -149,12 +166,12 @@ Optional arguments, with defaults after the colon:
149166

150167
The -waitFor option is supported for the 'deploy', 'invoke' and 'ping'
151168
commands only. The semantics are explained below in the section headed
152-
"Semantics of -waitFor"
169+
"Semantics of -waitFor"
153170

154171
-json : See below
155172

156173
Select -json to force even single-peer operations to print as a JSON
157-
object, rather than simply as a value. This opiton is ignored for the
174+
object, rather than simply as a value. This option is ignored for the
158175
'chaincodes' and 'network' commands.
159176

160177

@@ -191,6 +208,14 @@ proc singletonCommand {cmd} {
191208
}
192209

193210

211+
proc fixedArgs {cmd nArgs} {
212+
213+
if {[llength [parms args]] != $nArgs} {
214+
errorExit "The '$cmd' command expects $nArgs arguments."
215+
}
216+
}
217+
218+
194219
proc chaincodes {} {
195220

196221
singletonCommand chaincodes
@@ -294,7 +319,7 @@ proc invoke {} {
294319
"Deployed IDs are $a(ids)"
295320
}
296321
set name $a($ccId.name)
297-
322+
298323
if {![null [parms waitFor]]} {
299324
set heights \
300325
[mapeach address [parms restAddresses] {
@@ -322,7 +347,7 @@ proc invoke {} {
322347
}
323348
}
324349

325-
350+
326351
proc query {} {
327352

328353
waitForNotOK query
@@ -344,7 +369,7 @@ proc query {} {
344369
errorExit
345370
}
346371
set name $a($ccId.name)
347-
372+
348373
parms results \
349374
[mapeach address [parms restAddresses] {
350375
return [fabric::query $address [parms user] $name $function $args]
@@ -369,7 +394,7 @@ proc ping {} {
369394
errorExit
370395
}
371396
set name $a($ccId.name)
372-
397+
373398
proc _ping {name} {
374399
set results {}
375400
foreach address [parms restAddresses] {
@@ -395,7 +420,33 @@ proc ping {} {
395420
}
396421
}
397422

398-
423+
424+
proc pid {} {
425+
426+
waitForNotOK pid
427+
fixedArgs pid 0
428+
429+
parms results [mapeach peer [parms peers] {
430+
return [parms network.peer.$peer.pid]
431+
}]
432+
}
433+
434+
435+
proc ps {} {
436+
437+
waitForNotOK ps
438+
fixedArgs ps 1
439+
440+
parms results [mapeach peer [parms peers] {
441+
set pid [parms network.peer.$peer.pid]
442+
if {[catch {exec ps -p $pid -ww --noheader -o [parms args]} result]} {
443+
errorExit "Exec of 'ps' failed : $result"
444+
}
445+
return [string trim $result]; # Remove leading/trailing whitespace
446+
}]
447+
}
448+
449+
399450
############################################################################
400451
# The script
401452
############################################################################
@@ -410,11 +461,11 @@ setLoggingLevel {} warn
410461
set options {
411462
{enum {-h -help --help} parms(help) 0 p_help}
412463
{key -home parms(home) {}}
413-
{bool -user parms(user) {} p_user}
464+
{key -user parms(user) {} p_user}
414465
{key -waitFor parms(waitFor) {}}
415466
{bool -json parms(json) 0}
416467
}
417-
468+
418469
mapKeywordArgs $argv $options parms(other)
419470

420471
if {$p_help} {
@@ -430,7 +481,7 @@ parms command [first [parms other]]
430481
switch [parms command] {
431482
chaincodes {chaincodes}
432483
network {network}
433-
}
484+
}
434485

435486
parms peers [busywork::peersFromSpec [second [parms other]]]
436487
parms args [restn [parms other] 2]
@@ -459,6 +510,8 @@ switch [parms command] {
459510
invoke {invoke}
460511
query {query}
461512
ping {ping}
513+
pid {pid}
514+
ps {ps}
462515
default {errorExit "Unrecognized command: [parms command]"}
463516
}
464517

@@ -489,9 +542,3 @@ if {[parms json] || [expr {[llength [parms results]] > 1}]} {
489542

490543
puts [first [parms results]]
491544
}
492-
493-
494-
495-
496-
497-

0 commit comments

Comments
 (0)