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 ()
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 () 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
)
118 Endpoint
ep (addr
.c_str());
119 (void)this->by_addr_
.find(ep
,pp
);
124 HostProcess::find_peer (long h
)
126 if (this->by_handle_
.size() == 0)
128 for (PeerArray::ITERATOR
i(this->by_handle_
);
132 PeerNode
*node
= reinterpret_cast<PeerNode
*>(i
.next()->item_
);
133 if (node
->handle_
== h
)
141 HostProcess::pid () const
147 const ACE_Time_Value
&
148 HostProcess::start_time () const
150 return this->start_time_
;
154 HostProcess::start_time (const ACE_Time_Value
&start
)
156 this->start_time_
= start
;
160 HostProcess::has_endpoint (const Endpoint
& addr
, bool listen
)
162 AddrList
&list
= listen
? this->listen_endpoints_
: this->client_endpoints_
;
163 for (ACE_DLList_Iterator
<Endpoint
> i(list
);
176 HostProcess::add_client_endpoint(const Endpoint
&addr
)
178 this->client_endpoints_
.insert_tail(new Endpoint (addr
));
182 HostProcess::add_listen_endpoint(const Endpoint
&addr
)
184 this->listen_endpoints_
.insert_tail(new Endpoint (addr
));
188 HostProcess::add_peer(long handle
, PeerProcess
*peer
)
190 peer
->set_owner (this);
191 PeerProcess
*existing
= this->find_peer(handle
);
194 ACE_DEBUG ((LM_DEBUG
,
195 "add_peer, found existing for %d\n",
198 const Endpoint
&addr
= peer
->is_server() ?
199 peer
->server_addr() : peer
->last_client_addr();
200 int result
= this->by_addr_
.bind (addr
,peer
);
202 ACE_ERROR ((LM_ERROR
,"add_peer, cannot bind to addr %s result = %d, %p\n",
203 addr
.addr_
.c_str(), result
, "by_addr_.bind"));
205 PeerNode
*node
= new PeerNode (handle
,peer
);
206 this->by_handle_
.insert_tail(node
);
210 HostProcess::remove_peer(long h
)
212 if (this->by_handle_
.size() == 0)
214 for (PeerArray::ITERATOR
i(this->by_handle_
);
218 PeerNode
*node
= reinterpret_cast<PeerNode
*>(i
.next()->item_
);
219 if (node
->handle_
== h
)
221 this->by_handle_
.remove(i
.next());
228 HostProcess::dump_summary (ostream
&strm
)
230 strm
<< "Host process " << this->proc_name_
<< " pid(" << this->pid_
<< ") from logfile " << this->logfile_name_
<< endl
;
231 size_t num
= this->listen_endpoints_
.size();
234 strm
<< " listening on ";
236 for (ACE_DLList_Iterator
<Endpoint
> t_iter (this->listen_endpoints_
);
242 strm
<< ep
->addr_
.c_str();
249 strm
<< " " << threads_
.size() << " threads";
251 if (clients_
.current_size() > 0)
252 strm
<< ", client to " << clients_
.current_size();
253 if (servers_
.current_size() > 0)
254 strm
<< ", server to " << servers_
.current_size();
260 HostProcess::dump_ident (ostream
&strm
, const char *message
)
262 strm
<<"\nHost process ";
263 if (this->proc_name_
.length())
264 strm
<< this->proc_name_
;
265 strm
<< " pid (" << this->pid_
<< ") " << message
<< endl
;
269 HostProcess::dump_thread_summary (ostream
&strm
)
271 this->dump_ident (strm
, "thread summary:");
274 size_t total_bytes_sent
= 0;
275 size_t total_bytes_recv
= 0;
276 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
282 thr
->dump_summary (strm
);
283 thr
->get_summary (total_recv
, total_sent
, total_bytes_recv
, total_bytes_sent
);
285 strm
<< "Total requests sent: " << total_sent
<< " received: " << total_recv
<< endl
;
286 strm
<< "Total requests bytes sent: " << total_bytes_sent
<< " received: " << total_bytes_recv
<< endl
;
290 HostProcess::split_thread_invocations (Session
*session
, const ACE_Time_Value
& start
)
292 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
299 thr
->split_filename(fname
,100);
300 ostream
*strm
= session
->stream_for (0, this, "threads", fname
);
301 thr
->dump_invocations (*strm
);
303 thr
->dump_incidents (*strm
, start
);
309 HostProcess::dump_thread_invocations (ostream
&strm
, const ACE_Time_Value
& start
)
311 this->dump_ident (strm
, "invocations by thread:");
312 for (ACE_DLList_Iterator
<Thread
> t_iter (this->threads_
);
318 thr
->dump_invocations (strm
);
320 thr
->dump_incidents (strm
, start
);
326 HostProcess::iterate_peers (int group
,
332 for (PeerProcs::ITERATOR i
= this->by_addr_
.begin(); i
!= by_addr_
.end(); i
++)
334 PeerProcs::ENTRY
*entry
;
335 if (i
.next(entry
) == 0)
337 PeerProcess
*pp
= entry
->item();
341 ((pp
->is_server() && group
== 1)
342 || (!pp
->is_server() && group
== 2)))
348 entry
->item()->dump_summary (*strm
);
351 entry
->item()->dump_object_detail (*strm
);
358 entry
->item()->split_filename(fname
,100);
359 strm
= session
->stream_for (0, this, "peers",fname
);
360 this->dump_ident (*strm
, "Invocation Detail");
361 entry
->item()->dump_invocation_detail (*strm
);
369 this->dump_ident (*strm
,"Invocations continued");
370 entry
->item()->dump_invocation_detail (*strm
);
375 entry
->item()->match_hosts (session
);
383 HostProcess::dump_peer_summary (ostream
&strm
)
385 this->dump_ident (strm
, "peer processes:");
386 size_t num_servers
= 0;
387 size_t num_clients
= 0;
388 strm
<< " total peers: " << this->by_addr_
.current_size() << endl
;
389 for (PeerProcs::ITERATOR i
= this->by_addr_
.begin(); i
!= by_addr_
.end(); i
++)
391 PeerProcs::ENTRY
*entry
;
392 if (i
.next(entry
) == 0)
394 PeerProcess
*pp
= entry
->item();
403 strm
<< " from " << num_clients
<< " clients" << endl
;
404 this->iterate_peers (1, 0, &strm
);
405 strm
<< " to " << num_servers
<< " servers" << endl
;
406 this->iterate_peers (2, 0, &strm
);
410 HostProcess::dump_object_detail (ostream
&strm
)
412 this->dump_ident (strm
, "peer objects: ");
413 this->iterate_peers (3, 1, &strm
);
417 HostProcess::split_peer_invocations (Session
*session
)
419 this->iterate_peers (3, 2, 0, session
);
423 HostProcess::dump_invocation_detail(ostream
&strm
)
425 this->dump_ident (strm
, "invocations: ");
426 this->iterate_peers (3, 2, &strm
);
427 this->dump_ident (strm
, "end invocation report");
431 HostProcess::reconcile_peers (Session
*session
)
433 this->iterate_peers (3, 3, 0, session
);