我是靠谱客的博主 震动小兔子,这篇文章主要介绍dahdi_tools 分析(三)dahdi_testdahdi_tools 分析(三)dahdi_test,现在分享给大家,希望可以做个参考。

dahdi_tools 分析(三)dahdi_test

dahdi_test 的使用

复制代码
1
2
3
4
5
6
7
8
9
10
# dahdi_test -h Usage: dahdi_test [-c COUNT] [-v] Valid options are: -c COUNT Run just COUNT cycles (otherwise: forever). -v More verbose output. -h This help text.

示例:

复制代码
1
2
3
4
5
6
7
8
# dahdi_test Opened pseudo dahdi interface, measuring accuracy... 97.888% 97.881% 97.891% 97.884% 97.883% 97.878% 97.895% 97.884% 97.878% ^C --- Results after 9 passes --- Best: 97.895% -- Worst: 97.878% -- Average: 97.884602% Cummulative Accuracy (not per pass): 97.885

代码分析

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
static double calculate_accuracy(double count, double ms) { return ((count - _fmin(count, fabs(count - ms))) / count) * 100.0; } int main(int argc, char *argv[]) { int fd; int res; int c; int count = 0; int seconds = 0; int curarg = 1; char buf[8192]; float ms; struct timeval start, now; fd = open("/dev/dahdi/pseudo", O_RDWR); // 打开/dev/dahdi/pseudo if (fd < 0) { fprintf(stderr, "Unable to open dahdi interface: %sn", strerror(errno)); exit(1); } for (;;) { if (count == 0) ms = 0; gettimeofday(&start, NULL); // 计时开始 res = read(fd, buf, sizeof(buf)); // 读取 8192 字节数据 if (res < 0) { fprintf(stderr, "Failed to read from pseudo interface: %sn", strerror(errno)); exit(1); } count += res; gettimeofday(&now, NULL); // 计时结束 ms += (now.tv_sec - start.tv_sec) * 8000; ms += (now.tv_usec - start.tv_usec) / 125.0; if (count >= SIZE) { const double percent = calculate_accuracy(count, ms); if (verbose) { printf("n%d samples in %0.3f system clock sample intervals (%.3f%%)", count, ms, percent); } else if (pass > 0 && (pass % 8) == 0) { printf("n"); } if (percent > best) best = percent; if (percent < worst) worst = percent; if (!verbose) printf("%.3f%% ", percent); total += percent; fflush(stdout); total_count += count; total_time += ms; count = 0; pass++; } }

代码大意是,每次读取从 /dev/dahdi/pseudo 中读取 8192 字节数据,并记录花了多长时间假设 x 秒,然后计算 x 时间里真正产生的数据 y = 采样率 8000 * x 。

计算 8192 / y 的百分比值。比值越接近于 100% 说明,系统性能越好。

思考

1.为什么不能达到100% ?

个人理解是 read 的过程还涉及系统调用,系统调用花费额外的时间,所以再强大的cpu 也不可能达到100%。

最后

以上就是震动小兔子最近收集整理的关于dahdi_tools 分析(三)dahdi_testdahdi_tools 分析(三)dahdi_test的全部内容,更多相关dahdi_tools内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部