2 #include "Invocation.h"
3 #include "PeerProcess.h"
4 #include "GIOP_Buffer.h"
5 #include "ace/OS_NS_stdio.h"
9 Thread::Thread (long tid
, const char *alias
, size_t offset
)
13 client_encounters_ (0),
14 server_encounters_ (0),
21 current_invocation_ (),
30 Thread::add_time (const ACE_CString
&time
)
35 if (first_time_
.length() == 0)
41 Thread::push_new_connection (PeerProcess
*pp
)
43 this->new_connection_
.push (pp
);
47 Thread::pop_new_connection ()
50 this->new_connection_
.pop (pp
);
55 Thread::peek_new_connection () const
58 this->new_connection_
.top (pp
);
63 Thread::pending_local_addr (const ACE_CString
&addr
)
65 this->pending_local_addr_
= addr
;
69 Thread::pending_local_addr () const
71 return this->pending_local_addr_
;
75 Thread::handle_request ()
77 this->server_encounters_
++;
78 if (this->pending_
.size() > 1)
83 Thread::enter_wait (PeerProcess
*pp
)
85 this->pending_
.push (pp
);
86 this->client_encounters_
++;
87 if (this->pending_
.size() > this->max_depth_
)
88 this->max_depth_
= this->pending_
.size();
89 if (this->pending_
.size() > 1)
94 Thread::exit_wait (PeerProcess
*pp
, size_t linenum
)
97 if (this->pending_
.pop(old
) == -1)
101 ACE_ERROR ((LM_ERROR
,
102 "Line %d, Ending an invocation to peer %s, but most recent started"
103 " is to peer %s\n", linenum
, pp
->id(), old
->id()));
104 // this->pending_.push(old);
105 if (this->pending_
.pop(old
) == -1)
108 if (this->pending_
.top (old
) == 0)
110 this->active_handle (old
->last_transport ()->handle_
);
114 this->active_handle (0);
119 Thread::max_depth () const
121 return static_cast<long> (this->max_depth_
);
131 Thread::alias () const
137 Thread::split_filename (char *buff
, size_t len
) const
139 strncpy (buff
, this->alias_
.c_str(), len
);
140 char *c
= strchr(buff
, '[');
147 Thread::incoming_from (PeerProcess
*pp
)
149 this->incoming_
= pp
;
153 Thread::incoming () const
155 return this->incoming_
;
159 Thread::active_handle (long handle
)
161 this->active_handle_
= handle
;
165 Thread::active_handle () const
167 return this->active_handle_
;
171 Thread::set_dup (Thread
*other
, bool set_other
)
173 this->target_dup_
= other
;
176 other
->set_dup (this, false);
183 this->target_dup_
= 0;
189 return this->target_dup_
!= 0;
193 Thread::swap_target ()
195 if (target_dup_
!= 0 && target_dup_
->giop_target() != 0)
197 this->giop_target_
->swap (target_dup_
->giop_target());
198 this->target_dup_
->clear_dup ();
199 this->target_dup_
= 0;
203 if (target_dup_
== 0)
204 ACE_ERROR ((LM_ERROR
, "Thread::swap_target, target_dup_ == 0\n"));
206 ACE_ERROR ((LM_ERROR
, "Thread::swap_target, target_dup_.id = %d, giop_target == 0\n", target_dup_
->id()));
211 Thread::giop_target ()
213 return this->giop_target_
;
217 Thread::set_giop_target (GIOP_Buffer
*buffer
)
219 this->giop_target_
= buffer
;
220 if (this->target_dup_
!= 0)
222 this->target_dup_
->clear_dup();
223 this->target_dup_
= 0;
228 Thread::add_invocation (Invocation
*inv
)
230 this->invocations_
.insert_tail (inv
);
234 Thread::push_invocation (Invocation
*inv
)
236 this->current_invocation_
.push(inv
);
240 Thread::pop_invocation ()
243 this->current_invocation_
.pop (inv
);
247 Thread::current_invocation () const
250 if (this->current_invocation_
.size() > 0)
251 this->current_invocation_
.top(inv
);
256 Thread::dump_summary (ostream
&strm
)
258 strm
<< " " << this->alias_
<< " tid = 0x" << hex
<< this->id_
259 << " (" << dec
<< this->id_
260 << ")\tfirst line " << this->first_line_
<< " \t"
261 << this->client_encounters_
<< " requests sent "
262 << this->server_encounters_
<< " requests received";
263 if (this->count_nesting () > 0 && this->max_depth_
> 0)
265 strm
<<", with " << this->nested_
<< " nested upcalls, max depth "
266 << this->max_depth_
<< endl
;
268 if (this->first_time_
.length() )
270 strm
<< " first encountered " << this->first_time_
271 << " last encountered " << this->last_time_
;
274 strm
<< "\n" << endl
;
278 Thread::get_summary (long &sent_reqs
,
283 for (ACE_DLList_Iterator
<Invocation
> i(this->invocations_
);
289 if (inv
->sent_request())
292 sent_size
+= inv
->request_bytes();
297 recv_size
+= inv
->request_bytes();
303 Thread::dump_invocations (ostream
&strm
)
305 size_t total_request_bytes
= 0;
306 strm
<< this->alias_
<< " handled " << this->invocations_
.size()
307 << " invocations" << endl
;
309 std::stack
<Invocation
*> nested
;
310 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
318 while (!nested
.empty ())
320 if (nested
.top()->contains (inv
->req_line ()))
322 level
= nested
.size();
323 if (level
> this->nested_
)
324 this->nested_
= level
;
331 inv
->dump_detail (strm
, level
, Invocation::Dump_Proc
, false);
332 total_request_bytes
+= inv
->request_bytes();
334 strm
<< "total request octet count: " << total_request_bytes
;
338 Thread::dump_incidents (ostream
&strm
, const ACE_Time_Value
& relstart
)
340 if (this->nested_
== 0)
342 strm
<< "\n" << this->alias_
<< " handled " << this->invocations_
.size()
343 << " invocations with a max nesting level of " << this->nested_
<< endl
;
345 std::deque
<Invocation
*> nested_queue
;
346 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
352 size_t level
= nested_queue
.size();
354 while (!nested_queue
.empty ())
356 Invocation
*prev
= nested_queue
.back ();
357 if (prev
->contains (inv
->req_line ()))
361 nested_queue
.pop_back ();
363 prev
->dump_finish_line (strm
, level
, relstart
);
365 if (nested_queue
.size() > 1)
367 size_t inv_line
= inv
->req_line ();
368 for (std::deque
<Invocation
*>::iterator j
= nested_queue
.begin ();
369 j
!= nested_queue
.end ();
372 if ((*j
)->repl_line () < inv_line
)
374 (*j
)->dump_finish_line (strm
, level
, relstart
);
378 nested_queue
.push_back (inv
);
379 inv
->dump_start_line (strm
, level
, relstart
);
384 Thread::count_nesting ()
386 std::stack
<Invocation
*> nested
;
387 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
394 while (!nested
.empty ())
396 level
= nested
.size();
397 if (level
> this->nested_
)
398 this->nested_
= level
;
399 if (nested
.top()->contains (inv
->req_line ()))
407 return this->nested_
;