summaryrefslogtreecommitdiff
path: root/TAO/utils/logWalker/logWalker.cpp
blob: cbd0c7375c38ababf8d1f4e3f63f65129cd07b2a (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
// $Id$

// Utility to traverse and simplify verbose log files.
//
// The goal is to take a collection of log files and extract details
// related to connections, objects, and invocations to separate out
// perhaps multiple processes, or at least threads to get a sense of
// invocation lifecycle.
//
// Ideally a collection of files could be used so that invocations
// that traverse many processes could be tracked.

#include "ace/OS_NS_stdio.h"
#include "ace/Log_Msg.h"
#include "ace/streams.h"
#include "ace/OS_NS_strings.h"
#include "ace/Tokenizer_T.h"

#include "Invocation.h"
#include "PeerObject.h"
#include "PeerProcess.h"
#include "Session.h"
#include "Log.h"

ACE_TCHAR *outfile = 0;

void
parse_filename (Session &session, char * buffer)
{
  Log log(session);
  if (ACE_OS::strchr(buffer,'=') == 0)
    {
      log.init(ACE_TEXT_CHAR_TO_TCHAR(buffer));
    }
  else
    {
      ACE_Tokenizer_T<char> tokens(buffer);
      tokens.delimiter_replace('=', 0);
      char *alias = tokens.next();
      ACE_TString filename = ACE_TEXT_CHAR_TO_TCHAR(tokens.next());
      log.init(filename.c_str(), alias);
    }
}

void
parse_manifest (Session &session, ACE_TCHAR *filename)
{
  // get list of logs, aliases, and other config from file
  ifstream strm (ACE_TEXT_ALWAYS_CHAR (filename));
  if (!strm.is_open())
    {
      ACE_DEBUG ((LM_DEBUG,"cannot open manifest file %C\n", filename));
      return;
    }
  char buffer[500];
  while (!strm.eof())
    {
      strm.getline(buffer,500);
      if (buffer[0] == '\0' ||
          buffer[0] == '#')
        {
          continue;
        }
      if (buffer[0] == '-')
        {
          if (buffer[1] == 'o')
            {
              if (session.has_dir())
                {
                  ACE_ERROR ((LM_ERROR,
                              "supply either output file "
                              "or directory but not both\n"));
                  ACE_OS::exit (0);
                }
              session.outfile (buffer+3);
              continue;
            }
          if (buffer[1] == 'd')
            {
              if (session.has_outfile())
                {
                  ACE_ERROR ((LM_ERROR,
                              "supply either output file "
                              "or directory but not both\n"));
                  ACE_OS::exit (0);
                }
              session.make_dir (buffer+3);
              continue;
            }
          if (buffer[1] == 't')
            {
              Session::set_tao_version (ACE_TEXT_CHAR_TO_TCHAR (buffer + 3));
              continue;
            }
          if (buffer[1] == 'a')
            {
              session.alternate_address(buffer+3);
              continue;
            }
          if (buffer[1] == 'p')
            {
              session.default_service (buffer+3);
              continue;
            }
        }
      parse_filename (session, buffer);
    }
}

void
print_help (void)
{
  ACE_DEBUG ((LM_DEBUG, "tao_logWalker recongizes the following arguments\n"));
  ACE_DEBUG ((LM_DEBUG, "-outfile <filename> - write all output to specified file\n"));
  ACE_DEBUG ((LM_DEBUG, "-dir <directory> - create separate output files, one per log, and put them in specified directory.\n   Either -outfile or -dir may be set but not both. Default output to stdout.\n"));
  ACE_DEBUG ((LM_DEBUG, "-manifest <manifest> - Take inputs from named manifest file\n"));
  ACE_DEBUG ((LM_DEBUG, "-tao <1.5 .. 2.0>  - set source TAO version, default 2.0\n"));
  ACE_DEBUG ((LM_DEBUG, "-date <1|2> - interpret dates as 1) YYYY-MM-DD hh:mm:ss.sss, or 2) MMM DD hh:mm:ss.sss YYYY\n"));
  ACE_DEBUG ((LM_DEBUG, "-alias <name=address> - bind an alias to a host address.\n   Repeat as many times as necessary.\n"));
  ACE_DEBUG ((LM_DEBUG, "-proc <service=address> - bind a service such as Naming to a specific endpoint address\n"));
}

int
ACE_TMAIN (int argc, ACE_TCHAR **argv)
{
  if (argc < 2)
    {
      ACE_ERROR ((LM_ERROR,
                  " At least one log file must be specified\n"));
      return 0;
    }
  Session session;
  for (int i = 1; i < argc; i++)
    {
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-outfile")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-o")) == 0)
        {
          if (session.has_dir())
            ACE_ERROR_RETURN ((LM_ERROR,
                               "supply either output file "
                               "or directory but not both\n"), 0);
          session.outfile(ACE_TEXT_ALWAYS_CHAR(argv[++i]));
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-dir")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-d")) == 0)
        {
          if (session.has_outfile())
            ACE_ERROR_RETURN ((LM_ERROR,
                               "supply either output file "
                               "or directory but not both\n"), 0);
          session.make_dir (ACE_TEXT_ALWAYS_CHAR(argv[++i]));
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-manifest")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-m")) == 0)
        {
          parse_manifest (session, argv[++i]);
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-tao")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-t")) == 0)
        {
          if (Session::set_tao_version (argv[++i]))
            continue;
          else
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT("TAO version must be 1.5, 1.6, 1.7, 1.8, or 2.0 \n")), 0);
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-date")) == 0)
        {
          if (Session::set_date_format (argv[++i]))
            continue;
          else
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT("Date format option must be 1 or 2\n")), 0);
        }

      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-alias")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-a")) == 0)
        {
          session.alternate_address (ACE_TEXT_ALWAYS_CHAR (argv[++i]));
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-proc")) == 0 ||
          ACE_OS::strcasecmp (argv[i], ACE_TEXT("-p")) == 0)
        {
          session.default_service (ACE_TEXT_ALWAYS_CHAR (argv[++i]));
          continue;
        }
      if (argv[i][0] == ACE_TEXT('-'))
        {
          print_help ();
          return 0;
        }

      Log log(session);

      parse_filename (session, ACE_TEXT_ALWAYS_CHAR (argv[i]));
    }

  session.reconcile();

  session.dump();

  return 0;
}