Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
6e5c2515
Unverified
Commit
6e5c2515
authored
Apr 26, 2019
by
Steven Allen
Committed by
GitHub
Apr 26, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6258 from myself659/bitswap-stat-human
humanize for ipfs bitswap stat
parents
9e973e52
63e18dac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
5 deletions
+38
-5
core/commands/bitswap.go
core/commands/bitswap.go
+15
-3
test/sharness/t0220-bitswap.sh
test/sharness/t0220-bitswap.sh
+23
-2
No files found.
core/commands/bitswap.go
View file @
6e5c2515
...
...
@@ -90,6 +90,7 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
const
(
bitswapVerboseOptionName
=
"verbose"
bitswapHumanOptionName
=
"human"
)
var
bitswapStatCmd
=
&
cmds
.
Command
{
...
...
@@ -99,6 +100,7 @@ var bitswapStatCmd = &cmds.Command{
},
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
bitswapVerboseOptionName
,
"v"
,
"Print extra information"
),
cmdkit
.
BoolOption
(
bitswapHumanOptionName
,
"Print sizes in human readable format (e.g., 1K 234M 2G)"
),
},
Type
:
bitswap
.
Stat
{},
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
...
...
@@ -130,15 +132,25 @@ var bitswapStatCmd = &cmds.Command{
return
err
}
verbose
,
_
:=
req
.
Options
[
bitswapVerboseOptionName
]
.
(
bool
)
human
,
_
:=
req
.
Options
[
bitswapHumanOptionName
]
.
(
bool
)
fmt
.
Fprintln
(
w
,
"bitswap status"
)
fmt
.
Fprintf
(
w
,
"
\t
provides buffer: %d / %d
\n
"
,
s
.
ProvideBufLen
,
bitswap
.
HasBlockBufferSize
)
fmt
.
Fprintf
(
w
,
"
\t
blocks received: %d
\n
"
,
s
.
BlocksReceived
)
fmt
.
Fprintf
(
w
,
"
\t
blocks sent: %d
\n
"
,
s
.
BlocksSent
)
fmt
.
Fprintf
(
w
,
"
\t
data received: %d
\n
"
,
s
.
DataReceived
)
fmt
.
Fprintf
(
w
,
"
\t
data sent: %d
\n
"
,
s
.
DataSent
)
if
human
{
fmt
.
Fprintf
(
w
,
"
\t
data received: %s
\n
"
,
humanize
.
Bytes
(
s
.
DataReceived
))
fmt
.
Fprintf
(
w
,
"
\t
data sent: %s
\n
"
,
humanize
.
Bytes
(
s
.
DataSent
))
}
else
{
fmt
.
Fprintf
(
w
,
"
\t
data received: %d
\n
"
,
s
.
DataReceived
)
fmt
.
Fprintf
(
w
,
"
\t
data sent: %d
\n
"
,
s
.
DataSent
)
}
fmt
.
Fprintf
(
w
,
"
\t
dup blocks received: %d
\n
"
,
s
.
DupBlksReceived
)
fmt
.
Fprintf
(
w
,
"
\t
dup data received: %s
\n
"
,
humanize
.
Bytes
(
s
.
DupDataReceived
))
if
human
{
fmt
.
Fprintf
(
w
,
"
\t
dup data received: %s
\n
"
,
humanize
.
Bytes
(
s
.
DupDataReceived
))
}
else
{
fmt
.
Fprintf
(
w
,
"
\t
dup data received: %d
\n
"
,
s
.
DupDataReceived
)
}
fmt
.
Fprintf
(
w
,
"
\t
wantlist [%d keys]
\n
"
,
len
(
s
.
Wantlist
))
for
_
,
k
:=
range
s
.
Wantlist
{
fmt
.
Fprintf
(
w
,
"
\t\t
%s
\n
"
,
enc
.
Encode
(
k
))
...
...
test/sharness/t0220-bitswap.sh
View file @
6e5c2515
...
...
@@ -24,7 +24,7 @@ bitswap status
data received: 0
data sent: 0
dup blocks received: 0
dup data received: 0
B
dup data received: 0
wantlist [0 keys]
partners [0]
EOF
...
...
@@ -62,7 +62,7 @@ bitswap status
data received: 0
data sent: 0
dup blocks received: 0
dup data received: 0
B
dup data received: 0
wantlist [0 keys]
partners [0]
EOF
...
...
@@ -77,6 +77,27 @@ test_expect_success "'ipfs bitswap wantlist -p' output looks good" '
test_cmp wantlist_out wantlist_p_out
'
test_expect_success
"'ipfs bitswap stat --human' succeeds"
'
ipfs bitswap stat --human >stat_out_human
'
test_expect_success
"'ipfs bitswap stat --human' output looks good"
'
cat <<EOF | unexpand -t2 >expected &&
bitswap status
provides buffer: 0 / 256
blocks received: 0
blocks sent: 0
data received: 0 B
data sent: 0 B
dup blocks received: 0
dup data received: 0 B
wantlist [0 keys]
partners [0]
EOF
test_cmp expected stat_out_human
'
test_kill_ipfs_daemon
test_done
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment