00001 extern "C"
00002 {
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 }
00006
00007 #include "perftype.hh"
00008 #include "rcs_prnt.hh"
00009 #include "cms.hh"
00010 #include "nml.hh"
00011
00012 unsigned int real_test_msg_size = 0;
00013 unsigned int test_msg_buffer_size = 0;
00014 void *test_msg_buffer = NULL;
00015
00016
00017
00018
00019 static void
00020 corrected_free (void *ptr)
00021 {
00022 #ifdef sparcworks_sun4
00023 free ((char *) ptr);
00024 #else
00025 free (ptr);
00026 #endif
00027 }
00028
00029 int
00030 perf_types_format (NMLTYPE type, void *buffer, CMS * cms)
00031 {
00032 switch (type)
00033 {
00034 case NML_PERFORMANCE_TEST_MSG_TYPE:
00035 ((NML_PERFORMANCE_TEST_MSG *) buffer)->update (cms);
00036 break;
00037 default:
00038 rcs_print_error ("perf_types_format: Unknown Type.(%d) (mode = %d)\n",
00039 type, cms->mode);
00040 return (-1);
00041 }
00042 return (0);
00043 }
00044
00045
00046 void
00047 NML_PERFORMANCE_TEST_MSG::update (CMS * cms)
00048 {
00049 cms->update (serial_number);
00050 cms->update (test_type);
00051 cms->update (array_length);
00052 switch (test_type)
00053 {
00054 case CHAR_TEST:
00055 cms->update (&char_data, (array_length > 0) ? array_length : 1);
00056 break;
00057 case SHORT_TEST:
00058 cms->update (&short_data, (array_length > 0) ? array_length : 1);
00059 break;
00060 case INT_TEST:
00061 cms->update (&int_data, (array_length > 0) ? array_length : 1);
00062 break;
00063 case LONG_TEST:
00064 cms->update (&long_data, (array_length > 0) ? array_length : 1);
00065 break;
00066 case FLOAT_TEST:
00067 cms->update (&float_data, (array_length > 0) ? array_length : 1);
00068 break;
00069 case DOUBLE_TEST:
00070 cms->update (&double_data, (array_length > 0) ? array_length : 1);
00071 break;
00072 }
00073 }
00074
00075 void
00076 NML_PERFORMANCE_TEST_MSG::compute_array_length ()
00077 {
00078 long array_unit_size, base_size, org_size;
00079 org_size = size;
00080
00081 switch (test_type)
00082 {
00083 case CHAR_TEST:
00084 array_unit_size = sizeof (char);
00085 break;
00086 case SHORT_TEST:
00087 array_unit_size = sizeof (short);
00088 break;
00089 case INT_TEST:
00090 array_unit_size = sizeof (int);
00091 break;
00092 case LONG_TEST:
00093 array_unit_size = sizeof (long);
00094 break;
00095 case FLOAT_TEST:
00096 array_unit_size = sizeof (float);
00097 break;
00098 case DOUBLE_TEST:
00099 array_unit_size = sizeof (double);
00100 break;
00101 default:
00102 rcs_print_error ("PERFTYPE: Invalid test type. (%ld)\n", test_type);
00103 array_unit_size = 1;
00104 break;
00105 }
00106 base_size = sizeof (NML_PERFORMANCE_TEST_MSG) - sizeof (double);
00107 array_length = (size - base_size) / array_unit_size;
00108 if (array_length > 0)
00109 {
00110 size = array_length * array_unit_size + base_size;
00111 }
00112 else
00113 {
00114 rcs_print_error
00115 ("NML_PERFORMANCE_TEST_MSG::compute_array_length() - array_length <= 0\n");
00116 }
00117 }
00118
00119 void *
00120 NML_PERFORMANCE_TEST_MSG::operator new (size_t size)
00121 {
00122 if (test_msg_buffer_size > size && test_msg_buffer_size > real_test_msg_size
00123 && test_msg_buffer != NULL)
00124 {
00125 return test_msg_buffer;
00126 }
00127 if (test_msg_buffer != NULL)
00128 {
00129 corrected_free (test_msg_buffer);
00130 test_msg_buffer = NULL;
00131 }
00132 if (real_test_msg_size > size)
00133 {
00134 test_msg_buffer_size = real_test_msg_size;
00135 return (test_msg_buffer = calloc (real_test_msg_size, 1));
00136 }
00137 test_msg_buffer_size = size;
00138 return (test_msg_buffer = calloc (size, 1));
00139 }
00140
00141 void
00142 NML_PERFORMANCE_TEST_MSG::operator delete (void *ptr)
00143 {
00144 if (ptr != test_msg_buffer && ptr != NULL)
00145 {
00146 corrected_free (ptr);
00147 }
00148 }
00149
00150 void
00151 delete_test_msg_buffer ()
00152 {
00153 if (NULL != test_msg_buffer)
00154 {
00155 corrected_free (test_msg_buffer);
00156 test_msg_buffer = NULL;
00157 }
00158 }
00159
00160 void
00161 set_real_test_msg_size (long size)
00162 {
00163 real_test_msg_size = size;
00164 }