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
|
#include "ace/Get_Opt.h"
// $Id$
#include "Options.h"
// Static Singleton instance.
Options *Options::instance_ = 0;
Options *
Options::instance (void)
{
if (Options::instance_ == 0)
Options::instance_ = new Options ();
return Options::instance_;
}
char *
Options::program_name (void)
{
return this->program_name_;
}
const char *
Options::slave_name (void)
{
return this->slave_name_;
}
int
Options::debug (void)
{
return this->debug_;
}
int
Options::exec_slave (void)
{
return this->exec_slave_;
}
size_t
Options::iteration_count (void)
{
return this->iteration_count_;
}
int
Options::use_sbrk (void)
{
return this->use_sbrk_;
}
size_t
Options::max_msg_size (void)
{
return this->max_msg_size_;
}
size_t
Options::spawn_count (void)
{
return this->spawn_count_;
}
int
Options::spawn_threads (void)
{
return this->spawn_threads_;
}
int
Options::use_mmap (void)
{
return this->use_mmap_;
}
int
Options::use_shmem (void)
{
return this->use_shmem_;
}
int
Options::child (void)
{
return this->child_;
}
// Explain usage and exit.
void
Options::print_usage_and_die (void)
{
ACE_ERROR ((LM_ERROR, "usage: %n"
"\n[-d] (run in debugging mode)\n"
"[-e] (use exec(2) in addition to fork(2))\n"
"[-l] (use C++ new operator rather than sbrk(2)\n"
"[-L max_msg_size]\n"
"[-m] (use mmap rather than SysV shared memory)\n"
"[-p] (use processes rather than threads)\n"
"[-s] (use SysV shared memory rather than mmap)\n"
"[-t number of threads or processes to spawn]\n"
"[-n iteration_count]\n%a", -1));
/* NOTREACHED */
}
Options::Options (void)
: slave_name_ ("slave"),
debug_ (0),
exec_slave_ (0),
iteration_count_ (100),
use_sbrk_ (0),
use_shmem_ (0),
max_msg_size_ (127),
spawn_count_ (1),
spawn_threads_ (1),
use_mmap_ (0),
child_ (0)
{
}
void
Options::parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opt (argc, argv, "dehlL:mn:pst:");
this->program_name_ = argv[0];
ACE_LOG_MSG->open (this->program_name_);
// Put in a special-case check for child process.
if (ACE_OS::strcmp (this->program_name_, slave_name_) == 0)
{
this->child_ = 1;
this->use_mmap_ = 1;
}
int c;
while ((c = get_opt ()) != -1)
{
switch (c)
{
case 'd':
this->debug_ = 1;
break;
case 'e':
this->exec_slave_ = 1;
break;
case 'h':
this->print_usage_and_die ();
/* NOTREACHED */
break;
case 'l':
this->use_sbrk_ = 0;
break;
case 'L':
this->max_msg_size_ = ACE_OS::atoi (get_opt.optarg);
break;
case 'm':
this->use_mmap_ = 1;
break;
case 'n':
this->iteration_count_ = ACE_OS::atoi (get_opt.optarg);
break;
case 'p': // Spawn processes rather than threads
this->spawn_threads_ = 0;
break;
case 's':
// Use System V shared memory...
this->use_shmem_ = 1;
break;
case 't':
this->spawn_count_ = ACE_OS::atoi (get_opt.optarg);
break;
default:
this->print_usage_and_die ();
/* NOTREACHED */
break;
}
}
// Switch to using MMAP when the -p and -e options are enabled.
if (this->exec_slave_ == 1 && this->spawn_threads_ == 0)
this->use_mmap_ = 1;
}
|