Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
68892535
提交
68892535
authored
5月 26, 2016
作者:
nneul at mst.edu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9199 easier memory allocation debugging and analysis
上级
67e1db09
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
144 行增加
和
4 行删除
+144
-4
analyze-debug-alloc.pl
scripts/perl/analyze-debug-alloc.pl
+136
-0
switch_core_memory.c
src/switch_core_memory.c
+8
-4
没有找到文件。
scripts/perl/analyze-debug-alloc.pl
0 → 100755
浏览文件 @
68892535
#!/usr/bin/perl
# analyze-debug-alloc.pl
# generate allocation report by processing log files
# Note that this script is only useful when run against freeswitch log files
# produced when server is running with DEBUG_ALLOC and DEBUG_ALLOC2 set.
# It's purely for diagnosing memory leaks.
use
strict
;
use
JSON
;
my
$debug
=
0
;
my
@logs
=
sort
glob
(
"freeswitch.log.*"
);
push
(
@logs
,
"freeswitch.log"
);
my
%
pools
=
();
foreach
my
$file
(
@logs
)
{
open
(
my
$in
,
"<$file"
);
while
(
defined
(
my
$line
=
<
$in
>
)
)
{
if
(
$line
=~
/(0x[0-9A-Fa-f]+) DESTROY POOL$/o
)
{
my
$paddr
=
$1
;
if
(
!
$pools
{
$paddr
}
)
{
$debug
&&
print
"WARN: No ref to pool $paddr.\n"
;
}
else
{
foreach
my
$alloc
(
@
{
$pools
{
$paddr
}
->
{
allocs
}
}
)
{
# debug, might not be needed
}
delete
$pools
{
$paddr
};
}
}
elsif
(
$line
=~
/(0x[0-9A-Fa-f]+) Free Pool/o
)
{
my
$paddr
=
$1
;
if
(
!
$pools
{
$paddr
}
)
{
$debug
&&
print
"WARN: No ref to pool $paddr.\n"
;
}
else
{
foreach
my
$alloc
(
@
{
$pools
{
$paddr
}
->
{
allocs
}
}
)
{
# debug, might not be needed
}
delete
$pools
{
$paddr
};
}
}
elsif
(
$line
=~
/(0x[0-9A-Fa-f]+) New Pool (.*)$/o
)
{
my
$paddr
=
$1
;
my
$where
=
$2
;
if
(
$pools
{
$paddr
}
)
{
$debug
&&
print
"WARN: Duplicate pool $paddr at $where.\n"
;
}
$pools
{
$paddr
}
->
{
where
}
=
$where
;
if
(
!
$pools
{
$paddr
}
->
{
allocs
}
)
{
$pools
{
$paddr
}
->
{
allocs
}
=
[]
;
}
}
elsif
(
$line
=~
/CONSOLE\] \s*(.*?:\d+) (0x[0-9A-Fa-f]+) Core Allocate (.*:\d+)\s+(\d+)$/o
)
{
my
$where
=
$1
;
my
$paddr
=
$2
;
my
$pwhere
=
$3
;
my
$size
=
$4
;
if
(
!
$pools
{
$paddr
}
)
{
$debug
&&
print
"WARN: Missing pool ref for alloc of $size from $paddr at $where (pool $pwhere)\n"
;
}
$pools
{
$paddr
}
->
{
where
}
=
$where
;
push
(
@
{
$pools
{
$paddr
}
->
{
allocs
}
},
{
size
=>
$size
,
where
=>
$where
}
);
}
elsif
(
$line
=~
/CONSOLE\] \s*(.*?:\d+) (0x[0-9A-Fa-f]+) Core Strdup Allocate (.*:\d+)\s+(\d+)$/o
)
{
my
$where
=
$1
;
my
$paddr
=
$2
;
my
$pwhere
=
$3
;
my
$size
=
$4
;
if
(
!
$pools
{
$paddr
}
)
{
$debug
&&
print
"WARN: Missing pool ref for strdup alloc of $size from $paddr at $where (pool $pwhere)\n"
;
}
$pools
{
$paddr
}
->
{
where
}
=
$where
;
push
(
@
{
$pools
{
$paddr
}
->
{
allocs
}
},
{
size
=>
$size
,
where
=>
$where
}
);
}
}
}
my
$used
=
0
;
my
$pcount
=
0
;
my
$acount
=
0
;
my
%
pool_cnt_by_where
=
();
my
%
alloc_size_by_where
=
();
my
%
alloc_cnt_by_where
=
();
foreach
my
$pool
(
keys
%
pools
)
{
my
$where
=
$pools
{
$pool
}
->
{
where
};
$pcount
++
;
$pool_cnt_by_where
{
$where
}
++
;
foreach
my
$alloc
(
@
{
$pools
{
$pool
}
->
{
allocs
}
}
)
{
my
$sz
=
$alloc
->
{
size
};
my
$where
=
$alloc
->
{
where
};
$acount
++
;
$alloc_size_by_where
{
$where
}
+=
$sz
;
$alloc_cnt_by_where
{
$where
}
++
;
$used
+=
$sz
;
}
}
print
"Used: $used\n"
;
print
"Pool Count: $pcount\n"
;
print
"Alloc Count: $acount\n"
;
my
$json
=
new
JSON
;
$json
->
pretty
(
1
);
$json
->
canonical
(
1
);
print
"Pool Count by Where:\n"
;
foreach
my
$pool
(
sort
{
$pool_cnt_by_where
{
$a
}
<=>
$pool_cnt_by_where
{
$b
}
||
$a
cmp
$b
}
keys
%
pool_cnt_by_where
)
{
print
$pool_cnt_by_where
{
$pool
},
"\t"
,
$pool
,
"\n"
;
}
print
"\n"
;
print
"Alloc Count by Where:\n"
;
foreach
my
$pool
(
sort
{
$alloc_cnt_by_where
{
$a
}
<=>
$alloc_cnt_by_where
{
$b
}
||
$a
cmp
$b
}
keys
%
alloc_cnt_by_where
)
{
print
$alloc_cnt_by_where
{
$pool
},
"\t"
,
$pool
,
"\n"
;
}
print
"\n"
;
print
"Alloc Size by Where:\n"
;
foreach
my
$pool
(
sort
{
$alloc_size_by_where
{
$a
}
<=>
$alloc_size_by_where
{
$b
}
||
$a
cmp
$b
}
keys
%
alloc_size_by_where
)
{
print
$alloc_size_by_where
{
$pool
},
"\t"
,
$pool
,
"\n"
;
}
print
"\n"
;
src/switch_core_memory.c
浏览文件 @
68892535
...
...
@@ -37,6 +37,7 @@
//#define DEBUG_ALLOC
//#define DEBUG_ALLOC2
//#define DEBUG_ALLOC_CUTOFF 0 /* Lower to zero to log all pool allocations when DEBUG_ALLOC is defined */
//#define DESTROY_POOLS
//#define INSTANTLY_DESTROY_POOLS
//#define LOCK_MORE
...
...
@@ -45,6 +46,9 @@
#ifndef SWITCH_POOL_RECYCLE
#define PER_POOL_LOCK 1
#endif
#ifndef DEBUG_ALLOC_CUTOFF
#define DEBUG_ALLOC_CUTOFF 500
#endif
static
struct
{
#ifdef USE_MEM_LOCK
...
...
@@ -79,7 +83,7 @@ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *
#endif
#ifdef DEBUG_ALLOC
if
(
memory
>
500
)
if
(
memory
>
DEBUG_ALLOC_CUTOFF
)
switch_log_printf
(
SWITCH_CHANNEL_ID_LOG
,
file
,
func
,
line
,
NULL
,
SWITCH_LOG_CONSOLE
,
"%p %p Session Allocate %s %d
\n
"
,
(
void
*
)
session
->
pool
,
(
void
*
)
session
,
apr_pool_tag
(
session
->
pool
,
NULL
),
(
int
)
memory
);
#endif
...
...
@@ -247,7 +251,7 @@ SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t
#ifdef DEBUG_ALLOC
len
=
strlen
(
todup
);
if
(
len
>
500
)
if
(
len
>
DEBUG_ALLOC_CUTOFF
)
switch_log_printf
(
SWITCH_CHANNEL_ID_LOG
,
file
,
func
,
line
,
NULL
,
SWITCH_LOG_CONSOLE
,
"%p %p Sess Strdup Allocate %s %ld
\n
"
,
(
void
*
)
session
->
pool
,
(
void
*
)
session
,
apr_pool_tag
(
session
->
pool
,
NULL
),
strlen
(
todup
));
#endif
...
...
@@ -286,7 +290,7 @@ SWITCH_DECLARE(char *) switch_core_perform_strdup(switch_memory_pool_t *pool, co
len
=
strlen
(
todup
)
+
1
;
#ifdef DEBUG_ALLOC
if
(
len
>
500
)
if
(
len
>
DEBUG_ALLOC_CUTOFF
)
switch_log_printf
(
SWITCH_CHANNEL_ID_LOG
,
file
,
func
,
line
,
NULL
,
SWITCH_LOG_CONSOLE
,
"%p Core Strdup Allocate %s %d
\n
"
,
(
void
*
)
pool
,
apr_pool_tag
(
pool
,
NULL
),
(
int
)
len
);
#endif
...
...
@@ -457,7 +461,7 @@ SWITCH_DECLARE(void *) switch_core_perform_alloc(switch_memory_pool_t *pool, swi
#endif
#ifdef DEBUG_ALLOC
if
(
memory
>
500
)
if
(
memory
>
DEBUG_ALLOC_CUTOFF
)
switch_log_printf
(
SWITCH_CHANNEL_ID_LOG
,
file
,
func
,
line
,
NULL
,
SWITCH_LOG_CONSOLE
,
"%p Core Allocate %s %d
\n
"
,
(
void
*
)
pool
,
apr_pool_tag
(
pool
,
NULL
),
(
int
)
memory
);
/*switch_assert(memory < 20000); */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论