00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <Basics.H>
00026 #include <VestaLog.H>
00027 #include <Recovery.H>
00028 #include <VestaLogSeq.H>
00029 #include <FP.H>
00030 #include <CacheArgs.H>
00031 #include <CacheConfig.H>
00032 #include <GraphLog.H>
00033
00034 using std::cout;
00035 using std::cerr;
00036 using std::endl;
00037
00038 void ReadGraphLog(RecoveryReader &rd, bool verbose, int &num,
00039 int &rootCnt, int &nodeCnt)
00040 throw (VestaLog::Error, VestaLog::Eof)
00041 {
00042 while (!rd.eof()) {
00043 GraphLog::Entry *entry = GraphLog::Entry::Recover(rd);
00044 if (entry->kind == GraphLog::RootKind) {
00045 rootCnt++;
00046 } else if (entry->kind == GraphLog::NodeKind) {
00047 nodeCnt++;
00048 } else {
00049 cerr << "Fatal error: unrecognized graph log node:" << endl;
00050 cerr << " kind = " << entry->kind << endl;
00051 cerr << "Exiting..." << endl;
00052 exit(1);
00053 }
00054 if (verbose) {
00055 cout << "*** Entry " << num++ << " ***" << endl;
00056 entry->DebugFull(cout);
00057 cout << endl;
00058 } else {
00059 entry->Debug(cout);
00060 }
00061 cout.flush();
00062 delete entry;
00063 }
00064 }
00065
00066 void SyntaxError(char *msg, char *arg = (char *)NULL) throw ()
00067 {
00068 cerr << "Error: " << msg;
00069 if (arg != (char *)NULL) cerr << " `" << arg << "'";
00070 cerr << endl;
00071 cerr << "Syntax: PrintGraphLog [ -verbose ]" << endl;
00072 exit(1);
00073 }
00074
00075 int main(int argc, char *argv[])
00076 {
00077 bool verbose = false;
00078 int arg;
00079 if (argc > 2) SyntaxError("too many arguments");
00080 for (arg = 1; arg < argc; arg++) {
00081 if (*argv[arg] == '-') {
00082 if (CacheArgs::StartsWith(argv[arg], "-verbose")) {
00083 verbose = true;
00084 continue;
00085 }
00086 }
00087 SyntaxError("unrecognized argument", argv[arg]);
00088 }
00089 if (!verbose) {
00090 cout << "Graph log entries:" << endl;
00091 }
00092
00093 try {
00094
00095 VestaLogSeq graphLogSeq(Config_GraphLogPath.chars());
00096 graphLogSeq.Open( -1, true);
00097 RecoveryReader *rd;
00098
00099
00100 int num = 0, rootCnt = 0, nodeCnt = 0;
00101 while ((rd = graphLogSeq.Next()) != (RecoveryReader *)NULL) {
00102 ReadGraphLog(*rd, verbose, num,
00103 rootCnt, nodeCnt);
00104 }
00105
00106
00107 cout << "*** Totals ***" << endl;
00108 cout << " roots = " << rootCnt << endl;
00109 cout << " nodes = " << nodeCnt << endl;
00110 }
00111 catch (VestaLog::Error &err) {
00112 cerr << "VestaLog fatal error -- failed reading graph log:" << endl;
00113 cerr << " " << err.msg << endl;
00114 cerr << "Exiting..." << endl;
00115 exit(1);
00116 }
00117 catch (VestaLog::Eof) {
00118 cerr << "VestaLog fatal error: ";
00119 cerr << "unexpected EOF while reading graph log; exiting..." << endl;
00120 exit(1);
00121 }
00122 return 0;
00123 }