Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / utils / logWalker / logWalker.cpp
blob7079d83c108e34a3aec645db5324b6f9edf11212
1 // Utility to traverse and simplify verbose log files.
2 //
3 // The goal is to take a collection of log files and extract details
4 // related to connections, objects, and invocations to separate out
5 // perhaps multiple processes, or at least threads to get a sense of
6 // invocation lifecycle.
7 //
8 // Ideally a collection of files could be used so that invocations
9 // that traverse many processes could be tracked.
11 #include "ace/OS_NS_stdio.h"
12 #include "ace/Log_Msg.h"
13 #include "ace/streams.h"
14 #include "ace/OS_NS_strings.h"
15 #include "ace/Tokenizer_T.h"
17 #include "Invocation.h"
18 #include "PeerObject.h"
19 #include "PeerProcess.h"
20 #include "Session.h"
21 #include "Log.h"
23 ACE_TCHAR *outfile = 0;
25 void
26 parse_filename (Session &session, char * buffer)
28 Log log(session);
29 if (ACE_OS::strchr(buffer,'=') == 0)
31 log.process_file (ACE_TEXT_CHAR_TO_TCHAR(buffer));
33 else
35 ACE_Tokenizer_T<char> tokens(buffer);
36 tokens.delimiter_replace('=', 0);
37 char *alias = tokens.next();
38 ACE_TString filename = ACE_TEXT_CHAR_TO_TCHAR(tokens.next());
39 log.process_file (filename.c_str(), alias);
43 void
44 parse_manifest (Session &session, ACE_TCHAR *filename)
46 // get list of logs, aliases, and other config from file
47 ifstream strm (ACE_TEXT_ALWAYS_CHAR (filename));
48 if (!strm.is_open())
50 ACE_DEBUG ((LM_DEBUG,"cannot open manifest file %C\n", filename));
51 return;
53 char buffer[500];
54 while (!strm.eof())
56 strm.getline(buffer,500);
57 if (buffer[0] == '\0' ||
58 buffer[0] == '#')
60 continue;
62 if (buffer[0] == '-')
64 if (buffer[1] == 'o')
66 if (session.has_dir())
68 ACE_ERROR ((LM_ERROR,
69 "supply either output file "
70 "or directory but not both\n"));
71 ACE_OS::exit (0);
73 session.outfile (buffer+3);
74 continue;
76 if (buffer[1] == 'd')
78 if (session.has_outfile())
80 ACE_ERROR ((LM_ERROR,
81 "supply either output file "
82 "or directory but not both\n"));
83 ACE_OS::exit (0);
85 if (buffer[2] == 'd')
87 session.make_dir (buffer+4, true);
89 else
91 session.make_dir (buffer+3, false);
93 continue;
95 if (buffer[1] == 't')
97 Session::set_tao_version (ACE_TEXT_CHAR_TO_TCHAR (buffer + 3));
98 continue;
100 if (buffer[1] == 'a')
102 session.alternate_address(buffer+3);
103 continue;
105 if (buffer[1] == 'p')
107 session.default_service (buffer+3);
108 continue;
111 parse_filename (session, buffer);
115 void
116 print_help ()
118 ACE_DEBUG ((LM_DEBUG, "tao_logWalker recongizes the following arguments\n"));
119 ACE_DEBUG ((LM_DEBUG, "-o <filename> - write all output to specified file\n"));
120 ACE_DEBUG ((LM_DEBUG, "-d[d] <directory> - create separate output files, one per log, and put them in specified directory.\n Either -o or -d may be set but not both. Default output to stdout.\n Use -dd to further split thread and peer process details onto multiple files."));
121 ACE_DEBUG ((LM_DEBUG, "-m <manifest> - Take inputs from named manifest file\n"));
122 ACE_DEBUG ((LM_DEBUG, "-t <1.5 .. 2.0> - set source TAO version, default 2.0\n"));
123 ACE_DEBUG ((LM_DEBUG, "-a <name=address> - bind an alias to a host address.\n Repeat as many times as necessary.\n"));
124 ACE_DEBUG ((LM_DEBUG, "-p <service=address> - bind a service such as Naming to a specific peer endpoint address\n"));
125 ACE_DEBUG ((LM_DEBUG, "[alias=]filename - provide a source file with an altenate name"));
129 ACE_TMAIN (int argc, ACE_TCHAR **argv)
131 if (argc < 2)
133 ACE_ERROR ((LM_ERROR,
134 " At least one log file must be specified\n"));
135 return 0;
137 Session session;
138 for (int i = 1; i < argc; i++)
140 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-o")) == 0)
142 if (session.has_dir())
143 ACE_ERROR_RETURN ((LM_ERROR,
144 "supply either output file "
145 "or directory but not both\n"), 0);
146 session.outfile(ACE_TEXT_ALWAYS_CHAR(argv[++i]));
147 continue;
149 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-d")) == 0 ||
150 ACE_OS::strcasecmp (argv[i], ACE_TEXT("-dd")) == 0)
152 if (session.has_outfile())
153 ACE_ERROR_RETURN ((LM_ERROR,
154 "supply either output file "
155 "or directory but not both\n"), 0);
156 bool split = ACE_OS::strcasecmp (argv[i], ACE_TEXT("-dd")) == 0;
157 session.make_dir (ACE_TEXT_ALWAYS_CHAR(argv[++i]), split);
158 continue;
160 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-m")) == 0)
162 parse_manifest (session, argv[++i]);
163 continue;
165 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-t")) == 0)
167 if (Session::set_tao_version (argv[++i]))
168 continue;
169 else
170 ACE_ERROR_RETURN ((LM_ERROR,
171 ACE_TEXT("TAO version must be 1.5, 1.6, 1.7, 1.8, or 2.0 \n")), 0);
173 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-a")) == 0)
175 session.alternate_address (ACE_TEXT_ALWAYS_CHAR (argv[++i]));
176 continue;
178 if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-p")) == 0)
180 session.default_service (ACE_TEXT_ALWAYS_CHAR (argv[++i]));
181 continue;
183 if (argv[i][0] == ACE_TEXT('-'))
185 print_help ();
186 return 0;
189 Log log(session);
191 parse_filename (session, ACE_TEXT_ALWAYS_CHAR (argv[i]));
194 session.reconcile();
196 session.dump();
198 return 0;