diff options
Diffstat (limited to 'tests/CDR/allocator.cpp')
-rw-r--r-- | tests/CDR/allocator.cpp | 229 |
1 files changed, 119 insertions, 110 deletions
diff --git a/tests/CDR/allocator.cpp b/tests/CDR/allocator.cpp index 59feefc454c..87320568722 100644 --- a/tests/CDR/allocator.cpp +++ b/tests/CDR/allocator.cpp @@ -67,133 +67,142 @@ private: int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { - CORBA::ORB_var orb = - CORBA::ORB_init (argc, argv); - - int tss = 0; - int iterations = 500; - int repeat = 100; - int max_fragments = 2048; - int max_fragment_size = 1024; - int max_arguments = 16; - int max_argument_size = 1024; - int quiet = 0; - unsigned int seed = static_cast<unsigned int> (ACE_OS::time(0)); - - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("tn:f:m:s:a:b:r:q")); - int opt; - - while ((opt = get_opt ()) != EOF) + try { - switch (opt) + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + int tss = 0; + int iterations = 500; + int repeat = 100; + int max_fragments = 2048; + int max_fragment_size = 1024; + int max_arguments = 16; + int max_argument_size = 1024; + int quiet = 0; + unsigned int seed = static_cast<unsigned int> (ACE_OS::time(0)); + + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("tn:f:m:s:a:b:r:q")); + int opt; + + while ((opt = get_opt ()) != EOF) { - case 't': - tss = 1; - break; - case 'n': - iterations = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'r': - repeat = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'f': - max_fragments = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'm': - max_fragment_size = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 's': - seed = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'a': - max_arguments = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'b': - max_argument_size = ACE_OS::atoi (get_opt.opt_arg ()); - break; - case 'q': - quiet = 1; - break; - case '?': - default: - ACE_DEBUG ((LM_DEBUG, - "Usage: %s " - "-n iterations " - "-n repeat " - "-f max_fragments " - "-m max_fragment_size " - "-s seed " - "-a max_arguments " - "-b max_argument_size " - "\n", - argv[0])); - return -1; + switch (opt) + { + case 't': + tss = 1; + break; + case 'n': + iterations = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'r': + repeat = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'f': + max_fragments = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'm': + max_fragment_size = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 's': + seed = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'a': + max_arguments = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'b': + max_argument_size = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'q': + quiet = 1; + break; + case '?': + default: + ACE_DEBUG ((LM_DEBUG, + "Usage: %s " + "-n iterations " + "-n repeat " + "-f max_fragments " + "-m max_fragment_size " + "-s seed " + "-a max_arguments " + "-b max_argument_size " + "\n", + argv[0])); + return -1; + } } - } - ACE_DEBUG ((LM_DEBUG, "SEED = %d\n", seed)); + ACE_DEBUG ((LM_DEBUG, "SEED = %d\n", seed)); - ACE_Allocator* buffer_allocator = - ACE_Allocator::instance (); - ACE_Allocator* dblock_allocator = - ACE_Allocator::instance (); - if (tss) - { - buffer_allocator = - TAO_ORB_Core_instance ()->output_cdr_buffer_allocator (); - dblock_allocator = - TAO_ORB_Core_instance ()->output_cdr_dblock_allocator (); - } - - Application_Simulator simulator (max_fragments, - max_fragment_size); - char* argument_buffer; - ACE_NEW_RETURN (argument_buffer, char[max_argument_size], 1); + ACE_Allocator* buffer_allocator = + ACE_Allocator::instance (); + ACE_Allocator* dblock_allocator = + ACE_Allocator::instance (); + if (tss) + { + buffer_allocator = + TAO_ORB_Core_instance ()->output_cdr_buffer_allocator (); + dblock_allocator = + TAO_ORB_Core_instance ()->output_cdr_dblock_allocator (); + } - int* argument_sizes; - ACE_NEW_RETURN (argument_sizes, int[max_arguments], 1); + Application_Simulator simulator (max_fragments, + max_fragment_size); + char* argument_buffer; + ACE_NEW_RETURN (argument_buffer, char[max_argument_size], 1); - int n = ACE_OS::rand_r (&seed) % max_arguments + 1; - for (int k = 0; k < n; ++k) - argument_sizes[k] = ACE_OS::rand_r (&seed) % max_argument_size + 1; + int* argument_sizes; + ACE_NEW_RETURN (argument_sizes, int[max_arguments], 1); - for (int i = 0; i < iterations; ++i) - { - simulator.upcall (&seed); + int n = ACE_OS::rand_r (&seed) % max_arguments + 1; + for (int k = 0; k < n; ++k) + argument_sizes[k] = ACE_OS::rand_r (&seed) % max_argument_size + 1; - // @@ TODO this is the place to put the other allocators. - ACE_High_Res_Timer cdr_encoding; - for (int j = 0; j < repeat; ++j) + for (int i = 0; i < iterations; ++i) { - cdr_encoding.start_incr (); + simulator.upcall (&seed); - char buffer[DEFAULT_BUFFER_SIZE]; - ACE_OutputCDR cdr (buffer, sizeof(buffer), - TAO_ENCAP_BYTE_ORDER, - buffer_allocator, - dblock_allocator); - - for (int k = 0; k < n; ++k) + // @@ TODO this is the place to put the other allocators. + ACE_High_Res_Timer cdr_encoding; + for (int j = 0; j < repeat; ++j) { - cdr.write_char_array (argument_buffer, - argument_sizes[k]); + cdr_encoding.start_incr (); + + char buffer[DEFAULT_BUFFER_SIZE]; + ACE_OutputCDR cdr (buffer, sizeof(buffer), + TAO_ENCAP_BYTE_ORDER, + buffer_allocator, + dblock_allocator); + + for (int k = 0; k < n; ++k) + { + cdr.write_char_array (argument_buffer, + argument_sizes[k]); + } + + cdr_encoding.stop_incr (); } - cdr_encoding.stop_incr (); - } + ACE_Time_Value tv; + cdr_encoding.elapsed_time_incr (tv); + ACE_hrtime_t usecs = tv.sec (); + usecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS); + usecs += tv.usec (); + double average = + static_cast<double> (ACE_HRTIME_CONVERSION(usecs)) / repeat; - ACE_Time_Value tv; - cdr_encoding.elapsed_time_incr (tv); - ACE_hrtime_t usecs = tv.sec (); - usecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS); - usecs += tv.usec (); - double average = - static_cast<double> (ACE_HRTIME_CONVERSION(usecs)) / repeat; + if (!quiet) + ACE_OS::printf ("AVE: %d %f\n", + i, average); - if (!quiet) - ACE_OS::printf ("AVE: %d %f\n", - i, average); + } + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Caught unexpected CORBA exception:"); + return 1; } return 0; } |