Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PrintGraphLog.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Thu Aug  5 01:15:05 EDT 2004 by ken@xorian.net  
00020 //      modified on Sat Feb 12 13:12:45 PST 2000 by mann  
00021 //      modified on Sun Aug 23 12:20:42 PDT 1998 by heydon
00022 
00023 // Read the graph log and print its complete contents
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, /*INOUT*/ int &num,
00039   /*INOUT*/ int &rootCnt, /*INOUT*/ 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         // open "graphLog"
00095         VestaLogSeq graphLogSeq(Config_GraphLogPath.chars());
00096         graphLogSeq.Open(/*ver=*/ -1, /*readonly=*/ true);
00097         RecoveryReader *rd;
00098         
00099         // read "graphLog"
00100         int num = 0, rootCnt = 0, nodeCnt = 0;
00101         while ((rd = graphLogSeq.Next()) != (RecoveryReader *)NULL) {
00102             ReadGraphLog(*rd, verbose, /*INOUT*/ num,
00103               /*INOUT*/ rootCnt, /*INOUT*/ nodeCnt);
00104         }
00105 
00106         // print totals
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 }

Generated on Mon May 8 00:48:35 2006 for Vesta by  doxygen 1.4.2