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 (void)
50 this->new_connection_
.pop (pp
);
55 Thread::peek_new_connection (void) 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 (void) const
71 return this->pending_local_addr_
;
75 Thread::handle_request (void)
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 (void) const
121 return static_cast<long> (this->max_depth_
);
125 Thread::id (void) const
131 Thread::alias (void) const
137 Thread::split_filename (char *buff
, size_t len
) const
139 strncpy (buff
, this->alias_
.c_str(), len
);
140 char *c
= strchr(buff
, '[');
148 Thread::incoming_from (PeerProcess
*pp
)
150 this->incoming_
= pp
;
154 Thread::incoming (void) const
156 return this->incoming_
;
160 Thread::active_handle (long handle
)
162 this->active_handle_
= handle
;
166 Thread::active_handle (void) const
168 return this->active_handle_
;
172 Thread::set_dup (Thread
*other
, bool set_other
)
174 this->target_dup_
= other
;
177 other
->set_dup (this, false);
182 Thread::clear_dup (void)
184 this->target_dup_
= 0;
188 Thread::has_dup (void)
190 return this->target_dup_
!= 0;
194 Thread::swap_target (void)
196 if (target_dup_
!= 0 && target_dup_
->giop_target() != 0)
198 this->giop_target_
->swap (target_dup_
->giop_target());
199 this->target_dup_
->clear_dup ();
200 this->target_dup_
= 0;
204 if (target_dup_
== 0)
205 ACE_ERROR ((LM_ERROR
, "Thread::swap_target, target_dup_ == 0\n"));
207 ACE_ERROR ((LM_ERROR
, "Thread::swap_target, target_dup_.id = %d, giop_target == 0\n", target_dup_
->id()));
212 Thread::giop_target (void)
214 return this->giop_target_
;
218 Thread::set_giop_target (GIOP_Buffer
*buffer
)
220 this->giop_target_
= buffer
;
221 if (this->target_dup_
!= 0)
223 this->target_dup_
->clear_dup();
224 this->target_dup_
= 0;
229 Thread::add_invocation (Invocation
*inv
)
231 this->invocations_
.insert_tail (inv
);
235 Thread::push_invocation (Invocation
*inv
)
237 this->current_invocation_
.push(inv
);
241 Thread::pop_invocation (void)
244 this->current_invocation_
.pop (inv
);
248 Thread::current_invocation (void) const
251 if (this->current_invocation_
.size() > 0)
252 this->current_invocation_
.top(inv
);
257 Thread::dump_summary (ostream
&strm
)
259 strm
<< " " << this->alias_
<< " tid = 0x" << hex
<< this->id_
260 << " (" << dec
<< this->id_
261 << ")\tfirst line " << this->first_line_
<< " \t"
262 << this->client_encounters_
<< " requests sent "
263 << this->server_encounters_
<< " requests received";
264 if (this->count_nesting () > 0 && this->max_depth_
> 0)
266 strm
<<", with " << this->nested_
<< " nested upcalls, max depth "
267 << this->max_depth_
<< endl
;
269 if (this->first_time_
.length() )
271 strm
<< " first encountered " << this->first_time_
272 << " last encountered " << this->last_time_
;
275 strm
<< "\n" << endl
;
279 Thread::get_summary (long &sent_reqs
,
285 for (ACE_DLList_Iterator
<Invocation
> i(this->invocations_
);
291 if (inv
->sent_request())
294 sent_size
+= inv
->request_bytes();
299 recv_size
+= inv
->request_bytes();
305 Thread::dump_invocations (ostream
&strm
)
307 size_t total_request_bytes
= 0;
308 strm
<< this->alias_
<< " handled " << this->invocations_
.size()
309 << " invocations" << endl
;
311 std::stack
<Invocation
*> nested
;
312 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
320 while (!nested
.empty ())
322 if (nested
.top()->contains (inv
->req_line ()))
324 level
= nested
.size();
325 if (level
> this->nested_
)
326 this->nested_
= level
;
333 inv
->dump_detail (strm
, level
, Invocation::Dump_Proc
, false);
334 total_request_bytes
+= inv
->request_bytes();
336 strm
<< "total request octet count: " << total_request_bytes
;
340 Thread::dump_incidents (ostream
&strm
, const ACE_Time_Value
& relstart
)
342 if (this->nested_
== 0)
344 strm
<< "\n" << this->alias_
<< " handled " << this->invocations_
.size()
345 << " invocations with a max nesting level of " << this->nested_
<< endl
;
347 std::deque
<Invocation
*> nested_queue
;
348 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
354 size_t level
= nested_queue
.size();
356 while (!nested_queue
.empty ())
358 Invocation
*prev
= nested_queue
.back ();
359 if (prev
->contains (inv
->req_line ()))
363 nested_queue
.pop_back ();
365 prev
->dump_finish_line (strm
, level
, relstart
);
367 if (nested_queue
.size() > 1)
369 size_t inv_line
= inv
->req_line ();
370 for (std::deque
<Invocation
*>::iterator j
= nested_queue
.begin ();
371 j
!= nested_queue
.end ();
374 if ((*j
)->repl_line () < inv_line
)
376 (*j
)->dump_finish_line (strm
, level
, relstart
);
380 nested_queue
.push_back (inv
);
381 inv
->dump_start_line (strm
, level
, relstart
);
386 Thread::count_nesting (void)
388 std::stack
<Invocation
*> nested
;
389 for (ACE_DLList_Iterator
<Invocation
> i (this->invocations_
);
396 while (!nested
.empty ())
398 level
= nested
.size();
399 if (level
> this->nested_
)
400 this->nested_
= level
;
401 if (nested
.top()->contains (inv
->req_line ()))
409 return this->nested_
;