1 #include "HostProcess.h"
2 #include "Invocation.h"
3 #include "PeerProcess.h"
7 #include "ace/OS_NS_stdio.h"
9 PeerNode::PeerNode (long h
, PeerProcess
*p
)
15 HostProcess::HostProcess (const ACE_CString
&src
, long pid
)
18 start_time_ (ACE_Time_Value::zero
)
22 HostProcess::~HostProcess (void)
24 for (AddrList::ITERATOR
i(this->listen_endpoints_
);
28 delete reinterpret_cast<Endpoint
*>(i
.next()->item_
);
30 for (ThreadList::ITERATOR
i(this->threads_
);
34 delete reinterpret_cast<Thread
*>(i
.next()->item_
);
37 for (PeerProcs::ITERATOR i
= by_addr_
.begin(); i
!= servers_
.end(); i
++)
39 PeerProcs::ENTRY
*entry
;
40 if (i
.next(entry
) == 0)
48 HostProcess::proc_name (const ACE_CString
&name
)
50 this->proc_name_
= name
;
54 HostProcess::proc_name (void) const
56 return this->proc_name_
;
60 HostProcess::find_thread (long tid
, size_t offset
)
63 for (ACE_DLList_Iterator
<Thread
> i(threads_
);
72 ACE_OS::snprintf (alias
, 20, "Thread[" ACE_SIZE_T_FORMAT_SPECIFIER_ASCII
"]",
73 this->threads_
.size() + 1);
74 thr
= new Thread (tid
, alias
, offset
);
75 threads_
.insert_tail (thr
);
80 HostProcess::find_thread_for_peer (const ACE_CString
&addr
)
83 Endpoint
ep (addr
.c_str());
84 for (ACE_DLList_Iterator
<Thread
> i(threads_
);
89 PeerProcess
*pp
= thr
->peek_new_connection();
93 if (pp
->match_server_addr(ep
))
100 HostProcess::find_thread_for_handle (long h
)
103 for (ACE_DLList_Iterator
<Thread
> i(threads_
);
108 if (thr
->active_handle() == h
&& thr
->giop_target() != 0)
115 HostProcess::find_peer (const ACE_CString
&addr
)
119 Endpoint
ep (addr
.c_str());
120 (void)this->by_addr_
.find(ep
,pp
);
125 HostProcess::find_peer (long h
)
127 if (this->by_handle_
.size() == 0)
129 for (PeerArray::ITERATOR
i(this->by_handle_
);
133 PeerNode
*node
= reinterpret_cast<PeerNode
*>(i
.next()->item_
);
134 if (node
->handle_
== h
)
142 HostProcess::pid (void) const
148 const ACE_Time_Value
&
149 HostProcess::start_time (void) const
151 return this->start_time_
;
155 HostProcess::start_time (const ACE_Time_Value
&start
)
157 this->start_time_
= start
;
161 HostProcess::has_endpoint (const Endpoint
& addr
, bool listen
)
163 AddrList
&list
= listen
? this->listen_endpoints_
: this->client_endpoints_
;
164 for (ACE_DLList_Iterator
<Endpoint
> i(list
);
177 HostProcess::add_client_endpoint(const Endpoint
&addr
)
179 this->client_endpoints_
.insert_tail(new Endpoint (addr
));
183 HostProcess::add_listen_endpoint(const Endpoint
&addr
)
185 this->listen_endpoints_
.insert_tail(new Endpoint (addr
));
189 HostProcess::add_peer(long handle
, PeerProcess
*peer
)
191 peer
->set_owner (this);
192 PeerProcess
*existing
= this->find_peer(handle
);
195 ACE_DEBUG ((LM_DEBUG
,
196 "add_peer, found existing for %d\n",
199 const Endpoint
&addr
= peer
->is_server() ?
200 peer
->server_addr() : peer
->last_client_addr();
201 int result
= this->by_addr_
.bind (addr
,peer
);
203 ACE_ERROR ((LM_ERROR
,"add_peer, cannot bind to addr %s result = %d, %p\n",
204 addr
.addr_
.c_str(), result
, "by_addr_.bind"));
206 PeerNode
*node
= new PeerNode (handle
,peer
);
207 this->by_handle_
.insert_tail(node
);
211 HostProcess::remove_peer(long h
)
213 if (this->by_handle_
.size() == 0)
215 for (PeerArray::ITERATOR
i(this->by_handle_
);
219 PeerNode
*node
= reinterpret_cast<PeerNode
*>(i
.next()->item_
);
220 if (node
->handle_
== h
)
222 this->by_handle_
.remove(i
.next());
229 HostProcess::dump_summary (ostream
&strm
)
231 strm
<< "Host process " << this->proc_name_
<< " pid(" << this->pid_
<< ") from logfile " << this->logfile_name_
<< endl
;
232 size_t num
= this->listen_endpoints_
.size();
235 strm
<< " listening on ";
237 for (ACE_DLList_Iterator
<Endpoint
> t_iter (this->listen_endpoints_
);
243 strm
<< ep
->addr_
.c_str();
250 strm
<< " " << threads_
.size() << " threads";
252 if (clients_
.current_size() > 0)
253 strm
<< ", client to " << clients_
.current_size();
254 if (servers_
.current_size() > 0)
255 strm
<< ", server to " << servers_
.current_size();
261 HostProcess::dump_ident (ostream
&strm
, const char *message
)
263 strm
<<"\nHost process ";
264 if (this->proc_name_
.length())
265 strm
<< this->proc_name_
;
266 strm
<< " pid (" << this->pid_
<< ") " << message
<< endl
;
270 HostProcess::dump_thread_summary (ostream
&strm
)
272 this->dump_ident (strm
, "thread summary:");
275 size_t total_bytes_sent
= 0;
276 size_t total_bytes_recv
= 0;
277 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
283 thr
->dump_summary (strm
);
284 thr
->get_summary (total_recv
, total_sent
, total_bytes_recv
, total_bytes_sent
);
286 strm
<< "Total requests sent: " << total_sent
<< " received: " << total_recv
<< endl
;
287 strm
<< "Total requests bytes sent: " << total_bytes_sent
<< " received: " << total_bytes_recv
<< endl
;
291 HostProcess::split_thread_invocations (Session
*session
, const ACE_Time_Value
& start
)
293 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
300 thr
->split_filename(fname
,100);
301 ostream
*strm
= session
->stream_for (0, this, "threads", fname
);
302 thr
->dump_invocations (*strm
);
304 thr
->dump_incidents (*strm
, start
);
310 HostProcess::dump_thread_invocations (ostream
&strm
, const ACE_Time_Value
& start
)
312 this->dump_ident (strm
, "invocations by thread:");
313 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
319 thr
->dump_invocations (strm
);
321 thr
->dump_incidents (strm
, start
);
327 HostProcess::iterate_peers (int group
,
333 for (PeerProcs::ITERATOR i
= this->by_addr_
.begin(); i
!= by_addr_
.end(); i
++)
335 PeerProcs::ENTRY
*entry
;
336 if (i
.next(entry
) == 0)
338 PeerProcess
*pp
= entry
->item();
342 ((pp
->is_server() && group
== 1)
343 || (!pp
->is_server() && group
== 2)))
349 entry
->item()->dump_summary (*strm
);
352 entry
->item()->dump_object_detail (*strm
);
359 entry
->item()->split_filename(fname
,100);
360 strm
= session
->stream_for (0, this, "peers",fname
);
361 this->dump_ident (*strm
, "Invocation Detail");
362 entry
->item()->dump_invocation_detail (*strm
);
370 this->dump_ident (*strm
,"Invocations continued");
371 entry
->item()->dump_invocation_detail (*strm
);
376 entry
->item()->match_hosts (session
);
384 HostProcess::dump_peer_summary (ostream
&strm
)
386 this->dump_ident (strm
, "peer processes:");
387 size_t num_servers
= 0;
388 size_t num_clients
= 0;
389 strm
<< " total peers: " << this->by_addr_
.current_size() << endl
;
390 for (PeerProcs::ITERATOR i
= this->by_addr_
.begin(); i
!= by_addr_
.end(); i
++)
392 PeerProcs::ENTRY
*entry
;
393 if (i
.next(entry
) == 0)
395 PeerProcess
*pp
= entry
->item();
404 strm
<< " from " << num_clients
<< " clients" << endl
;
405 this->iterate_peers (1, 0, &strm
);
406 strm
<< " to " << num_servers
<< " servers" << endl
;
407 this->iterate_peers (2, 0, &strm
);
411 HostProcess::dump_object_detail (ostream
&strm
)
413 this->dump_ident (strm
, "peer objects: ");
414 this->iterate_peers (3, 1, &strm
);
418 HostProcess::split_peer_invocations (Session
*session
)
420 this->iterate_peers (3, 2, 0, session
);
424 HostProcess::dump_invocation_detail(ostream
&strm
)
426 this->dump_ident (strm
, "invocations: ");
427 this->iterate_peers (3, 2, &strm
);
428 this->dump_ident (strm
, "end invocation report");
432 HostProcess::reconcile_peers (Session
*session
)
434 this->iterate_peers (3, 3, 0, session
);