~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/tests/Notify/performance-tests/Filter/Sequence_Consumer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Sequence_Consumer.cpp,v 1.8 2003/11/02 23:27:22 dhinton Exp
2
 
 
3
 
// ******************************************************************
4
 
// Include Section
5
 
// ******************************************************************
6
 
 
7
 
#include "ace/Get_Opt.h"
8
 
 
9
 
#include "orbsvcs/CosNotifyCommC.h"
10
 
#include "orbsvcs/CosNamingC.h"
11
 
#include "Notify_Sequence_Push_Consumer.h"
12
 
#include "goC.h"
13
 
#include "tao/debug.h"
14
 
#include "ace/OS_NS_sys_time.h"
15
 
 
16
 
#include "Notify_Test_Client.h"
17
 
 
18
 
// ******************************************************************
19
 
// Data Section
20
 
// ******************************************************************
21
 
 
22
 
static const char* ior = "file://supplier.ior";
23
 
static CORBA::Boolean done = 0;
24
 
static CORBA::Boolean dummy = 0;
25
 
static CORBA::Boolean filter = 0;
26
 
static unsigned int consumers = 2;
27
 
static unsigned int batch_size = 10;
28
 
static unsigned int expected = 50;  // 50 sets of 10
29
 
 
30
 
#define GRAMMAR "EXTENDED_TCL"
31
 
 
32
 
// ******************************************************************
33
 
// Subroutine Section
34
 
// ******************************************************************
35
 
 
36
 
class Consumer_Client : public Notify_Test_Client
37
 
{
38
 
public:
39
 
  virtual int parse_args (int argc, char* argv[]);
40
 
};
41
 
 
42
 
 
43
 
int
44
 
Consumer_Client::parse_args (int argc, char *argv[])
45
 
{
46
 
  ACE_Get_Opt get_opts (argc, argv, "k:c:e:f");
47
 
  int c;
48
 
 
49
 
  while ((c = get_opts ()) != -1)
50
 
    switch (c)
51
 
      {
52
 
      case 'k':
53
 
        ior = get_opts.optarg;
54
 
        break;
55
 
 
56
 
      case 'c':
57
 
        consumers = ACE_OS::atoi (get_opts.optarg);
58
 
        break;
59
 
 
60
 
      case 'e':
61
 
        expected = ACE_OS::atoi (get_opts.optarg);
62
 
        break;
63
 
 
64
 
      case 'f':
65
 
        filter = 1;
66
 
        break;
67
 
 
68
 
      default:
69
 
        ACE_ERROR_RETURN ((LM_ERROR,
70
 
                           "usage:  %s "
71
 
                           "-k <ior> "
72
 
                           "-c <# of consumers> "
73
 
                           "-e <expected events> "
74
 
                           "-f "
75
 
                           "\n",
76
 
                           argv [0]),
77
 
                          -1);
78
 
      }
79
 
  // Indicates sucessful parsing of the command line
80
 
  return 0;
81
 
}
82
 
 
83
 
 
84
 
static CosNotifyChannelAdmin::ConsumerAdmin_ptr
85
 
create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
86
 
                      ACE_ENV_ARG_DECL)
87
 
{
88
 
  CosNotifyChannelAdmin::AdminID adminid = 0;
89
 
  CosNotifyChannelAdmin::ConsumerAdmin_var admin =
90
 
    ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
91
 
                           adminid
92
 
                           ACE_ENV_ARG_PARAMETER);
93
 
 
94
 
  ACE_CHECK_RETURN (0);
95
 
 
96
 
  if (filter)
97
 
    {
98
 
      // Filter Section
99
 
      CosNotifyFilter::FilterFactory_var ffact =
100
 
          ec->default_filter_factory (ACE_ENV_SINGLE_ARG_PARAMETER);
101
 
      ACE_CHECK_RETURN (0);
102
 
 
103
 
      // One Filter
104
 
      CosNotifyFilter::Filter_var filter =
105
 
          ffact->create_filter (GRAMMAR ACE_ENV_ARG_PARAMETER);
106
 
      ACE_CHECK_RETURN (0);
107
 
 
108
 
      CosNotifyFilter::ConstraintExpSeq constraint_list (1);
109
 
      constraint_list.length (1);
110
 
 
111
 
      constraint_list[0].event_types.length (0);
112
 
      constraint_list[0].constraint_expr =
113
 
                                 CORBA::string_dup ("type == 'even'");
114
 
 
115
 
      filter->add_constraints (constraint_list ACE_ENV_ARG_PARAMETER);
116
 
      ACE_CHECK_RETURN (0);
117
 
 
118
 
      admin->add_filter (filter.in () ACE_ENV_ARG_PARAMETER);
119
 
      ACE_CHECK_RETURN (0);
120
 
      // End One Filter
121
 
    }
