summaryrefslogtreecommitdiff
path: root/TAO/performance-tests/POA/Object_Creation_And_Registration/registration.cpp
blob: cfa1d925660147be229b378677af6735b05ba9e7 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// $Id$

// ================================================================
//
// = LIBRARY
//    TAO/performance-tests/POA/Object_Creation_And_Registration
//
// = FILENAME
//    registration.cpp
//
// = DESCRIPTION
//
//    This test is used to measure the time it takes to register and
//    activate an object in the POA.
//
// = AUTHOR
//    Irfan Pyarali
//
// ================================================================

#include "testS.h"
#include "ace/Profile_Timer.h"
#include "ace/Get_Opt.h"

//#define USING_PURIFY
//#define USING_PURIFY_FOR_SERVANT_LOOKUP
//#define USING_PURIFY_FOR_UNDERBAR_THIS

#if defined (USING_PURIFY)
#if defined (ACE_WIN32)
#include "pure.h"

#else

#include "quantify.h"
inline int QuantifyClearData ()
{
  return quantify_clear_data ();
}

inline int QuantifyStartRecordingData ()
{
  return quantify_start_recording_data ();
}

inline int QuantifyStopRecordingData ()
{
  return quantify_stop_recording_data ();
}

#endif /* ACE_WIN32 */
#endif /* USING_PURIFY */

class test_i : public POA_test
  // = TITLE
  //     Oversimplified servant class
{
};

// Prototype for stat printing function
void
print_stats (ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time);

void
reverse_map_effectiveness (test_i *servants);

static int measure_reverse_map_effectiveness = 0;

// Default iterations
static u_long iterations = 1000;

static int
parse_args (int argc, char **argv)
{
  ACE_Get_Opt get_opts (argc, argv, "i:r");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'i':
        iterations = ACE_static_cast (u_long, ACE_OS::atoi (get_opts.optarg));
        break;

      case 'r':
        measure_reverse_map_effectiveness = 1;
        break;

      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s "
                           "[-r [measure reverse map effectiveness]] "
                           "[-i iterations] "
                           "\n",
                           argv [0]),
                          -1);
      }

  // Indicates successful parsing of command line.
  return 0;
}

int
main (int argc, char **argv)
{
  ACE_DECLARE_NEW_CORBA_ENV;

  ACE_TRY
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            0,
                                            ACE_TRY_ENV);
      ACE_TRY_CHECK;

      int result = parse_args (argc, argv);
      if (result != 0)
        return result;

      // Obtain the RootPOA.
      CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA",
                                                               ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Get the POA_var object from Object_var.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in (),
                                      ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Create an array of servants
      test_i *servants = new test_i[iterations];

      // Create an array of objects
      test_var *objects = new test_var[iterations];

      // Create an array of objects
      PortableServer::ObjectId_var *object_ids = new PortableServer::ObjectId_var[iterations];

      if (measure_reverse_map_effectiveness)
        {
          reverse_map_effectiveness (servants);
        }

      // Index counter
      u_long i = 0;

      {
        // Profile timer
        ACE_Profile_Timer timer;
        ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;

        // We start the profile timer here...
        timer.start ();

#if defined (USING_PURIFY_FOR_UNDERBAR_THIS)
        // Reset Quantify data recording; whatever happened in the
        // past is not relevant to this test.
        QuantifyClearData ();
        QuantifyStartRecordingData ();
#endif /* USING_PURIFY_FOR_UNDERBAR_THIS */

        for (i = 0; i < iterations; i++)
          {
            objects[i] = servants[i]._this (ACE_TRY_ENV);
            ACE_TRY_CHECK;
          }

#if defined (USING_PURIFY_FOR_UNDERBAR_THIS)
        // Stop recording data here; whatever happens after this in
        // the test is not relevant to this test.
        QuantifyStopRecordingData ();
#endif /* USING_PURIFY_FOR_UNDERBAR_THIS */

        // stop the timer.
        timer.stop ();
        timer.elapsed_time (elapsed_time);

        // compute average time.
        ACE_DEBUG ((LM_DEBUG, "\n_this stats...\n"));
        print_stats (elapsed_time);
      }

      {
        // Profile timer
        ACE_Profile_Timer timer;
        ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;

        // We start the profile timer here...
        timer.start ();

#if defined (USING_PURIFY_FOR_SERVANT_LOOKUP)
        // Reset Quantify data recording; whatever happened in the
        // past is not relevant to this test.
        QuantifyClearData ();
        QuantifyStartRecordingData ();
#endif /* USING_PURIFY_FOR_SERVANT_LOOKUP */

        for (i = 0; i < iterations; i++)
          {
            object_ids[i] = root_poa->servant_to_id (&servants[i],
                                                     ACE_TRY_ENV);
            ACE_TRY_CHECK;
          }

#if defined (USING_PURIFY_FOR_SERVANT_LOOKUP)
        // Stop recording data here; whatever happens after this in
        // the test is not relevant to this test.
        QuantifyStopRecordingData ();
#endif /* USING_PURIFY_FOR_SERVANT_LOOKUP */

        // stop the timer.
        timer.stop ();
        timer.elapsed_time (elapsed_time);

        // compute average time.
        ACE_DEBUG ((LM_DEBUG, "\nservant_to_id stats...\n"));
        print_stats (elapsed_time);
      }

      // Destroy RootPOA.
      root_poa->destroy (1,
                         1,
                         ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Cleanup
      delete[] objects;
      delete[] servants;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught");
      return -1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return 0;
}

