Planeshift
psprofile.h
Go to the documentation of this file.
1 /*
2  * psprofile.h by Ondrej Hurt
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef __PSPROFILE_H__
21 #define __PSPROFILE_H__
22 
23 #include <csutil/parray.h>
24 #include <csutil/csstring.h>
25 #include <csutil/hash.h>
26 
31 /****************************************************************************************
32 * General profilling library
33 *
34 * It is used to measure consumption of certain hardware resources (time, bandwidth etc)
35 * by different operations. "Operation" is some action that consumes resources.
36 * Profiler keeps aggregate statistics for each operation. When the operation
37 * runs more than once, the consumption is added.
38 *
39 * Statistics of one operation are kept in psOperProfile.
40 * All psOperProfiles are kept in some subclass of psOperProfileSet.
41 * Abstract class psOperProfileSet offers some common actions that can be done with
42 * the statistics, regardless of their nature. But other actions must be implemented
43 * in its subclasses. The most important subclass is psNamedProfiles that can be used
44 * for most purposes.
45 *****************************************************************************************/
46 
49 {
50 public:
51  psOperProfile(const csString & desc);
52 
54  void AddConsumption(double cons);
55 
57  void Reset();
58 
62  csString Dump(double totalConsumption, const csString & unitName);
63 
64  double GetConsumption();
65 
67  static int cmpProfs(const void * a, const void * b);
68 
69 protected:
70  csStringFast<100> desc;
71  double count;
72  double consumption ;
73  double maxCons; // the maximum resource consumption per operation
74  // that we witnessed
75 };
76 
83 {
84 public:
86 
89  void Dump(const csStringFast<50> & unitName, csStringFast<50> & header, csStringFast<50> & list);
90 
91  void Reset();
92 
93 protected:
94  csPDelArray<psOperProfile> profs;
97  csTicks profStart;
98 };
99 
100 
105 {
106 public:
108  virtual ~psNamedProfiles() { }
109 
111  virtual void AddCons(const csString & operName, csTicks time);
112 
115  csString Dump(const csString & unitName, const csString & header);
116 
117  void Reset();
118 
119 protected:
121  csHash<psOperProfile*, csString> namedProfs;
122 };
123 
124 
127 {
128 public:
130  void Start();
132  csTicks Stop();
133 protected:
134  csTicks start;
135 };
136 
139 #endif
double consumption
number of operations of this kind that took place
Definition: psprofile.h:72
void AddConsumption(double cons)
Use this to notify about resource consumption.
double maxCons
total resource consumption by this kind of operation
Definition: psprofile.h:73
double count
textual description
Definition: psprofile.h:71
csHash< psOperProfile *, csString > namedProfs
Maps strings IDs to their operations.
Definition: psprofile.h:121
csStringFast< 100 > desc
Definition: psprofile.h:70
csString Dump(double totalConsumption, const csString &unitName)
Return textual description of consumption statistics where &#39;totalConsumption&#39; is total consumption of...
Statistics for one operation.
Definition: psprofile.h:48
csTicks start
Definition: psprofile.h:134
void Reset()
Reset consumption counters.
Statistics of consumption by operations that are identified by names (strings) This is usable for mos...
Definition: psprofile.h:104
csTicks profStart
keeps statistics of all operations
Definition: psprofile.h:97
csPDelArray< psOperProfile > profs
Definition: psprofile.h:94
Used to measure time intervals.
Definition: psprofile.h:126
psOperProfile(const csString &desc)
virtual ~psNamedProfiles()
needed to clear MSVC warning
Definition: psprofile.h:108
double GetConsumption()
static int cmpProfs(const void *a, const void *b)
Sorting.
Statistics for all kinds of operations This class is abstract, you have to inherit from it to use it...
Definition: psprofile.h:82