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

vperfdebug.C

Go to the documentation of this file.
00001 // Copyright (C) 2004, Kenneth C. Schalk
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 //
00020 // vperfdebug.C - Utility for controlling the repository's performance
00021 // debugging features.
00022 //
00023 // Last modified on Mon Dec 13 12:42:50 EST 2004 by ken@xorian.net  
00024 
00025 #include <VDirSurrogate.H>
00026 #include <perfDebugControl.H>
00027 
00028 extern "C" {
00029 #include <getopt.h>
00030 }
00031 
00032 using std::cout;
00033 using std::cerr;
00034 using std::endl;
00035 
00036 Text program_name;
00037 
00038 void usage()
00039 {
00040   cerr << "Usage: " << program_name << endl <<
00041     "        [-n|-N] [-l|-L]" << endl <<
00042     "        [-R repos]" << endl << endl;
00043   exit(1);
00044 }
00045 
00046 int
00047 main(int argc, char* argv[])
00048 {
00049   // Save the program name
00050   program_name = Text(argv[0]);
00051 
00052   // Set of performance debugging features that we want to be turned
00053   // on.
00054   Basics::uint64 settings = 0;
00055 
00056   try
00057     {
00058       // Use the repository from the config file by default
00059       Text repos;
00060       bool default_repos = true;
00061       Text host(VDirSurrogate::defaultHost());
00062       Text port(VDirSurrogate::defaultPort());
00063       // Parse command line
00064       opterr = 0;
00065       for (;;)
00066         {
00067           int c = getopt(argc, argv, "nNlLR:");
00068           if (c == EOF) break;
00069           switch (c)
00070             {
00071             case 'n':
00072               settings |= PerfDebug::nfsCallTiming;
00073               break;
00074             case 'N':
00075               settings &= ~((Basics::uint64) PerfDebug::nfsCallTiming);
00076               break;
00077             case 'l':
00078               settings |= PerfDebug::centralLockTiming;
00079               break;
00080             case 'L':
00081               settings &= ~((Basics::uint64) PerfDebug::centralLockTiming);
00082               break;
00083             case 'R':
00084               repos = optarg;
00085               default_repos = false;
00086               break;
00087             case '?':
00088             default:
00089               usage();
00090             }
00091         }
00092 
00093       // We should have used all the arguments
00094       if (argc != optind)
00095         {
00096           usage();
00097         }
00098 
00099       // Use a nondefault repository if specified
00100       if (!default_repos)
00101         {
00102           int colon = repos.FindCharR(':');
00103           if (colon == -1)
00104             {
00105               host = repos;
00106               repos = repos + ":" + port;
00107             }
00108           else
00109             {
00110               host = repos.Sub(0, colon);
00111               port = repos.Sub(colon+1);
00112             }
00113         }
00114 
00115       // Ask the repository to enable/disable the performance
00116       // debugging features
00117       Basics::uint64 result = PerfDebug::Set(settings, host, port);
00118 
00119       // Print out which features the repository now has
00120       // enabled/disabled
00121       if(result & PerfDebug::nfsCallTiming)
00122         {
00123           cout << "Enabdled fine-graned NFS call timing" << endl;
00124         }
00125       else
00126         {
00127           cout << "Disabdled fine-graned NFS call timing" << endl;
00128         }
00129       if(result & PerfDebug::centralLockTiming)
00130         {
00131           cout << "Enabdled central lock timing" << endl;
00132         }
00133       else
00134         {
00135           cout << "Disabdled central lock timing" << endl;
00136         }
00137 
00138       // If the repository says it has nothing turned on, maybe this
00139       // repository didn't have performance debugging compiled in
00140       if((result == 0) && (settings != 0))
00141         {
00142           cout << "(Maybe this repository doesn't have performance debugging?)"
00143                << endl;
00144         }
00145     }
00146   catch (VestaConfig::failure f)
00147     {
00148       cerr << program_name << ": " << f.msg << endl;
00149       exit(2);
00150     }
00151   catch (SRPC::failure f)
00152     {
00153       cerr << program_name
00154            << ": SRPC failure; " << f.msg << " (" << f.r << ")" << endl;
00155       exit(2);
00156     }
00157 }

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