Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
2af0cf89
提交
2af0cf89
authored
9月 26, 2013
作者:
Seven Du
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some statistics on sonar
上级
e09cdf9c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
52 行增加
和
3 行删除
+52
-3
mod_sonar.c
src/mod/applications/mod_sonar/mod_sonar.c
+52
-3
没有找到文件。
src/mod/applications/mod_sonar/mod_sonar.c
浏览文件 @
2af0cf89
...
@@ -40,6 +40,14 @@
...
@@ -40,6 +40,14 @@
#include <switch.h>
#include <switch.h>
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/* Prototypes */
/* Prototypes */
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_sonar_shutdown
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_sonar_shutdown
);
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_sonar_runtime
);
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_sonar_runtime
);
...
@@ -51,17 +59,26 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sonar_load);
...
@@ -51,17 +59,26 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sonar_load);
SWITCH_MODULE_DEFINITION
(
mod_sonar
,
mod_sonar_load
,
mod_sonar_shutdown
,
NULL
);
SWITCH_MODULE_DEFINITION
(
mod_sonar
,
mod_sonar_load
,
mod_sonar_shutdown
,
NULL
);
switch_time_t
start
,
end
,
diff
;
switch_time_t
start
,
end
,
diff
;
int
samples
[
1024
];
int
received
;
int
sum
,
min
,
max
=
0
;
switch_bool_t
sonar_ping_callback
(
switch_core_session_t
*
session
,
const
char
*
app
,
const
char
*
app_data
){
switch_bool_t
sonar_ping_callback
(
switch_core_session_t
*
session
,
const
char
*
app
,
const
char
*
app_data
){
if
(
end
)
{
if
(
end
)
{
return
SWITCH_TRUE
;
return
SWITCH_TRUE
;
}
}
end
=
switch_time_now
();
end
=
switch_time_now
();
diff
=
end
-
start
;
diff
=
end
-
start
;
start
=
0
;
start
=
0
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Sonar ping took %ld milliseconds
\n
"
,
(
long
)
diff
/
1000
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Sonar ping took %ld milliseconds
\n
"
,
(
long
)
diff
/
1000
);
diff
/=
1000
;
sum
+=
diff
;
max
=
MAX
(
max
,
diff
);
min
=
MIN
(
min
,
diff
);
samples
[
received
++
]
=
diff
;
return
SWITCH_TRUE
;
return
SWITCH_TRUE
;
}
}
...
@@ -72,6 +89,9 @@ SWITCH_STANDARD_APP(sonar_app)
...
@@ -72,6 +89,9 @@ SWITCH_STANDARD_APP(sonar_app)
char
*
tone
=
"%(500,0,1004)"
;
char
*
tone
=
"%(500,0,1004)"
;
const
char
*
arg
=
(
char
*
)
data
;
const
char
*
arg
=
(
char
*
)
data
;
int
loops
;
int
loops
;
int
lost
=
0
;
int
x
;
int
avg
=
0
,
mdev
=
0
;
if
(
zstr
(
arg
))
{
if
(
zstr
(
arg
))
{
loops
=
5
;
loops
=
5
;
...
@@ -81,6 +101,8 @@ SWITCH_STANDARD_APP(sonar_app)
...
@@ -81,6 +101,8 @@ SWITCH_STANDARD_APP(sonar_app)
if
(
loops
<
0
)
{
if
(
loops
<
0
)
{
loops
=
5
;
loops
=
5
;
}
else
if
(
loops
>
1024
)
{
loops
=
1024
;
}
}
switch_channel_answer
(
channel
);
switch_channel_answer
(
channel
);
...
@@ -93,18 +115,45 @@ SWITCH_STANDARD_APP(sonar_app)
...
@@ -93,18 +115,45 @@ SWITCH_STANDARD_APP(sonar_app)
switch_ivr_sleep
(
session
,
1000
,
SWITCH_FALSE
,
NULL
);
switch_ivr_sleep
(
session
,
1000
,
SWITCH_FALSE
,
NULL
);
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
received
=
0
;
sum
=
0
;
max
=
0
;
min
=
999999
;
for
(
x
=
0
;
x
<
loops
;
x
++
)
{
end
=
0
;
end
=
0
;
start
=
switch_time_now
();
start
=
switch_time_now
();
switch_ivr_gentones
(
session
,
tone
,
1
,
NULL
);
switch_ivr_gentones
(
session
,
tone
,
1
,
NULL
);
switch_ivr_sleep
(
session
,
2000
,
SWITCH_FALSE
,
NULL
);
switch_ivr_sleep
(
session
,
2000
,
SWITCH_FALSE
,
NULL
);
if
(
start
)
{
if
(
start
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Lost sonar ping
\n
"
);
lost
++
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"Lost sonar ping
\n
"
);
}
}
}
}
switch_ivr_sleep
(
session
,
1000
,
SWITCH_FALSE
,
NULL
);
switch_ivr_sleep
(
session
,
1000
,
SWITCH_FALSE
,
NULL
);
switch_ivr_stop_tone_detect_session
(
session
);
switch_ivr_stop_tone_detect_session
(
session
);
if
(
loops
==
lost
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Too bad, we lost all!
\n
"
);
return
;
}
if
(
received
+
lost
!=
loops
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Race happend %d + %d != %d
\n
"
,
received
,
lost
,
loops
);
}
if
(
received
>
0
)
avg
=
sum
/
received
;
sum
=
0
;
for
(
x
=
0
;
x
<
received
;
x
++
)
{
sum
+=
(
samples
[
x
]
-
avg
)
*
(
samples
[
x
]
-
avg
);
}
if
(
received
>
1
)
{
mdev
=
sqrt
(
sum
/
(
received
-
1
));
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"SONAR: min:%d max:%d avg:%d mdev:%d sent:%d recv: %d lost:%d lost/send:%2.2f%%
\n
"
,
min
,
max
,
avg
,
mdev
,
loops
,
received
,
lost
,
lost
*
1
.
0
/
loops
);
}
}
/* Macro expands to: switch_status_t mod_sonar_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
/* Macro expands to: switch_status_t mod_sonar_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论