Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
0d7b10ee
Commit
0d7b10ee
authored
Apr 11, 2013
by
antirez
Browse files
redis-cli: --latency-history mode implemented.
parent
8d81e68d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
0d7b10ee
...
@@ -72,6 +72,7 @@ static struct config {
...
@@ -72,6 +72,7 @@ static struct config {
int
monitor_mode
;
int
monitor_mode
;
int
pubsub_mode
;
int
pubsub_mode
;
int
latency_mode
;
int
latency_mode
;
int
latency_history
;
int
cluster_mode
;
int
cluster_mode
;
int
cluster_reissue_command
;
int
cluster_reissue_command
;
int
slave_mode
;
int
slave_mode
;
...
@@ -700,6 +701,9 @@ static int parseOptions(int argc, char **argv) {
...
@@ -700,6 +701,9 @@ static int parseOptions(int argc, char **argv) {
config
.
output
=
OUTPUT_CSV
;
config
.
output
=
OUTPUT_CSV
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"--latency"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--latency"
))
{
config
.
latency_mode
=
1
;
config
.
latency_mode
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"--latency-history"
))
{
config
.
latency_mode
=
1
;
config
.
latency_history
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"--slave"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--slave"
))
{
config
.
slave_mode
=
1
;
config
.
slave_mode
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"--stat"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--stat"
))
{
...
@@ -753,26 +757,29 @@ static void usage() {
...
@@ -753,26 +757,29 @@ static void usage() {
"redis-cli %s
\n
"
"redis-cli %s
\n
"
"
\n
"
"
\n
"
"Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
\n
"
"Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
\n
"
" -h <hostname> Server hostname (default: 127.0.0.1)
\n
"
" -h <hostname> Server hostname (default: 127.0.0.1)
\n
"
" -p <port> Server port (default: 6379)
\n
"
" -p <port> Server port (default: 6379)
\n
"
" -s <socket> Server socket (overrides hostname and port)
\n
"
" -s <socket> Server socket (overrides hostname and port)
\n
"
" -a <password> Password to use when connecting to the server
\n
"
" -a <password> Password to use when connecting to the server
\n
"
" -r <repeat> Execute specified command N times
\n
"
" -r <repeat> Execute specified command N times
\n
"
" -i <interval> When -r is used, waits <interval> seconds per command.
\n
"
" -i <interval> When -r is used, waits <interval> seconds per command.
\n
"
" It is possible to specify sub-second times like -i 0.1
\n
"
" It is possible to specify sub-second times like -i 0.1
\n
"
" -n <db> Database number
\n
"
" -n <db> Database number
\n
"
" -x Read last argument from STDIN
\n
"
" -x Read last argument from STDIN
\n
"
" -d <delimiter> Multi-bulk delimiter in for raw formatting (default:
\\
n)
\n
"
" -d <delimiter> Multi-bulk delimiter in for raw formatting (default:
\\
n)
\n
"
" -c Enable cluster mode (follow -ASK and -MOVED redirections)
\n
"
" -c Enable cluster mode (follow -ASK and -MOVED redirections)
\n
"
" --raw Use raw formatting for replies (default when STDOUT is not a tty)
\n
"
" --raw Use raw formatting for replies (default when STDOUT is
\n
"
" --latency Enter a special mode continuously sampling latency
\n
"
" not a tty)
\n
"
" --slave Simulate a slave showing commands received from the master
\n
"
" --latency Enter a special mode continuously sampling latency
\n
"
" --rdb <filename> Transfer an RDB dump from remote server to local file.
\n
"
" --latency-history Like --latency but tracking latency changes over time.
\n
"
" --pipe Transfer raw Redis protocol from stdin to server
\n
"
" Default time interval is 15 sec. Change it using -i.
\n
"
" --bigkeys Sample Redis keys looking for big keys
\n
"
" --slave Simulate a slave showing commands received from the master
\n
"
" --eval <file> Send an EVAL command using the Lua script at <file>
\n
"
" --rdb <filename> Transfer an RDB dump from remote server to local file.
\n
"
" --help Output this help and exit
\n
"
" --pipe Transfer raw Redis protocol from stdin to server
\n
"
" --version Output version and exit
\n
"
" --bigkeys Sample Redis keys looking for big keys
\n
"
" --eval <file> Send an EVAL command using the Lua script at <file>
\n
"
" --help Output this help and exit
\n
"
" --version Output version and exit
\n
"
"
\n
"
"
\n
"
"Examples:
\n
"
"Examples:
\n
"
" cat /etc/passwd | redis-cli -x set mypasswd
\n
"
" cat /etc/passwd | redis-cli -x set mypasswd
\n
"
...
@@ -943,10 +950,16 @@ static int evalMode(int argc, char **argv) {
...
@@ -943,10 +950,16 @@ static int evalMode(int argc, char **argv) {
return
cliSendCommand
(
argc
+
3
-
got_comma
,
argv2
,
config
.
repeat
);
return
cliSendCommand
(
argc
+
3
-
got_comma
,
argv2
,
config
.
repeat
);
}
}
#define LATENCY_SAMPLE_RATE 10
/* milliseconds. */
#define LATENCY_HISTORY_DEFAULT_INTERVAL 15000
/* milliseconds. */
static
void
latencyMode
(
void
)
{
static
void
latencyMode
(
void
)
{
redisReply
*
reply
;
redisReply
*
reply
;
long
long
start
,
latency
,
min
=
0
,
max
=
0
,
tot
=
0
,
count
=
0
;
long
long
start
,
latency
,
min
=
0
,
max
=
0
,
tot
=
0
,
count
=
0
;
long
long
history_interval
=
config
.
interval
?
config
.
interval
/
1000
:
LATENCY_HISTORY_DEFAULT_INTERVAL
;
double
avg
;
double
avg
;
long
long
history_start
=
mstime
();
if
(
!
context
)
exit
(
1
);
if
(
!
context
)
exit
(
1
);
while
(
1
)
{
while
(
1
)
{
...
@@ -971,7 +984,13 @@ static void latencyMode(void) {
...
@@ -971,7 +984,13 @@ static void latencyMode(void) {
printf
(
"
\x1b
[0G
\x1b
[2Kmin: %lld, max: %lld, avg: %.2f (%lld samples)"
,
printf
(
"
\x1b
[0G
\x1b
[2Kmin: %lld, max: %lld, avg: %.2f (%lld samples)"
,
min
,
max
,
avg
,
count
);
min
,
max
,
avg
,
count
);
fflush
(
stdout
);
fflush
(
stdout
);
usleep
(
10000
);
if
(
config
.
latency_history
&&
mstime
()
-
history_start
>
history_interval
)
{
printf
(
" -- %.2f seconds range
\n
"
,
(
float
)(
mstime
()
-
history_start
)
/
1000
);
history_start
=
mstime
();
min
=
max
=
tot
=
count
=
0
;
}
usleep
(
LATENCY_SAMPLE_RATE
*
1000
);
}
}
}
}
...
@@ -1452,6 +1471,7 @@ int main(int argc, char **argv) {
...
@@ -1452,6 +1471,7 @@ int main(int argc, char **argv) {
config
.
monitor_mode
=
0
;
config
.
monitor_mode
=
0
;
config
.
pubsub_mode
=
0
;
config
.
pubsub_mode
=
0
;
config
.
latency_mode
=
0
;
config
.
latency_mode
=
0
;
config
.
latency_history
=
0
;
config
.
cluster_mode
=
0
;
config
.
cluster_mode
=
0
;
config
.
slave_mode
=
0
;
config
.
slave_mode
=
0
;
config
.
getrdb_mode
=
0
;
config
.
getrdb_mode
=
0
;
...
...
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