//
// Code for printing stats
//
void
print_stats (ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time)
{
  if (iterations > 0)
    {
      elapsed_time.real_time *= ACE_ONE_SECOND_IN_MSECS;
      elapsed_time.user_time *= ACE_ONE_SECOND_IN_MSECS;
      elapsed_time.system_time *= ACE_ONE_SECOND_IN_MSECS;

      elapsed_time.real_time /= iterations;
      elapsed_time.user_time /= iterations;
      elapsed_time.system_time /= iterations;

      double tmp = 1000 / elapsed_time.real_time;

      ACE_DEBUG ((LM_DEBUG,
		  "\titerations\t = %d, \n"
		  "\treal_time\t = %0.06f ms, \n"
		  "\tuser_time\t = %0.06f ms, \n"
		  "\tsystem_time\t = %0.06f ms, \n"
		  "\t%0.00f calls/second\n",
                  iterations,
		  elapsed_time.real_time   < 0.0 ? 0.0 : elapsed_time.real_time,
		  elapsed_time.user_time   < 0.0 ? 0.0 : elapsed_time.user_time,
		  elapsed_time.system_time < 0.0 ? 0.0 : elapsed_time.system_time,
		  tmp < 0.0 ? 0.0 : tmp));
    }
  else
    ACE_ERROR ((LM_ERROR,
		"\tNo time stats printed.  Zero iterations or error ocurred.\n"));
}


//
// Measures how well the reverse hash map works.
//
void
reverse_map_effectiveness (test_i *servants)
{
  // Size of the active object map
  const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &parameters =
    TAO_ORB_Core_instance ()->server_factory ()->active_object_map_creation_parameters ();

  u_long active_object_map_size = parameters.active_object_map_size_;

  // Hash counters
  u_long *hash_counter = new u_long[active_object_map_size];

  // Index counter
  u_long i = 0;

  // Initialize the hash counters
  for (i = 0; i < active_object_map_size; i++)
    {
      hash_counter[i] = 0;
    }

  // Calculate the effectiveness of the hash.
  for (i = 0; i < iterations; i++)
    {
      u_long hash_index = u_long (&servants[i]) % active_object_map_size;
      hash_counter[hash_index]++;
    }

  for (i = 0; i < active_object_map_size; i++)
    {
      if (((i) % 10) == 0)
        {
          ACE_DEBUG ((LM_DEBUG, "\n"));
        }
      ACE_DEBUG ((LM_DEBUG, "%d = %d, ", i, hash_counter[i]));
    }
  ACE_DEBUG ((LM_DEBUG, "\n\n"));

  delete[] hash_counter;
}