2 ======================================================================
3 Copyright (c) 2019 Nokia
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions andlimitations under the License.
17 ======================================================================
33 //array to save ts for each transaction
34 time_t ts_array[MAX_TRANS];
35 //array to save tns for each transaction
36 long int tns_array[MAX_TRANS];
37 //array to save latency for each transaction
38 double latency_array[MAX_TRANS]={0};
39 //array to save time passed for each transaction
40 double elapse_array[MAX_TRANS]={0};
41 //array to save typeid for each transaction
42 int type_array[MAX_TRANS]={0};
44 //they are used to track time in order to get msg rate
46 long int tns_start_rcv;
48 int main( int argc, char** argv ) {
51 char* proto_port = "tcp:4560";
52 uta_mbuf_t* msg = NULL;
59 double total_ms_delta = 0.0;
60 double ave_latency = 0.0;
61 double rcv_rate = 0.0;
62 long long rcv_count = 0;
64 if((mr = uta_init( proto_port,
65 UTA_MAX_RCV_BYTES, UTAFL_NONE )) == NULL) {
67 "abort: unable to initialize the message lib: %s\n",
72 while(rcv_count <= MAX_RCV_COUNT) {
74 msg = uta_rcv_msg(mr, msg);
77 type_array[rcv_count] = msg->mtype;
78 pm = (msg_t *) msg->payload;
79 clock_gettime(CLOCK_REALTIME, &ts);
80 //record the time when the first msg is recieved
82 ts_start_rcv = ts.tv_sec;
83 tns_start_rcv = ts.tv_nsec;
86 delta = (ts.tv_sec - (pm->ts).tv_sec) * 1000000000 +
87 ts.tv_nsec - (pm->ts).tv_nsec;
89 ms_delta = (double) delta / 1000000;
90 elapse = (ts.tv_sec - ts_start_rcv) * 1000000000
91 + ts.tv_nsec - tns_start_rcv;
92 ms_elapse = (double) elapse / 1000000;
93 elapse_array[rcv_count] = ms_elapse;
94 total_ms_delta += ms_delta;
95 latency_array[rcv_count] = ms_delta;
100 //when test ends dump memory into file
101 total_ms_delta -= latency_array[rcv_count - 1];
102 ms_elapse = elapse_array[rcv_count - 2];
104 ave_latency = total_ms_delta/rcv_count;
105 rcv_rate = (rcv_count/ms_elapse)*1000.0;
107 snprintf(fname, sizeof fname, "report/xAPP_counters.csv");
108 FILE *fptr = fopen(fname, "w");
109 fprintf(fptr, "average latency %.3fmillisec\n", ave_latency);
110 for(int i = 0; i < rcv_count; i++)
111 fprintf(fptr, "%d %.3fmillisec \n", i, latency_array[i]);