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
73db2acc
Commit
73db2acc
authored
Sep 02, 2010
by
antirez
Browse files
memory fragmentation reporting in INFO also added for Mac OS X
parent
eddb388e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/config.h
View file @
73db2acc
...
@@ -26,6 +26,11 @@
...
@@ -26,6 +26,11 @@
#define HAVE_PROCFS 1
#define HAVE_PROCFS 1
#endif
#endif
/* test for task_info() */
#if defined(__APPLE__)
#define HAVE_TASKINFO 1
#endif
/* test for backtrace() */
/* test for backtrace() */
#if defined(__APPLE__) || defined(__linux__)
#if defined(__APPLE__) || defined(__linux__)
#define HAVE_BACKTRACE 1
#define HAVE_BACKTRACE 1
...
...
src/zmalloc.c
View file @
73db2acc
...
@@ -32,10 +32,7 @@
...
@@ -32,10 +32,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <pthread.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "config.h"
#include "config.h"
#if defined(__sun)
#if defined(__sun)
...
@@ -176,8 +173,14 @@ void zmalloc_enable_thread_safeness(void) {
...
@@ -176,8 +173,14 @@ void zmalloc_enable_thread_safeness(void) {
}
}
/* Fragmentation = RSS / allocated-bytes */
/* Fragmentation = RSS / allocated-bytes */
#if defined(HAVE_PROCFS)
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
float
zmalloc_get_fragmentation_ratio
(
void
)
{
float
zmalloc_get_fragmentation_ratio
(
void
)
{
#ifdef HAVE_PROCFS
size_t
allocated
=
zmalloc_used_memory
();
size_t
allocated
=
zmalloc_used_memory
();
int
page
=
sysconf
(
_SC_PAGESIZE
);
int
page
=
sysconf
(
_SC_PAGESIZE
);
size_t
rss
;
size_t
rss
;
...
@@ -208,7 +211,29 @@ float zmalloc_get_fragmentation_ratio(void) {
...
@@ -208,7 +211,29 @@ float zmalloc_get_fragmentation_ratio(void) {
rss
=
strtoll
(
p
,
NULL
,
10
);
rss
=
strtoll
(
p
,
NULL
,
10
);
rss
*=
page
;
rss
*=
page
;
return
(
float
)
rss
/
allocated
;
return
(
float
)
rss
/
allocated
;
}
#elif defined(HAVE_TASKINFO)
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/task.h>
#include <mach/mach_init.h>
float
zmalloc_get_fragmentation_ratio
(
void
)
{
task_t
task
=
MACH_PORT_NULL
;
struct
task_basic_info
t_info
;
mach_msg_type_number_t
t_info_count
=
TASK_BASIC_INFO_COUNT
;
if
(
task_for_pid
(
current_task
(),
getpid
(),
&
task
)
!=
KERN_SUCCESS
)
return
0
;
task_info
(
task
,
TASK_BASIC_INFO
,
(
task_info_t
)
&
t_info
,
&
t_info_count
);
return
(
float
)
t_info
.
resident_size
/
zmalloc_used_memory
();
}
#else
#else
float
zmalloc_get_fragmentation_ratio
(
void
)
{
return
0
;
return
0
;
#endif
}
}
#endif
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