Planeshift

psprofile.h

Go to the documentation of this file.
00001 /*
00002  * psprofile.h by Ondrej Hurt
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program 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
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef __PSPROFILE_H__
00021 #define __PSPROFILE_H__
00022 
00023 #include <csutil/parray.h>
00024 #include <csutil/csstring.h>
00025 #include <csutil/hash.h>
00026 
00031 /****************************************************************************************
00032 * General profilling library
00033 *
00034 * It is used to measure consumption of certain hardware resources (time, bandwidth etc) 
00035 * by different operations. "Operation" is some action that consumes resources.
00036 * Profiler keeps aggregate statistics for each operation. When the operation
00037 * runs more than once, the consumption is added.
00038 *
00039 * Statistics of one operation are kept in psOperProfile.
00040 * All psOperProfiles are kept in some subclass of psOperProfileSet.
00041 * Abstract class psOperProfileSet offers some common actions that can be done with
00042 * the statistics, regardless of their nature. But other actions must be implemented
00043 * in its subclasses. The most important subclass is psNamedProfiles that can be used
00044 * for most purposes.
00045 *****************************************************************************************/
00046 
00048 class psOperProfile
00049 {
00050 public:
00051     psOperProfile(const csString & desc);
00052     
00054     void AddConsumption(double cons);
00055     
00057     void Reset();
00058     
00062     csString Dump(double totalConsumption, const csString & unitName);
00063     
00064     double GetConsumption();
00065     
00067     static int cmpProfs(const void * a, const void * b);
00068 
00069 protected:
00070     csStringFast<100> desc;         
00071     double count;          
00072     double consumption ;   
00073     double maxCons; // the maximum resource consumption per operation 
00074                     //     that we witnessed
00075 };
00076 
00082 class psOperProfileSet
00083 {
00084 public:
00085     psOperProfileSet();
00086     
00089     void Dump(const csStringFast<50> & unitName, csStringFast<50> & header, csStringFast<50> & list);
00090     
00091     void Reset();
00092     
00093 protected:
00094     csPDelArray<psOperProfile> profs; 
00097     csTicks profStart;
00098 };
00099 
00100 
00104 class psNamedProfiles : public psOperProfileSet
00105 {
00106 public:
00108     virtual ~psNamedProfiles() { }  
00109 
00111     virtual void AddCons(const csString & operName, csTicks time);
00112     
00115     csString Dump(const csString & unitName, const csString & header);
00116     
00117     void Reset();
00118 
00119 protected:
00121     csHash<psOperProfile*, csString> namedProfs;
00122 };
00123 
00124 
00126 class psStopWatch
00127 {
00128 public:
00130     void Start();
00132     csTicks Stop();
00133 protected:
00134     csTicks start;
00135 };
00136 
00139 #endif