2 #include "HostProcess.h"
3 #include "PeerProcess.h"
5 #include "ace/OS_NS_strings.h"
6 #include "ace/SString.h"
7 #include "ace/OS_NS_sys_stat.h"
10 Session::tao_version_
= 220;
17 : split_details_ (false)
19 ACE_CString
n ("localhost");
20 ACE_CString
v ("127.0.0.1");
21 this->alt_addrs_
.bind (n
,v
);
26 for (Processes::iterator i
= processes_
.begin();
27 i
!= processes_
.end();
35 Session::set_tao_version (ACE_TCHAR
*str
)
37 if (ACE_OS::strncmp(str
, ACE_TEXT("1.5"), 3)== 0)
39 else if (ACE_OS::strncmp (str
, ACE_TEXT("1.6"), 3) == 0)
41 else if (ACE_OS::strncmp (str
, ACE_TEXT("1.7"), 3) == 0)
43 else if (ACE_OS::strncmp (str
, ACE_TEXT("1.8"), 3) == 0)
45 else if (ACE_OS::strncmp (str
, ACE_TEXT("2.0"), 3) == 0)
47 else if (ACE_OS::strncmp (str
, ACE_TEXT("2.2"), 3) == 0)
55 Session::tao_version ()
61 Session::add_process (HostProcess
*proc
)
63 if (processes_
.bind(proc
->pid(),proc
) != 0)
65 "Session::add_process could not bind pid %d\n",
67 if (procs_by_name_
.bind(proc
->proc_name(), proc
) != 0)
69 "Session::add_process could not bind procname %s\n",
70 proc
->proc_name().c_str()));
74 Session::alternate_address (const char *addrspec
)
76 const char *equal
= ACE_OS::strchr(addrspec
,'=');
79 ACE_CString
name (addrspec
,(equal
- addrspec
));
80 ACE_CString
value (equal
+1);
81 Session::alt_addrs_
.bind(name
,value
);
85 Session::is_equivalent (const ACE_CString
&primary
,
86 const ACE_CString
&alternate
)
88 ACE_CString
test(primary
);
90 if (Session::alt_addrs_
.find(test
,alt
) == 0)
92 return alt
== alternate
;
98 Session::default_service (const char *addrspec
)
100 const char *equal
= ACE_OS::strchr(addrspec
,'=');
103 ACE_CString
name (addrspec
,(equal
- addrspec
));
104 Endpoint
ep (equal
+1);
106 static long next_def_pid
= 0;
108 HostProcess
*hp
= new HostProcess ("defaulted",next_def_pid
);
110 hp
->add_listen_endpoint (ep
);
111 this->processes_
.bind(next_def_pid
,hp
);
112 this->procs_by_name_
.bind(name
,hp
);
116 Session::find_process (long pid
)
118 Processes::ENTRY
*entry
= 0;
119 if (this->processes_
.find(pid
,entry
) == 0)
120 return entry
->item();
126 Session::find_host_i (const Endpoint
&endpoint
, bool server
)
128 for (Processes::ITERATOR
i (this->processes_
); !i
.done(); i
.advance())
130 Processes::ENTRY
*entry
;
131 if (i
.next(entry
) == 0)
133 if (entry
->item()->has_endpoint(endpoint
, server
))
134 return entry
->item();
140 Session::find_host (const Endpoint
&endpoint
, bool server
)
142 HostProcess
*result
= find_host_i (endpoint
, server
);
146 Endpoint
test (endpoint
);
147 ACE_CString alternate
;
148 if (Session::alt_addrs_
.find(endpoint
.host_
,alternate
) == 0)
150 test
.host_
= alternate
;
151 return find_host_i (test
, server
);
157 Session::make_dir (const char *dirname
, bool split
)
159 this->base_dir_
= dirname
;
160 this->split_details_
= split
;
164 Session::outfile (const char *o
)
172 return this->base_dir_
.length() > 0;
176 Session::has_outfile ()
178 return this->outfile_
.length() > 0;
182 Session::stream_for ( ostream
*oldstream
, HostProcess
*hp
, const char *sub
, const char *detail
)
186 ACE_CString outname
= this->base_dir_
;
188 if (oldstream
== 0 && hp
== 0)
190 if (ACE_OS::mkdir(outname
.c_str()) != 0 && errno
!= EEXIST
)
191 ACE_ERROR ((LM_ERROR
,
192 "Session::stream_for unable to make dir %C, %p\n",
193 outname
.c_str(), "mkdir"));
196 outname
+= ACE_DIRECTORY_SEPARATOR_CHAR
;
199 outname
+= hp
->proc_name();
200 if (ACE_OS::mkdir(outname
.c_str()) != 0 && errno
!= EEXIST
)
201 ACE_ERROR ((LM_ERROR
,
202 "Session::stream_for unable to make dir %C, %p\n",
203 outname
.c_str(), "mkdir"));
205 outname
+= ACE_DIRECTORY_SEPARATOR_CHAR
;
207 outname
+= (sub
== 0) ? "summary.txt" : sub
;
210 if (ACE_OS::mkdir(outname
.c_str()) != 0 && errno
!= EEXIST
)
211 ACE_ERROR ((LM_ERROR
,
212 "Session::stream_for unable to make dir %C, %p\n",
213 outname
.c_str(), "mkdir"));
215 outname
+= ACE_DIRECTORY_SEPARATOR_CHAR
;
218 return new ofstream (outname
.c_str());
223 if (this->has_outfile())
224 return new ofstream(this->outfile_
.c_str());
232 bool single
= !this->has_dir();
233 ostream
*strm
= this->stream_for(0);
234 // report session metrics
238 this->split_details_
= false;
239 *strm
<< "Session summary report: "
240 << this->processes_
.current_size() << " Processes detected." << endl
;
242 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
244 Procs_By_Name::ENTRY
*entry
;
245 if (i
.next(entry
) == 0)
247 entry
->item()->dump_summary (*strm
);
251 *strm
<< "\n\n\nSession detail threads report: " << endl
;
252 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
254 Procs_By_Name::ENTRY
*entry
;
255 if (i
.next(entry
) == 0)
257 strm
= this->split_details_
?
258 stream_for (strm
,entry
->item(),"threads", "summary.txt"):
259 stream_for (strm
,entry
->item(),"threads.txt");
260 entry
->item()->dump_thread_summary (*strm
);
264 *strm
<< "\n\n\nSession detail peer process report: " << endl
;
265 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
267 Procs_By_Name::ENTRY
*entry
;
268 if (i
.next(entry
) == 0)
270 strm
= this->split_details_
?
271 stream_for (strm
,entry
->item(),"peers", "summary.txt") :
272 stream_for (strm
,entry
->item(),"peer_processes.txt");
273 entry
->item()->dump_peer_summary (*strm
);
277 *strm
<< "\n\n\nSession detail object report: " << endl
;
278 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
280 Procs_By_Name::ENTRY
*entry
;
281 if (i
.next(entry
) == 0)
283 strm
= stream_for (strm
,entry
->item(),"objects.txt");
284 entry
->item()->dump_object_detail (*strm
);
288 *strm
<< "\n\n\nSession detail invocation by peer process report: " << endl
;
289 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
291 Procs_By_Name::ENTRY
*entry
;
292 if (i
.next(entry
) == 0)
294 if (this->split_details_
)
296 entry
->item()->split_peer_invocations (this);
300 strm
= stream_for (strm
,entry
->item(),"invocation_by_peer.txt");
301 entry
->item()->dump_invocation_detail (*strm
);
306 *strm
<< "\n\n\nSession detail invocation by thread report: " << endl
;
308 ACE_Time_Value start
= ACE_Time_Value::zero
;
309 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
311 Procs_By_Name::ENTRY
*entry
;
312 if (i
.next(entry
) == 0)
314 if (start
== ACE_Time_Value::zero
||
315 entry
->item()->start_time().msec() < start
.msec())
317 start
= entry
->item()->start_time();
321 for (Procs_By_Name::ITERATOR
i (this->procs_by_name_
); !i
.done(); i
.advance())
323 Procs_By_Name::ENTRY
*entry
;
324 if (i
.next(entry
) == 0)
326 if (this->split_details_
)
328 entry
->item()->split_thread_invocations (this, start
);
332 strm
= stream_for (strm
,entry
->item(),"invocation_by_thread.txt");
333 entry
->item()->dump_thread_invocations (*strm
, start
);
336 if (this->has_outfile() || this->has_dir())
341 // iterate over the collection of host processes to associate peer
342 // processes via endpoints.
344 Session::reconcile ()
346 for (Processes::ITERATOR
i (this->processes_
); !i
.done(); i
.advance())
348 Processes::ENTRY
*entry
;
349 if (i
.next(entry
) == 0)
351 entry
->item()->reconcile_peers(this);