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

infolines.h

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00039 
00040 /*
00041  This file to be included into all projects in the group
00042 
00043  CHANGES
00044 
00045  971130  ilm  reworked clas MemUsage() to give readings
00046               of both peak memory and estimated memory usage
00047               cout << MemUsage() now works similar to cout << TimeStamp;
00048 */
00049 #ifndef  _INFOLINES_H_
00050 #define  _INFOLINES_H_
00051 
00052 #include <stdlib.h>
00053 #include <time.h>
00054 #include <string.h>
00055 #include <string>
00056 #include <iostream>
00057 #include <iomanip>
00058 #include "abkcpunorm.h"
00059 
00060 using std::istream;
00061 using std::ostream;
00062 using std::endl;
00063 using std::cout;
00064 using std::cin;
00065 using std::cerr;
00066 using std::setw;
00067 using std::flush;
00068 
00069 //: Baseclass for TimeStamp, CmdLine, Platform, MemUsage, MemChange, User. 
00070 //  it will be used, e.g., when writing commented info into files. The class
00071 //  is printable.
00072 class InfoLine
00073 {
00074 protected :
00075   char * _infoLine;
00076   InfoLine():_infoLine(NULL) {}
00077 public:
00078   virtual ~InfoLine() { if (_infoLine) delete[] _infoLine; }
00079   virtual operator const char* () const { return _infoLine; }
00080 };
00081 
00082 //: Prints a command line.
00083 struct CmdLine : public InfoLine
00084 { CmdLine(int argc, const char *argv[]) ; };
00085 
00086 //: Prints user's home directory
00087 struct UserHomeDir : public InfoLine
00088 { UserHomeDir() ; /* defined in platfDepend.cxx */ };
00089 
00090 //: Prints the location of the executable
00091 struct ExecLocation : public InfoLine
00092 { ExecLocation(); /* defined in platfDepend.cxx */ };
00093 
00094 //: Prints current's time
00095 struct TimeStamp : public InfoLine
00096 { TimeStamp(); };
00097 
00098 //: Prints information about the platform you are using
00099 struct Platform : public InfoLine
00100 {
00101   /* defined in platfDepend.cxx */
00102   Platform();       
00103 };
00104 
00105 //: Prints information about currnt user 
00106 struct User : public InfoLine
00107 {
00108   /* defined in platfDepend.cxx */
00109   User();          
00110 };
00111 
00112 //: Prints information about the memory usage of the process
00113 class MemUsage
00114 {
00115    double _peak;
00116    // in Mbytes
00117    double _estimate;
00118 public:
00119    /* defined in platfDepend.cxx */
00120    MemUsage();       
00121    double getPeakMem()  const { return _peak; }
00122    double getEstimate() const { return _estimate; }
00123    operator double()    const { return _estimate; }
00124 };
00125 
00126 std::ostream& operator<<(std::ostream&, const MemUsage&);
00127 
00128 class MaxMem
00129 {
00130    static double      _peak;
00131    static std::string _message;
00132 public:
00133    static void update(const char* message) {
00134       double currmem = MemUsage();
00135       if(currmem > _peak) {
00136         _peak = currmem;
00137         _message = message;
00138       }
00139    }
00140    static void summary(void) {
00141       cout<<"Maximum memory: "<<_peak<<"Mb which came from \""
00142           <<_message.c_str()<<"\""<<endl;
00143    }
00144    static double getPeak() { return _peak; }
00145    static std::string getMessage() { return _message; }
00146 };
00147 
00148 class MemChange
00149 {
00150    double _memUsageMark; 
00151    // in Mbytes
00152 public:
00153    /*  defined in platfDepend.cxx */
00154    MemChange();         
00155    void resetMark();        
00156    // does the same as ctor 
00157    operator double() const; 
00158    // returns the change wrt the stored value
00159 };
00160 
00161 //: For system information
00162 struct SysInfo
00163 {
00164    TimeStamp tm;
00165    Platform  pl;
00166    CPUNormalizer cpunorm;
00167    User      us;
00168    MemUsage  mu;
00169    
00170    SysInfo() {};
00171 };
00172 
00173 std::ostream& operator<<(std::ostream&, const SysInfo&);
00174 
00175 #endif 

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2