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
78f35f8d
Commit
78f35f8d
authored
Sep 16, 2016
by
antirez
Browse files
Memory related subcommands of DEBUG moved to MEMORY.
parent
123891db
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/debug.c
View file @
78f35f8d
...
@@ -252,14 +252,6 @@ void computeDatasetDigest(unsigned char *final) {
...
@@ -252,14 +252,6 @@ void computeDatasetDigest(unsigned char *final) {
}
}
}
}
#if defined(USE_JEMALLOC)
void
inputCatSds
(
void
*
result
,
const
char
*
str
)
{
/* result is actually a (sds *), so re-cast it here */
sds
*
info
=
(
sds
*
)
result
;
*
info
=
sdscat
(
*
info
,
str
);
}
#endif
void
debugCommand
(
client
*
c
)
{
void
debugCommand
(
client
*
c
)
{
if
(
c
->
argc
==
1
)
{
if
(
c
->
argc
==
1
)
{
addReplyError
(
c
,
"You must specify a subcommand for DEBUG. Try DEBUG HELP for info."
);
addReplyError
(
c
,
"You must specify a subcommand for DEBUG. Try DEBUG HELP for info."
);
...
@@ -303,10 +295,6 @@ void debugCommand(client *c) {
...
@@ -303,10 +295,6 @@ void debugCommand(client *c) {
"structsize -- Return the size of different Redis core C structures."
);
"structsize -- Return the size of different Redis core C structures."
);
blen
++
;
addReplyStatus
(
c
,
blen
++
;
addReplyStatus
(
c
,
"htstats <dbid> -- Return hash table statistics of the specified Redis database."
);
"htstats <dbid> -- Return hash table statistics of the specified Redis database."
);
blen
++
;
addReplyStatus
(
c
,
"jemalloc info -- Show internal jemalloc statistics."
);
blen
++
;
addReplyStatus
(
c
,
"jemalloc purge -- Force jemalloc to release unused memory."
);
setDeferredMultiBulkLength
(
c
,
blenp
,
blen
);
setDeferredMultiBulkLength
(
c
,
blenp
,
blen
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"segfault"
))
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"segfault"
))
{
*
((
char
*
)
-
1
)
=
'x'
;
*
((
char
*
)
-
1
)
=
'x'
;
...
@@ -520,30 +508,6 @@ void debugCommand(client *c) {
...
@@ -520,30 +508,6 @@ void debugCommand(client *c) {
stats
=
sdscat
(
stats
,
buf
);
stats
=
sdscat
(
stats
,
buf
);
addReplyBulkSds
(
c
,
stats
);
addReplyBulkSds
(
c
,
stats
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"jemalloc"
)
&&
c
->
argc
==
3
)
{
#if defined(USE_JEMALLOC)
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"info"
))
{
sds
info
=
sdsempty
();
je_malloc_stats_print
(
inputCatSds
,
&
info
,
NULL
);
addReplyBulkSds
(
c
,
info
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"purge"
))
{
char
tmp
[
32
];
unsigned
narenas
=
0
;
size_t
sz
=
sizeof
(
unsigned
);
if
(
!
je_mallctl
(
"arenas.narenas"
,
&
narenas
,
&
sz
,
NULL
,
0
))
{
sprintf
(
tmp
,
"arena.%d.purge"
,
narenas
);
if
(
!
je_mallctl
(
tmp
,
NULL
,
0
,
NULL
,
0
))
{
addReply
(
c
,
shared
.
ok
);
return
;
}
}
addReplyError
(
c
,
"Error purging dirty pages"
);
}
else
{
addReplyErrorFormat
(
c
,
"Valid jemalloc debug fields: info, purge"
);
}
#else
addReplyErrorFormat
(
c
,
"jemalloc support not available"
);
#endif
}
else
{
}
else
{
addReplyErrorFormat
(
c
,
"Unknown DEBUG subcommand or wrong number of arguments for '%s'"
,
addReplyErrorFormat
(
c
,
"Unknown DEBUG subcommand or wrong number of arguments for '%s'"
,
(
char
*
)
c
->
argv
[
1
]
->
ptr
);
(
char
*
)
c
->
argv
[
1
]
->
ptr
);
...
...
src/object.c
View file @
78f35f8d
...
@@ -893,6 +893,14 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
...
@@ -893,6 +893,14 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
return
mh
;
return
mh
;
}
}
/* Helper for "MEMORY allocator-stats", used as a callback for the jemalloc
* stats output. */
void
inputCatSds
(
void
*
result
,
const
char
*
str
)
{
/* result is actually a (sds *), so re-cast it here */
sds
*
info
=
(
sds
*
)
result
;
*
info
=
sdscat
(
*
info
,
str
);
}
/* ======================= The OBJECT and MEMORY commands =================== */
/* ======================= The OBJECT and MEMORY commands =================== */
/* This is a helper function for the OBJECT command. We need to lookup keys
/* This is a helper function for the OBJECT command. We need to lookup keys
...
@@ -1023,12 +1031,41 @@ void memoryCommand(client *c) {
...
@@ -1023,12 +1031,41 @@ void memoryCommand(client *c) {
addReplyDouble
(
c
,
mh
->
dataset_perc
);
addReplyDouble
(
c
,
mh
->
dataset_perc
);
freeMemoryOverheadData
(
mh
);
freeMemoryOverheadData
(
mh
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"allocator-stats"
)
&&
c
->
argc
==
2
)
{
#if defined(USE_JEMALLOC)
sds
info
=
sdsempty
();
je_malloc_stats_print
(
inputCatSds
,
&
info
,
NULL
);
addReplyBulkSds
(
c
,
info
);
#else
addReplyBulkCString
(
c
,
"Stats not supported for the current allocator"
);
#endif
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"purge"
)
&&
c
->
argc
==
2
)
{
#if defined(USE_JEMALLOC)
char
tmp
[
32
];
unsigned
narenas
=
0
;
size_t
sz
=
sizeof
(
unsigned
);
if
(
!
je_mallctl
(
"arenas.narenas"
,
&
narenas
,
&
sz
,
NULL
,
0
))
{
sprintf
(
tmp
,
"arena.%d.purge"
,
narenas
);
if
(
!
je_mallctl
(
tmp
,
NULL
,
0
,
NULL
,
0
))
{
addReply
(
c
,
shared
.
ok
);
return
;
}
}
addReplyError
(
c
,
"Error purging dirty pages"
);
#else
addReply
(
c
,
shared
.
ok
);
/* Nothing to do for other allocators. */
#endif
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"help"
)
&&
c
->
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"help"
)
&&
c
->
argc
==
2
)
{
addReplyMultiBulkLen
(
c
,
2
);
addReplyMultiBulkLen
(
c
,
4
);
addReplyBulkCString
(
c
,
"MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"
);
addReplyBulkCString
(
c
,
"MEMORY OVERHEAD - Show memory usage details"
);
addReplyBulkCString
(
c
,
addReplyBulkCString
(
c
,
"MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of ke
y"
);
"MEMORY PURGE - Ask the allocator to release memor
y"
);
addReplyBulkCString
(
c
,
addReplyBulkCString
(
c
,
"MEMORY OVERHEAD - Show memory usage detail
s"
);
"MEMORY ALLOCATOR-STATS - Show allocator internal stat
s"
);
}
else
{
}
else
{
addReplyError
(
c
,
"Syntax error. Try MEMORY HELP"
);
addReplyError
(
c
,
"Syntax error. Try MEMORY HELP"
);
}
}
...
...
src/redis-cli.c
View file @
78f35f8d
...
@@ -843,8 +843,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -843,8 +843,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
output_raw
=
0
;
output_raw
=
0
;
if
(
!
strcasecmp
(
command
,
"info"
)
||
if
(
!
strcasecmp
(
command
,
"info"
)
||
(
argc
>=
2
&&
!
strcasecmp
(
command
,
"debug"
)
&&
(
argc
>=
2
&&
!
strcasecmp
(
command
,
"debug"
)
&&
((
!
strcasecmp
(
argv
[
1
],
"jemalloc"
)
&&
!
strcasecmp
(
argv
[
2
],
"info"
))
||
!
strcasecmp
(
argv
[
1
],
"htstats"
))
||
!
strcasecmp
(
argv
[
1
],
"htstats"
)))
||
(
argc
>=
2
&&
!
strcasecmp
(
command
,
"memory"
)
&&
!
strcasecmp
(
argv
[
1
],
"allocator-stats"
))
||
(
argc
==
2
&&
!
strcasecmp
(
command
,
"cluster"
)
&&
(
argc
==
2
&&
!
strcasecmp
(
command
,
"cluster"
)
&&
(
!
strcasecmp
(
argv
[
1
],
"nodes"
)
||
(
!
strcasecmp
(
argv
[
1
],
"nodes"
)
||
!
strcasecmp
(
argv
[
1
],
"info"
)))
||
!
strcasecmp
(
argv
[
1
],
"info"
)))
||
...
...
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