summaryrefslogtreecommitdiff
path: root/TAO/utils/logWalker/logWalker.cpp
blob: e5ca05a10e63573c34a1719ea6823d9d0b69b242 (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
// $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_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')
            {
              outfile = new ACE_TCHAR[ACE_OS::strlen(buffer) - 3];
              ACE_OS::strcpy(buffer+3, ACE_TEXT_ALWAYS_CHAR(outfile));
              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;
            }
        }
      if (ACE_OS::strchr(buffer,'=') == 0)
        {
          ACE_DEBUG ((LM_DEBUG,"Unparsable string: %s\n",
                      buffer));
          return;
        }
      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 log(session);
      log.init(filename.c_str(), alias);
    }
}

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("-o")) == 0)
        {
          outfile = argv[++i];
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-m")) == 0)
        {
          parse_manifest (session, argv[++i]);
          continue;
        }
      if (ACE_OS::strcasecmp (argv[i], ACE_TEXT("-t")) == 0)
        {
          Session::set_tao_version (argv[++i]);
          continue;
        }
      if (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("-p")) == 0)
        {
          session.default_service (ACE_TEXT_ALWAYS_CHAR (argv[++i]));
          continue;
        }

      Log log(session);
      ACE_DEBUG ((LM_DEBUG,"Parsing file %s\n", argv[i]));
      if (log.init(argv[i]) == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "Could not parse log file %s\n", argv[i]));
          continue;
        }
      
    }

  session.reconcile();
  ostream *strm;
  if (outfile == 0)
    strm = &cout;
  else
    strm = new ofstream(ACE_TEXT_ALWAYS_CHAR (outfile));

  session.dump(*strm);

  return 0;
}