mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
zmalloc_get_private_dirty() function added (Linux only).
For non Linux systmes it just returns 0. This function is useful to estimate copy-on-write because of childs saving stuff on disk.
This commit is contained in:
parent
af0b220756
commit
3bfeb9c1a7
@ -324,3 +324,28 @@ size_t zmalloc_get_rss(void) {
|
|||||||
float zmalloc_get_fragmentation_ratio(void) {
|
float zmalloc_get_fragmentation_ratio(void) {
|
||||||
return (float)zmalloc_get_rss()/zmalloc_used_memory();
|
return (float)zmalloc_get_rss()/zmalloc_used_memory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_PROCFS)
|
||||||
|
size_t zmalloc_get_private_dirty(void) {
|
||||||
|
char line[1024];
|
||||||
|
size_t pd = 0;
|
||||||
|
FILE *fp = fopen("/proc/self/smaps","r");
|
||||||
|
|
||||||
|
if (!fp) return 0;
|
||||||
|
while(fgets(line,sizeof(line),fp) != NULL) {
|
||||||
|
if (strncmp(line,"Private_Dirty:",14) == 0) {
|
||||||
|
char *p = strchr(line,'k');
|
||||||
|
if (p) {
|
||||||
|
*p = '\0';
|
||||||
|
pd += strtol(line+14,NULL,10) * 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return pd;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
size_t zmalloc_get_private_dirty(void) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -75,6 +75,7 @@ void zmalloc_enable_thread_safeness(void);
|
|||||||
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
||||||
float zmalloc_get_fragmentation_ratio(void);
|
float zmalloc_get_fragmentation_ratio(void);
|
||||||
size_t zmalloc_get_rss(void);
|
size_t zmalloc_get_rss(void);
|
||||||
|
size_t zmalloc_get_private_dirty(void);
|
||||||
void zlibc_free(void *ptr);
|
void zlibc_free(void *ptr);
|
||||||
|
|
||||||
#ifndef HAVE_MALLOC_SIZE
|
#ifndef HAVE_MALLOC_SIZE
|
||||||
|
Loading…
Reference in New Issue
Block a user