122
 
 
123
 
  return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
124
 
}
125
 
 
126
 
 
127
 
static void
128
 
create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
129
 
                  Notify_Test_Client* client
130
 
                  ACE_ENV_ARG_DECL)
131
 
{
132
 
  for(unsigned int i = 0; i < consumers; i++)
133
 
    {
134
 
      // startup the first consumer
135
 
      char name[64] = "";
136
 
      ACE_OS::sprintf(name, "consumer%u", i);
137
 
      Notify_Sequence_Push_Consumer* consumer;
138
 
      ACE_NEW_THROW_EX (consumer,
139
 
                        Notify_Sequence_Push_Consumer (
140
 
                                         name,
141
 
                                         expected,
142
 
                                         (i + 1 == consumers ? done : dummy)),
143
 
                        CORBA::NO_MEMORY ());
144
 
 
145
 
      consumer->init (client->root_poa () ACE_ENV_ARG_PARAMETER);
146
 
      ACE_CHECK;
147
 
 
148
 
      consumer->_connect (admin ACE_ENV_ARG_PARAMETER);
149
 
      ACE_CHECK;
150
 
    }
151
 
}
152
 
 
153
 
// ******************************************************************
154
 
// Main Section
155
 
// ******************************************************************
156
 
 
157
 
int main (int argc, char* argv[])
158
 
{
159
 
  int status = 0;
160
 
  ACE_TRY_NEW_ENV
161
 
    {
162
 
      Consumer_Client client;
163
 
 
164
 
      status = client.init (argc, argv ACE_ENV_ARG_PARAMETER);
165
 
      ACE_TRY_CHECK;
166
 
 
167
 
      if (status == 0)
168
 
        {
169
 
          // If we are filtering, we will get half as many as originally
170
 
          // expected
171
 
          if (filter)
172
 
            {
173
 
              expected /= 2;
174
 
            }
175
 
 
176
 
          CosNotifyChannelAdmin::EventChannel_var ec =
177
 
            client.create_event_channel ("MyEventChannel", 1
178
 
                                         ACE_ENV_ARG_PARAMETER);
179
 
          ACE_TRY_CHECK;
180
 
 
181
 
          CORBA::ORB_ptr orb = client.orb ();
182
 
          CORBA::Object_var object =
183
 
                              orb->string_to_object (ior ACE_ENV_ARG_PARAMETER);
184
 
          ACE_TRY_CHECK;
185
 
 
186
 
          sig_var sig = sig::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
187
 
          ACE_TRY_CHECK;
188
 
 
189
 
          if (CORBA::is_nil (sig.in ()))
190
 
            {
191
 
              ACE_ERROR_RETURN ((LM_ERROR,
192
 
                                 "Object reference <%s> is nil\n",
193
 
                                 ior),
194
 
                                1);
195
 
            }
196
 
 
197
 
          CosNotifyChannelAdmin::ConsumerAdmin_var admin =
198
 
            create_consumeradmin (ec.in () ACE_ENV_ARG_PARAMETER);
199
 
          ACE_TRY_CHECK;
200
 
 
201
 
          if (!CORBA::is_nil (admin.in ()))
202
 
            {
203
 
              create_consumers(admin.in (), &client ACE_ENV_ARG_PARAMETER);
204
 
              ACE_TRY_CHECK;
205
 
 
206
 
              // Tell the supplier to go
207
 
              sig->go (ACE_ENV_SINGLE_ARG_PARAMETER);
208
 
              ACE_TRY_CHECK;
209
 
 
210
 
              ACE_Time_Value now = ACE_OS::gettimeofday ();
211
 
              while (!done)
212
 
                {
213
 
                  if (orb->work_pending ())
214
 
                    {
215
 
                      orb->perform_work ();
216
 
                    }
217
 
                }
218
 
              ACE_Time_Value then = ACE_OS::gettimeofday ();
219
 
 
220
 
              static const unsigned int per = 100;
221
 
              ACE_Time_Value difference = then - now;
222
 
              double denominator = per / ((double)expected *
223
 
                                          (double)batch_size);
224
 
              difference *= denominator;
225
 
 
226
 
              if (TAO_debug_level)
227
 
                ACE_DEBUG((LM_DEBUG,
228
 
                           "Average of %ds %dus for %u events\n",
229
 
                           difference.sec (), difference.usec (), per));
230
 
            }
231
 
        }
232
 
    }
233
 
  ACE_CATCH (CORBA::Exception, e)
234
 
    {
235
 
      ACE_PRINT_EXCEPTION (e,
236
 
                           "Consumer exception: ");
237
 
      status = 1;
238
 
    }
239
 
  ACE_ENDTRY;
240
 
 
241
 
  return status;
242
 
}