summaryrefslogtreecommitdiff
path: root/zttest.c
diff options
context:
space:
mode:
authortzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-09-08 00:45:41 +0000
committertzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-09-08 00:45:41 +0000
commit77d4e30e83958f97ecd58e9a5c67280cc72114b0 (patch)
tree0c3d76ad59d2f3c1bc4dc4aebb4402dfced0872b /zttest.c
parent32bd02693b852a1a2214bf0c1380e101c0b183e1 (diff)
* Improve accuracy of zttest by using floats (#10312).
* Account only for the time of actually waiting for the clock. * Clarify message for zttest -v . * Don't print some digits that are not meaningful enough. git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@2995 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'zttest.c')
-rw-r--r--zttest.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/zttest.c b/zttest.c
index 5045c75..350d7ee 100644
--- a/zttest.c
+++ b/zttest.c
@@ -13,12 +13,14 @@
static int pass = 0;
static float best = 0.0;
static float worst = 100.0;
-static float total = 0.0;
+static double total = 0.0;
+static double delay_total = 0.0;
void hup_handler(int sig)
{
printf("\n--- Results after %d passes ---\n", pass);
- printf("Best: %f -- Worst: %f -- Average: %f\n", best, worst, pass ? total/pass : 100.00);
+ printf("Best: %.3f -- Worst: %.3f -- Average: %f, Difference: %f\n",
+ best, worst, pass ? total/pass : 100.00, pass ? delay_total/pass : 100);
exit(0);
}
@@ -28,11 +30,11 @@ int main(int argc, char *argv[])
int res;
int count=0;
int seconds;
- int ms;
int curarg = 1;
int verbose=0;
char buf[8192];
float score;
+ float ms;
struct timeval start, now;
fd = open("/dev/zap/pseudo", O_RDWR);
if (fd < 0) {
@@ -54,31 +56,38 @@ int main(int argc, char *argv[])
for (count = 0;count < 4; count++)
res = read(fd, buf, sizeof(buf));
count = 0;
- gettimeofday(&start, NULL);
if (seconds > 0)
alarm(seconds + 1);
for(;;) {
+ if (count == 0)
+ ms = 0;
+ gettimeofday(&start, NULL);
res = read(fd, buf, sizeof(buf));
if (res < 0) {
fprintf(stderr, "Failed to read from pseudo interface: %s\n", 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) {
- gettimeofday(&now, NULL);
- ms = (now.tv_sec - start.tv_sec) * 8000;
- ms += (now.tv_usec - start.tv_usec) / 125;
- start = now;
+ double percent;
+
+ percent = 100.0 * (count - ms) / count;
if (verbose)
- printf("\n%d samples in %d sample intervals ", count, ms);
+ printf("\n%d zaptel samples in %0.3f system clock sample intervals (%.3f%%)",
+ count, ms, 100 - percent);
else if ((pass % 8) == 7) printf("\n");
- score = 100.0 - 100.0 * fabs((float)count - (float)ms) / (float)count;
+ score = 100.0 - fabs(percent);
if (score > best)
best = score;
if (score < worst)
worst = score;
- printf("%f%% ", score);
+ if (!verbose)
+ printf("%f%% ", score);
total += score;
+ delay_total += 100 - percent;
fflush(stdout);
count = 0;
pass++;