Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

nmlperf.cc

Go to the documentation of this file.
00001 
00002 /* Program Name to print at startup. */
00003 #ifndef __GNUC__
00004 #ifndef __attribute__
00005 #define __attribute__(x)
00006 #endif
00007 #endif
00008 
00009 
00010 static char __attribute__ ((unused)) program_id[] =
00011   "nmlperf compiled on " __DATE__;
00012 
00013 #include "rcs_defs.hh"          /*  EXTERN_C_STD_HEADERS  */
00014 
00015 #if defined(SUN) || defined(LINUX)
00016 #define USE_TIMES_FUNCTION
00017 #else
00018 #define USE_CLOCK_FUNCTION
00019 #endif
00020 
00021 #ifdef  EXTERN_C_STD_HEADERS
00022 extern "C"
00023 {
00024 #endif
00025 #include <stdlib.h>             /* exit() */
00026 #include <string.h>             /* strcmp() */
00027 #include <signal.h>             /* SIGINT, signal */
00028 
00029 #if defined(V5_2) || defined(V5_1)
00030 #include <types.h>
00031 #include <types/vxTypesOld.h>
00032 #endif
00033 
00034 #include <time.h>               // clock()
00035 #ifdef USE_TIMES_FUNCTION
00036 #include <sys/times.h>          // times()
00037 #endif
00038 #ifndef VXWORKS
00039 #include <limits.h>
00040 #endif
00041 
00042 
00043 #ifdef  EXTERN_C_STD_HEADERS
00044 }
00045 #endif
00046 
00047 #include "rcs.hh"               /* NML,  */
00048 #include "dbg_mem.h"            // DEBUG_MALLOC, DEBUG_FREE
00049 #include "perftype.hh"          /* perf_type_format, */
00050                                 /* NML_PERFORMANCE_TEST_MSG */
00051 
00052 
00053 void
00054 clean_string (char *str, int len)
00055 {
00056   if (NULL == str)
00057     {
00058       return;
00059     }
00060   if (len > 1024)
00061     {
00062       return;
00063     }
00064   str[len - 1] = 0;
00065   char *temp = (char *) malloc (len);
00066   memset (temp, 0, len);
00067   char *t = temp;
00068   char *s = str;
00069   char c = *s;
00070   while (c != 0)
00071     {
00072       if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
00073         {
00074           *t = c;
00075           t++;
00076         }
00077       s++;
00078       c = *s;
00079     }
00080   strcpy (str, temp);
00081   free (temp);
00082 }
00083 
00084 
00085 enum DISPLAY_MODE
00086 {
00087   INVALID_DISPLAY_MODE,
00088   BYTES_PER_SEC_MODE,
00089   MSG_PER_SEC_MODE
00090 };
00091 
00092 
00093 enum CONNECT_STATUS
00094 {
00095   CS_NOT_ATTEMPTED = 0,
00096   CS_FAILED,
00097   CS_SUCCEEDED
00098 };
00099 
00100 char CS_ARRAY[3][3] = { "NA", "F", "S" };
00101 static unsigned char nmlperf_stop_flag = 0;
00102 
00103 void
00104 nmlperf_stop ()
00105 {
00106   nmlperf_stop_flag = 1;
00107 }
00108 
00109 
00110 int nml_perf_read_test (NML *);
00111 int nml_perf_write_test (NML *, int message_size);
00112 int nml_perf_combined_test (NML *, int message_size);
00113 
00114 int nmlperf_control_c_count = 0;
00115 void
00116 control_c_handler (int sig)
00117 {
00118   nmlperf_control_c_count++;
00119 }
00120 
00121 long nmlperf_max_message_count = -1;
00122 double nmlperf_min_cycle_time = -1.0;
00123 
00124 
00125 #if  defined(VXWORKS) || defined(WINDOWS_GUI)
00126 extern "C"
00127 {
00128   int nmlperf ();
00129   int nmlperf_go (int priority);
00130 }
00131 
00132 #ifdef VXWORKS
00133 #include "taskLib.h"
00134 int nmlperf_def_iterations = 1000;
00135 char *nmlperf_def_timeout = "0.1";
00136 
00137 
00138 int
00139 nmlperf_go (int priority)
00140 {
00141   return taskSpawn ("tNmlperf", priority, VX_FP_TASK, 0x4000,
00142                     (FUNCPTR) nmlperf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
00143 }
00144 
00145 #endif
00146 
00147 char *nmlperf_config_file = "test.nml";
00148 char *nmlperf_buffer_name = "testbuf";
00149 char *nmlperf_proc_name = "nmlperf";
00150 char *nmlperf_test_type = "C";
00151 long nmlperf_message_size = 100;
00152 
00153 int
00154 nmlperf ()
00155 #else
00156 int
00157 main (int argc, char **argv)
00158 #endif
00159 {
00160   NML *nml = NULL;
00161 #if  !defined(VXWORKS) && !defined(WINDOWS_GUI)
00162   char config_file[CMS_CONFIG_LINELEN];
00163   char buffer_name[CMS_CONFIG_LINELEN];
00164   char proc_name[CMS_CONFIG_LINELEN];
00165   char test_type[20];
00166   char message_size_string[20];
00167   unsigned long message_size;
00168 #else
00169   char *config_file = nmlperf_config_file;
00170   char *buffer_name = nmlperf_buffer_name;
00171   char *proc_name = nmlperf_proc_name;
00172   char *test_type = nmlperf_test_type;
00173   long message_size = nmlperf_message_size;
00174 
00175 #endif
00176   char count_string[20];
00177 
00178 
00179   set_rcs_print_destination (RCS_PRINT_TO_STDOUT);
00180   rcs_errors_printed = 0;
00181   if (max_rcs_errors_to_print < 40)
00182     {
00183       max_rcs_errors_to_print = 40;
00184     }
00185 
00186   rcs_print ("\nNML Performance Testing Program\n");
00187 #if  !defined(VXWORKS) && !defined(WINDOWS_GUI)
00188   rcs_print ("Configuration File? (test.nml) ");
00189   fgets (config_file, CMS_CONFIG_LINELEN, stdin);
00190   clean_string (config_file, CMS_CONFIG_LINELEN);
00191   if (strlen (config_file) < 2)
00192     {
00193       strcpy (config_file, "test.nml");
00194     }
00195   rcs_print ("Buffer Name? (testbuf) ");
00196   fgets (buffer_name, CMS_CONFIG_LINELEN, stdin);
00197   clean_string (buffer_name, CMS_CONFIG_LINELEN);
00198   if (strlen (buffer_name) < 2)
00199     {
00200       strcpy (buffer_name, "testbuf");
00201     }
00202   rcs_print ("Process Name? (nmlperf) ");
00203   fgets (proc_name, CMS_CONFIG_LINELEN, stdin);
00204   clean_string (proc_name, CMS_CONFIG_LINELEN);
00205   if (strlen (proc_name) < 2)
00206     {
00207       strcpy (proc_name, "nmlperf");
00208     }
00209   rcs_print ("Maximum Message Count (Infinite) ?");
00210   fgets (count_string, 20, stdin);
00211   clean_string (count_string, 20);
00212   if (count_string[0] > '0' && count_string[0] <= '9')
00213     {
00214       errno = 0;
00215       nmlperf_max_message_count = strtol (count_string, NULL, 0);
00216       if (errno != 0)
00217         {
00218           nmlperf_max_message_count = -1;
00219         }
00220     }
00221 #endif
00222 
00223   nml = new NML (perf_types_format, buffer_name, proc_name, config_file);
00224   if (NULL == nml)
00225     {
00226       exit (-1);
00227     }
00228   if (!nml->valid ())
00229     {
00230       delete nml;
00231       exit (-1);
00232     }
00233 
00234 
00235 #if  !defined(VXWORKS) && !defined(WINDOWS_GUI)
00236   rcs_print ("\n \tThere are 3 different tests that can be performed.\n");
00237   rcs_print
00238     ("The Read test only reads from the buffer, unless the write test is run is also run there will be no new data available for the read.\n");
00239   rcs_print ("The Write test only writes to the buffer.\n");
00240   rcs_print ("The Combined test alternates reads and writes.\n");
00241   rcs_print ("Test Type ( R = Read, W = Write, C = Combined)?\n");
00242   fgets (test_type, 20, stdin);
00243   clean_string (test_type, 20);
00244 #endif
00245   switch (test_type[0])
00246     {
00247     case 'w':
00248     case 'W':
00249 #if  !defined(VXWORKS) && !defined(WINDOWS_GUI)
00250       rcs_print ("Message Size?");
00251       fgets (message_size_string, 20, stdin);
00252       clean_string (message_size_string, 20);
00253       message_size = strtol (message_size_string, NULL, 0);
00254 #endif
00255       nml_perf_write_test (nml, message_size);
00256       break;
00257 
00258 
00259     case 'c':
00260     case 'C':
00261 #if  !defined(VXWORKS) && !defined(WINDOWS_GUI)
00262       rcs_print ("Message Size?");
00263       fgets (message_size_string, 20, stdin);
00264       clean_string (message_size_string, 20);
00265       message_size = strtol (message_size_string, NULL, 0);
00266 #endif
00267       nml_perf_combined_test (nml, message_size);
00268       break;
00269 
00270 
00271     case 'r':
00272     case 'R':
00273       nml_perf_read_test (nml);
00274       break;
00275 
00276     default:
00277       rcs_print_error ("Invalid test type.\n");
00278     }
00279 
00280   delete nml;
00281   exit (-1);
00282 }
00283 
00284 int
00285 nml_perf_write_test (NML * nml, int message_size)
00286 {
00287 #ifdef USE_TIMES_FUNCTION
00288   struct tms tms_buffer;
00289 #endif
00290 
00291   double start_time;
00292   double end_time;
00293   int data_type = 0;
00294 
00295   clock_t cpu_used_start_time;
00296   clock_t cpu_used_end_time;
00297   double total_cpu_time_used;
00298   double total_time_used;
00299   double last_time;
00300   double max_time = 0;
00301   double min_time = 1E6;
00302   double cur_time = 0;
00303   double time_dif = 0;
00304   NML_PERFORMANCE_TEST_MSG *test_msg = NULL;
00305   rcs_print ("NML Write Only Performance Test\n");
00306   set_real_test_msg_size (message_size);
00307   test_msg = new NML_PERFORMANCE_TEST_MSG ();
00308   test_msg->size = message_size;
00309   nmlperf_control_c_count = 0;
00310   signal (SIGINT, control_c_handler);
00311   rcs_print ("Press ^C to end the test.\n");
00312   long messages_written = 0;
00313 
00314 #ifdef USE_CLOCK_FUNCTION
00315   cpu_used_start_time = clock ();
00316   rcs_print (" \tclock() = %d\n", cpu_used_start_time);
00317 #endif
00318 
00319 #ifdef USE_TIMES_FUNCTION
00320   times (&tms_buffer);
00321   cpu_used_start_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00322   rcs_print
00323     (" \ttimes(&tms_buffer) \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00324      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00325      tms_buffer.tms_cstime);
00326 #endif
00327 
00328 
00329   cur_time = last_time = start_time = etime ();
00330   RCS_TIMER *timer = NULL;
00331   if (nmlperf_min_cycle_time > 1e-6)
00332     {
00333       timer = new RCS_TIMER (nmlperf_min_cycle_time);
00334     }
00335   int errors = 0;
00336 
00337   while (nmlperf_control_c_count == 0)
00338     {
00339       data_type++;
00340       data_type = data_type % 6;
00341       test_msg->test_type = data_type;
00342       test_msg->serial_number = messages_written;
00343       test_msg->compute_array_length ();
00344       if (messages_written < 6 && errors < 6)
00345         {
00346           rcs_print ("Test type %d: array length %d; size %d\n",
00347                      test_msg->test_type, test_msg->array_length,
00348                      test_msg->size);
00349         }
00350       if (nml->write (test_msg) < 0)
00351         {
00352           errors++;
00353         }
00354       else
00355         {
00356           messages_written++;
00357         }
00358       cur_time = etime ();
00359       time_dif = cur_time - last_time;
00360       if (time_dif > max_time)
00361         {
00362           max_time = time_dif;
00363         }
00364       if (time_dif < min_time)
00365         {
00366           min_time = time_dif;
00367         }
00368       last_time = cur_time;
00369       if (nmlperf_max_message_count > 0)
00370         {
00371           if (nmlperf_max_message_count < messages_written)
00372             {
00373               break;
00374             }
00375         }
00376       if (nmlperf_min_cycle_time > 1e-6)
00377         {
00378           timer->wait ();
00379         }
00380     }
00381 
00382   end_time = etime ();
00383 
00384 #ifdef USE_CLOCK_FUNCTION
00385   cpu_used_end_time = clock ();
00386   rcs_print (" \tclock() = %d\n", cpu_used_end_time);
00387 #endif
00388 
00389 #ifdef USE_TIMES_FUNCTION
00390   times (&tms_buffer);
00391   cpu_used_end_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00392   rcs_print
00393     (" \ttimes(&tms_buffer): \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00394      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00395      tms_buffer.tms_cstime);
00396 #endif
00397 
00398 #ifndef USE_CLOCK_FUNCTION
00399   total_cpu_time_used =
00400     (cpu_used_end_time - cpu_used_start_time) * clk_tck ();
00401 #else
00402   total_cpu_time_used =
00403     (cpu_used_end_time - cpu_used_start_time) / CLOCKS_PER_SEC;
00404 #endif
00405   total_time_used = end_time - start_time;
00406 
00407   rcs_print ("The test took %f seconds in real time  \n", total_time_used);
00408   if (total_cpu_time_used > 0)
00409     {
00410       rcs_print (" and used %f seconds of CPU time.\n", total_cpu_time_used);
00411     }
00412 
00413   rcs_print ("%d messages were written.\n", messages_written);
00414   rcs_print ("Message Size:%d\n", message_size);
00415   if (total_time_used > 0)
00416     {
00417       rcs_print ("Bytes written per second : %f\n",
00418                  message_size * messages_written / total_time_used);
00419     }
00420   if (errors > 0)
00421     {
00422       rcs_print ("%d errors occurred.\n", errors);
00423     }
00424   if (total_time_used > 0.0)
00425     {
00426       rcs_print ("Messages written per second: %f\n",
00427                  messages_written / total_time_used);
00428     }
00429   rcs_print ("Minimum time to write a message = %f\n", min_time);
00430   rcs_print ("Maximum time to write a message = %f\n", max_time);
00431   if (messages_written > 0)
00432     {
00433       rcs_print ("Average time to write a message = %f\n",
00434                  total_time_used / messages_written);
00435       if (total_cpu_time_used > 0)
00436         {
00437           rcs_print ("Average CPU time used to write a message = %f\n",
00438                      total_cpu_time_used / messages_written);
00439         }
00440     }
00441   rcs_print ("BufferLine: %s", nml->cms->BufferLine);
00442   rcs_print ("ProcessLine: %s\n", nml->cms->ProcessLine);
00443   return 0;
00444 }
00445 
00446 
00447 
00448 
00449 int
00450 nml_perf_combined_test (NML * nml, int message_size)
00451 {
00452   NML *nml2 = new NML (nml, -1, -1);    /* Make a clone of the original nml channel but with
00453                                            separate socket sessions, local buffers, and status
00454                                            variables. */
00455 
00456 #ifdef USE_TIMES_FUNCTION
00457   struct tms tms_buffer;
00458 #endif
00459 
00460   double start_time;
00461   double end_time;
00462   int data_type = 0;
00463   clock_t cpu_used_start_time;
00464   clock_t cpu_used_end_time;
00465   double total_cpu_time_used;
00466   double total_time_used;
00467   double last_time;
00468   double max_time = 0;
00469   int latency_count = 0;
00470   double min_time = 1E6;
00471   double cur_time = 0;
00472   double time_dif = 0;
00473   NMLTYPE read_return_value;
00474   long messages_received = 0;
00475   long read_returned_no_new_data_count = 0;
00476   rcs_print ("NML Combined Read/Write Performance Test\n");
00477   NML_PERFORMANCE_TEST_MSG *test_msg = NULL;
00478   set_real_test_msg_size (message_size);
00479   test_msg = new NML_PERFORMANCE_TEST_MSG ();
00480   test_msg->size = message_size;
00481   nmlperf_control_c_count = 0;
00482   signal (SIGINT, control_c_handler);
00483   rcs_print ("Press ^C to end the test.\n");
00484   long messages_written = 0;
00485 
00486 
00487 #ifdef USE_CLOCK_FUNCTION
00488   cpu_used_start_time = clock ();
00489   rcs_print (" \tclock() = %d\n", cpu_used_start_time);
00490 #endif
00491 
00492 #ifdef USE_TIMES_FUNCTION
00493   times (&tms_buffer);
00494   cpu_used_start_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00495   rcs_print
00496     (" \ttimes(&tms_buffer) \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00497      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00498      tms_buffer.tms_cstime);
00499 #endif
00500 
00501 
00502   cur_time = last_time = start_time = etime ();
00503   NML_PERFORMANCE_TEST_MSG *recvd_msg =
00504     (NML_PERFORMANCE_TEST_MSG *) nml2->get_address ();
00505   RCS_TIMER *timer = NULL;
00506   if (nmlperf_min_cycle_time > 1e-6)
00507     {
00508       timer = new RCS_TIMER (nmlperf_min_cycle_time);
00509     }
00510   int errors = 0;
00511 
00512   while (nmlperf_control_c_count == 0)
00513     {
00514       data_type++;
00515       data_type = data_type % 6;
00516       test_msg->test_type = data_type;
00517       test_msg->serial_number = messages_written;
00518       test_msg->compute_array_length ();
00519       if (messages_written < 6 && errors < 6)
00520         {
00521           rcs_print ("Test type %d: array length %d; size %d\n",
00522                      test_msg->test_type, test_msg->array_length,
00523                      test_msg->size);
00524         }
00525       last_time = etime ();
00526       if (nml->write (test_msg) < 0)
00527         {
00528           errors++;
00529         }
00530       else
00531         {
00532           messages_written++;
00533           rcs_errors_printed = 0;
00534         }
00535       cur_time = etime ();
00536       time_dif = cur_time - last_time;
00537       if (time_dif > max_time)
00538         {
00539           max_time = time_dif;
00540         }
00541       if (time_dif < min_time)
00542         {
00543           min_time = time_dif;
00544         }
00545       if (nmlperf_min_cycle_time > 1e-6)
00546         {
00547           timer->wait ();
00548         }
00549       last_time = etime ();
00550       read_return_value = nml2->read ();
00551       if (read_return_value < 0)
00552         {
00553           errors++;
00554         }
00555       if (read_return_value > 0)
00556         {
00557           int serial_difference =
00558             (messages_written - recvd_msg->serial_number);
00559           if (serial_difference > 1)
00560             {
00561               latency_count += (serial_difference - 1);
00562             }
00563           messages_received++;
00564           rcs_errors_printed = 0;
00565         }
00566       else
00567         {
00568           read_returned_no_new_data_count++;
00569         }
00570       cur_time = etime ();
00571       time_dif = cur_time - last_time;
00572       if (time_dif > max_time)
00573         {
00574           max_time = time_dif;
00575         }
00576       if (time_dif < min_time)
00577         {
00578           min_time = time_dif;
00579         }
00580       last_time = cur_time;
00581       if (nmlperf_max_message_count > 0)
00582         {
00583           if (nmlperf_max_message_count <
00584               messages_written + messages_received +
00585               read_returned_no_new_data_count)
00586             {
00587               break;
00588             }
00589         }
00590       if (nmlperf_min_cycle_time > 1e-6)
00591         {
00592           timer->wait ();
00593         }
00594 
00595     }
00596 
00597   end_time = etime ();
00598 
00599 
00600 
00601 #ifdef USE_CLOCK_FUNCTION
00602   cpu_used_end_time = clock ();
00603   rcs_print (" \tclock() = %d\n", cpu_used_end_time);
00604 #endif
00605 
00606 #ifdef USE_TIMES_FUNCTION
00607   times (&tms_buffer);
00608   cpu_used_end_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00609   rcs_print
00610     (" \ttimes(&tms_buffer): \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00611      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00612      tms_buffer.tms_cstime);
00613 #endif
00614 
00615 #ifndef USE_CLOCK_FUNCTION
00616   total_cpu_time_used =
00617     (cpu_used_end_time - cpu_used_start_time) * clk_tck ();
00618 #else
00619   total_cpu_time_used =
00620     (cpu_used_end_time - cpu_used_start_time) / CLOCKS_PER_SEC;
00621 #endif
00622 
00623 
00624   total_time_used = end_time - start_time;
00625 
00626   rcs_print ("The test took %f seconds in real time  \n", total_time_used);
00627   if (total_cpu_time_used > 0)
00628     {
00629       rcs_print (" and used %f seconds of CPU time.\n", total_cpu_time_used);
00630     }
00631 
00632   if (errors > 0)
00633     {
00634       rcs_print ("%d errors occurred.\n", errors);
00635     }
00636 
00637   rcs_print ("%d messages were written.\n", messages_written);
00638   rcs_print ("%d messages were received.\n", messages_received);
00639   if (total_time_used > 0)
00640     {
00641       rcs_print ("Throughput (Messages per Second): %f\n",
00642                  messages_received / total_time_used);
00643     }
00644   rcs_print ("Message Size:%d\n", message_size);
00645   if (total_time_used > 0)
00646     {
00647       rcs_print ("Bytes read per second : %f\n",
00648                  message_size * messages_received / total_time_used);
00649     }
00650   rcs_print ("Read returned No New data %d times.\n",
00651              read_returned_no_new_data_count);
00652   rcs_print ("Minimum time to read or write a message = %f\n", min_time);
00653   rcs_print ("Maximum time to read or write a message = %f\n", max_time);
00654   double avg_time = total_time_used / messages_written / 2.0;
00655   rcs_print ("Average time to read or write a message = %f\n", avg_time);
00656   if (messages_received > 0)
00657     {
00658       rcs_print ("Latency: %f\n",
00659                  latency_count / messages_received * avg_time);
00660     }
00661   else
00662     {
00663       rcs_print ("Latency: Unknown\n");
00664     }
00665 
00666   if (total_cpu_time_used > 0 && messages_written > 0)
00667     {
00668       rcs_print ("Average CPU time used to read/write a message = %f\n",
00669                  total_cpu_time_used / messages_written / 2);
00670     }
00671   rcs_print ("BufferLine: %s", nml->cms->BufferLine);
00672   rcs_print ("ProcessLine: %s\n", nml->cms->ProcessLine);
00673   delete nml2;
00674 
00675 
00676   return 0;
00677 }
00678 
00679 
00680 
00681 int
00682 nml_perf_read_test (NML * nml)
00683 {
00684 #ifdef USE_TIMES_FUNCTION
00685   struct tms tms_buffer;
00686 #endif
00687 
00688   clock_t cpu_used_start_time;
00689   clock_t cpu_used_end_time;
00690   double total_cpu_time_used;
00691 
00692   double start_time;
00693   double end_time;
00694   double total_time_used;
00695   double last_time;
00696   double max_time = 0;
00697   double min_time = 1E6;
00698   double cur_time = 0;
00699   double time_dif = 0;
00700   NMLTYPE read_return_value;
00701   long messages_received = 0;
00702   long read_returned_no_new_data_count = 0;
00703   nmlperf_control_c_count = 0;
00704   rcs_print ("NML Read Only Performance Test\n");
00705   signal (SIGINT, control_c_handler);
00706   rcs_print ("Press ^C to end the test.\n");
00707 
00708 
00709 #ifdef USE_CLOCK_FUNCTION
00710   cpu_used_start_time = clock ();
00711   rcs_print (" \tclock() = %d\n", cpu_used_start_time);
00712 #endif
00713 
00714 #ifdef USE_TIMES_FUNCTION
00715   times (&tms_buffer);
00716   cpu_used_start_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00717   rcs_print
00718     (" \ttimes(&tms_buffer) \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00719      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00720      tms_buffer.tms_cstime);
00721 #endif
00722 
00723   RCS_TIMER *timer = NULL;
00724   if (nmlperf_min_cycle_time > 1e-6)
00725     {
00726       timer = new RCS_TIMER (nmlperf_min_cycle_time);
00727     }
00728   int bytes_received = 0;
00729 
00730   NMLmsg *recvdmsg = nml->get_address ();
00731 
00732   // Throw the first read away for more acuracy.
00733   read_return_value = nml->read ();
00734 
00735   cur_time = last_time = start_time = etime ();
00736 
00737   int errors = 0;
00738 
00739   while (nmlperf_control_c_count == 0)
00740     {
00741       read_return_value = nml->read ();
00742       if (read_return_value < 0)
00743         {
00744           errors++;
00745         }
00746       if (nmlperf_control_c_count != 0)
00747         {
00748           // throw the last read away for more accuracy.
00749           break;
00750         }
00751       if (read_return_value > 0)
00752         {
00753           bytes_received += recvdmsg->size;
00754           messages_received++;
00755         }
00756       else
00757         {
00758           read_returned_no_new_data_count++;
00759         }
00760       cur_time = etime ();
00761       time_dif = cur_time - last_time;
00762       if (time_dif > max_time)
00763         {
00764           max_time = time_dif;
00765         }
00766       if (time_dif < min_time)
00767         {
00768           min_time = time_dif;
00769         }
00770       last_time = cur_time;
00771       if (nmlperf_max_message_count > 0)
00772         {
00773           if (nmlperf_max_message_count < messages_received +
00774               read_returned_no_new_data_count)
00775             {
00776               break;
00777             }
00778         }
00779       if (nmlperf_min_cycle_time > 1e-6)
00780         {
00781           timer->wait ();
00782         }
00783     }
00784 
00785   end_time = etime ();
00786 
00787 
00788 #ifdef USE_CLOCK_FUNCTION
00789   cpu_used_end_time = clock ();
00790   rcs_print (" \tclock() = %d\n", cpu_used_end_time);
00791 #endif
00792 
00793 #ifdef USE_TIMES_FUNCTION
00794   times (&tms_buffer);
00795   cpu_used_end_time = tms_buffer.tms_utime + tms_buffer.tms_stime;
00796   rcs_print
00797     (" \ttimes(&tms_buffer): \ttms_buffer.tms_utime = %d, tms_buffer.tms_stime=%d, tms_buffer.tms_cutime = %d, tms_buffer.tms_cstime=%d\n",
00798      tms_buffer.tms_utime, tms_buffer.tms_stime, tms_buffer.tms_cutime,
00799      tms_buffer.tms_cstime);
00800 #endif
00801 
00802 #ifndef USE_CLOCK_FUNCTION
00803   total_cpu_time_used =
00804     (cpu_used_end_time - cpu_used_start_time) * clk_tck ();
00805 #else
00806   total_cpu_time_used =
00807     (cpu_used_end_time - cpu_used_start_time) / CLOCKS_PER_SEC;
00808 #endif
00809 
00810   total_time_used = end_time - start_time;
00811   rcs_print ("The test took %f seconds in real time  \n", total_time_used);
00812   if (total_cpu_time_used > 0)
00813     {
00814       rcs_print (" and used %f seconds of CPU time.\n", total_cpu_time_used);
00815     }
00816 
00817   if (errors > 0)
00818     {
00819       rcs_print ("%d errors occurred.\n", errors);
00820     }
00821 
00822   rcs_print ("%d messages were received.\n", messages_received);
00823   if (total_time_used > 0.0)
00824     {
00825       rcs_print ("Throughput: %f\n", messages_received / total_time_used);
00826     }
00827   rcs_print ("Bytes received:%d\n", bytes_received);
00828   if (total_time_used > 0)
00829     {
00830       rcs_print ("Bytes read per second : %f\n",
00831                  bytes_received / total_time_used);
00832     }
00833   rcs_print ("Read returned No New data %d times.\n",
00834              read_returned_no_new_data_count);
00835   rcs_print ("Minimum time to call read() = %f\n", min_time);
00836   rcs_print ("Maximum time to call read()  = %f\n", max_time);
00837   rcs_print ("Average time to call_read = %f\n",
00838              total_time_used / (messages_received +
00839                                 read_returned_no_new_data_count));
00840   rcs_print ("Average time between new data received= %f\n",
00841              total_time_used / messages_received);
00842 
00843   if (total_cpu_time_used > 0
00844       && (messages_received + read_returned_no_new_data_count) > 0)
00845     {
00846       rcs_print ("Average CPU time used to call read() = %f\n",
00847                  total_cpu_time_used / (messages_received +
00848                                         read_returned_no_new_data_count));
00849     }
00850   rcs_print ("BufferLine: %s", nml->cms->BufferLine);
00851   rcs_print ("ProcessLine: %s\n", nml->cms->ProcessLine);
00852 
00853   return 0;
00854 }

Generated on Sun Dec 2 15:56:50 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001