Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
想上天的蜗牛@
redis
提交
eddb388e
R
redis
项目概览
想上天的蜗牛@
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eddb388e
编写于
9月 02, 2010
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
memory fragmentation ratio in INFO output
上级
a047bf52
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
0 deletion
+50
-0
src/config.h
src/config.h
+5
-0
src/redis.c
src/redis.c
+2
-0
src/zmalloc.c
src/zmalloc.c
+42
-0
src/zmalloc.h
src/zmalloc.h
+1
-0
未找到文件。
src/config.h
浏览文件 @
eddb388e
...
...
@@ -21,6 +21,11 @@
#define redis_stat stat
#endif
/* test for proc filesystem */
#ifdef __linux__
#define HAVE_PROCFS 1
#endif
/* test for backtrace() */
#if defined(__APPLE__) || defined(__linux__)
#define HAVE_BACKTRACE 1
...
...
src/redis.c
浏览文件 @
eddb388e
...
...
@@ -1166,6 +1166,7 @@ sds genRedisInfoString(void) {
"blocked_clients:%d
\r\n
"
"used_memory:%zu
\r\n
"
"used_memory_human:%s
\r\n
"
"mem_fragmentation_ratio:%.2f
\r\n
"
"changes_since_last_save:%lld
\r\n
"
"bgsave_in_progress:%d
\r\n
"
"last_save_time:%ld
\r\n
"
...
...
@@ -1192,6 +1193,7 @@ sds genRedisInfoString(void) {
server
.
blpop_blocked_clients
,
zmalloc_used_memory
(),
hmem
,
zmalloc_get_fragmentation_ratio
(),
server
.
dirty
,
server
.
bgsavechildpid
!=
-
1
,
server
.
lastsave
,
...
...
src/zmalloc.c
浏览文件 @
eddb388e
...
...
@@ -32,6 +32,10 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "config.h"
#if defined(__sun)
...
...
@@ -170,3 +174,41 @@ size_t zmalloc_used_memory(void) {
void
zmalloc_enable_thread_safeness
(
void
)
{
zmalloc_thread_safe
=
1
;
}
/* Fragmentation = RSS / allocated-bytes */
float
zmalloc_get_fragmentation_ratio
(
void
)
{
#ifdef HAVE_PROCFS
size_t
allocated
=
zmalloc_used_memory
();
int
page
=
sysconf
(
_SC_PAGESIZE
);
size_t
rss
;
char
buf
[
4096
];
char
filename
[
256
];
int
fd
,
count
;
char
*
p
,
*
x
;
snprintf
(
filename
,
256
,
"/proc/%d/stat"
,
getpid
());
if
((
fd
=
open
(
filename
,
O_RDONLY
))
==
-
1
)
return
0
;
if
(
read
(
fd
,
buf
,
4096
)
<=
0
)
{
close
(
fd
);
return
0
;
}
close
(
fd
);
p
=
buf
;
count
=
23
;
/* RSS is the 24th field in /proc/<pid>/stat */
while
(
p
&&
count
--
)
{
p
=
strchr
(
p
,
' '
);
if
(
p
)
p
++
;
}
if
(
!
p
)
return
0
;
x
=
strchr
(
p
,
' '
);
if
(
!
x
)
return
0
;
*
x
=
'\0'
;
rss
=
strtoll
(
p
,
NULL
,
10
);
rss
*=
page
;
return
(
float
)
rss
/
allocated
;
#else
return
0
;
#endif
}
src/zmalloc.h
浏览文件 @
eddb388e
...
...
@@ -38,5 +38,6 @@ void zfree(void *ptr);
char
*
zstrdup
(
const
char
*
s
);
size_t
zmalloc_used_memory
(
void
);
void
zmalloc_enable_thread_safeness
(
void
);
float
zmalloc_get_fragmentation_ratio
(
void
);
#endif
/* _ZMALLOC_H */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录