forked from YogeshJangir/token-bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken-statistics.c
More file actions
98 lines (95 loc) · 2.9 KB
/
Copy pathtoken-statistics.c
File metadata and controls
98 lines (95 loc) · 2.9 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// warmup2-statistics.c
// Warmup2-new
//
// Created by Abhishek Trigunayat on 6/14/14.
// Copyright (c) 2014 Abhishek Trigunayat. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "mylist.h"
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
#include "token.h"
#include <signal.h>
#include <math.h>
void display_statistics(){
struct timeval current_time;
gettimeofday(¤t_time, NULL);
float temp = calculate_time_difference(current_time,emulation_start_time);
printf("%012.3fms: emulation ends\n",temp);
pthread_mutex_lock(&mutex);
//printf("Total Q1 : %f\n",average_number_of_packets_in_Q1);
//printf("Total Q2 : %f\n",average_number_of_packets_in_Q2);
average_number_of_packets_in_Q1 = average_number_of_packets_in_Q1 / temp;
average_number_of_packets_in_Q2 = average_number_of_packets_in_Q2 / temp;
average_number_of_packets_at_S = average_number_of_packets_at_S / temp;
printf("\nStatistics:\n\n");
printf(" average packet inter-arrival time = ");
if(average_packet_inter_arrival_time >= 0.0){
printf("%f\n",average_packet_inter_arrival_time / 1000.0);
}
else {
printf("N/A\n");
}
printf(" average packet service time = ");
if(average_packet_service_time >= 0.0){
printf("%f\n\n",average_packet_service_time / 1000.0);
}
else {
printf("N/A\n\n");
}
printf(" average number of packets in Q1 = ");
if(average_number_of_packets_in_Q1 >= 0.0){
printf("%f\n",average_number_of_packets_in_Q1);
}
else {
printf("N/A\n");
}
printf(" average number of packets in Q2 = ");
if(average_number_of_packets_in_Q2 >= 0.0){
printf("%f\n",average_number_of_packets_in_Q2);
}
else {
printf("N/A\n");
}
printf(" average number of packets in S = ");
if(average_number_of_packets_at_S >= 0.0){
printf("%f\n\n",average_number_of_packets_at_S);
}
else {
printf("N/A\n\n");
}
printf(" average time a packet spent in system = ");
if(average_time_a_packet_spent_in_system >= 0.0){
printf("%f\n",average_time_a_packet_spent_in_system / 1000.0);
}
else {
printf("N/A\n");
}
printf(" standard deviation for the time spent in system = ");
if(standard_deviation_for_time_spent_in_system >= 0.0){
printf("%f\n\n",standard_deviation_for_time_spent_in_system / 1000.0);
}
else {
printf("N/A\n\n");
}
printf(" token drop probability = ");
if(token_drop_probability >= 0.0){
printf("%f\n",token_drop_probability);
}
else {
printf("N/A\n");
}
printf(" packet drop probability = ");
if(packet_drop_probability >= 0.0){
printf("%f\n",packet_drop_probability);
}
else {
printf("N/A\n");
}
pthread_mutex_unlock(&mutex);
}