summaryrefslogtreecommitdiff
path: root/TAO/utils/logWalker/Session.cpp
blob: 8f19441541754e3018ec2c9538bb464674415505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// $Id$

#include "Session.h"
#include "HostProcess.h"
#include "Log.h"
#include "ace/OS_NS_strings.h"
#include "ace/SString.h"
#include "ace/OS_NS_sys_stat.h"

long
Session::tao_version_ = 200;

Session::Session (void)
{
  ACE_CString n ("localhost");
  ACE_CString v ("127.0.0.1");
  this->alt_addrs_.bind (n,v);
}

Session::~Session (void)
{
  for (Processes::iterator i = processes_.begin();
       i != processes_.end();
       i++)
    {
      delete i->item();
    }
}

bool
Session::set_tao_version (ACE_TCHAR *str)
{
  if (ACE_OS::strncmp(str, ACE_TEXT("1.5"), 3)== 0)
    tao_version_ = 150;
  else if (ACE_OS::strncmp (str, ACE_TEXT("1.6"), 3) == 0)
    tao_version_ = 160;
  else if (ACE_OS::strncmp (str, ACE_TEXT("1.7"), 3) == 0)
    tao_version_ = 170;
  else if (ACE_OS::strncmp (str, ACE_TEXT("1.8"), 3) == 0)
    tao_version_ = 180;
  else if (ACE_OS::strncmp (str, ACE_TEXT("2.0"), 3) == 0)
    tao_version_ = 200;
  else
    return false;
  return true;
}

long
Session::tao_version (void)
{
  return tao_version_;
}

void
Session::add_process (HostProcess *proc)
{
  if (processes_.bind(proc->pid(),proc) != 0)
    ACE_ERROR ((LM_ERROR,
                "Session::add_process could not bind pid %d\n",
                proc->pid()));
  if (procs_by_name_.bind(proc->proc_name(), proc) != 0)
    ACE_ERROR ((LM_ERROR,
                "Session::add_process could not bind procname %s\n",
                proc->proc_name().c_str()));
}

void
Session::alternate_address (const char *addrspec)
{
  const char *equal = ACE_OS::strchr(addrspec,'=');
  if (equal == 0)
   return;
  ACE_CString name (addrspec,(equal - addrspec));
  ACE_CString value (equal+1);
  this->alt_addrs_.bind(name,value);
}

bool
Session::is_equivalent (const ACE_CString &primary,
                        const ACE_CString &alternate)
{
  ACE_CString test(primary);
  ACE_CString alt;
  if (this->alt_addrs_.find(test,alt) == 0)
    {
      return alt == alternate;
    }
  return false;
}

void
Session::default_service (const char *addrspec)
{
   const char *equal = ACE_OS::strchr(addrspec,'=');
  if (equal == 0)
    return;
  ACE_CString name (addrspec,(equal - addrspec));
  ACE_CString endpoint (equal+1);

  static long next_def_pid = 0;
  --next_def_pid;
  HostProcess *hp = new HostProcess ("defaulted",next_def_pid);
  hp->proc_name(name);
  hp->add_listen_endpoint (endpoint);
  this->processes_.bind(next_def_pid,hp);
  this->procs_by_name_.bind(name,hp);
}

HostProcess *
Session::find_process (long pid)
{
  Processes::ENTRY *entry = 0;
  if (this->processes_.find(pid,entry) == 0)
    return entry->item();
  else
    return 0;
}

HostProcess *
Session::find_host (ACE_CString &endpoint, bool server)
{
  ACE_CString test(endpoint);
  ACE_CString alternate;
  size_t sep = test.find(':');
  if (this->alt_addrs_.find(test.substring (0,sep),alternate) == 0)
    {
      test = alternate + test.substring(sep);
    }
  for (Processes::ITERATOR i (this->processes_); !i.done(); i.advance())
    {
      Processes::ENTRY *entry;
      if (i.next(entry) == 0)
        break;
      if (entry->item()->has_endpoint(test, server))
        return entry->item();
    }
  return 0;
}

void
Session::make_dir (const char *dirname)
{
  this->base_dir_ = dirname;
}

void
Session::outfile (const char *o)
{
  this->outfile_ = o;
}

bool
Session::has_dir (void)
{
  return this->base_dir_.length() > 0;
}

bool
Session::has_outfile (void)
{
  return this->outfile_.length() > 0;
}

ostream *
Session::stream_for ( ostream *oldstream, HostProcess *hp, const char *sub)
{
  if (this->has_dir())
    {
      ACE_CString outname = this->base_dir_;

      if (oldstream == 0)
        {
          ACE_OS::mkdir(this->base_dir_.c_str());
        }
      delete oldstream;
      outname += ACE_DIRECTORY_SEPARATOR_CHAR;
      if (hp != 0)
        {
          outname += hp->proc_name();
          ACE_OS::mkdir(outname.c_str());
          outname += ACE_DIRECTORY_SEPARATOR_CHAR;
        }
      outname += (sub == 0) ? "summary.txt" : sub;
      return new ofstream (outname.c_str());
    }

  if (oldstream != 0)
    return oldstream;
  if (this->has_outfile())
    return new ofstream(this->outfile_.c_str());
  else
    return &cout;
}

void
Session::dump ()
{
  bool single = !this->has_dir();
  ostream *strm = this->stream_for(0);

  // report session metrics

  if (single)
    *strm << "Session summary report: "
        << this->processes_.current_size() << " Processes detected." << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      entry->item()->dump_summary (*strm);
    }

  if (single)
    *strm << "\n\n\nSession detail threads report: " << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      strm = stream_for (strm,entry->item(),"threads.txt");
      entry->item()->dump_thread_detail (*strm);
    }

  if (single)
    *strm << "\n\n\nSession detail peer process report: " << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      strm = stream_for (strm,entry->item(),"peer_processes.txt");
      entry->item()->dump_peer_detail (*strm);
    }

  if (single)
    *strm << "\n\n\nSession detail object report: " << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      strm = stream_for (strm,entry->item(),"objects.txt");
      entry->item()->dump_object_detail (*strm);
    }

  if (single)
    *strm << "\n\n\nSession detail invocation by peer process report: " << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      strm = stream_for (strm,entry->item(),"invocation_by_peer.txt");
      entry->item()->dump_invocation_detail (*strm);
    }

  if (single)
    *strm << "\n\n\nSession detail invocation by thread report: " << endl;
  for (Procs_By_Name::ITERATOR i (this->procs_by_name_); !i.done(); i.advance())
    {
      Procs_By_Name::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      strm = stream_for (strm,entry->item(),"invocation_by_thread.txt");
//       entry->item()->dump_invocation_detail (*strm);
       entry->item()->dump_thread_invocations (*strm);
    }
  if (this->has_outfile() || this->has_dir())
    delete strm;
}


// iterate over the collection of host processes to associate peer
// processes via endpoints.
void
Session::reconcile (void)
{
  for (Processes::ITERATOR i (this->processes_); !i.done(); i.advance())
    {
      Processes::ENTRY *entry;
      if (i.next(entry) == 0)
        continue;
      entry->item()->reconcile_peers(this);
    }

}