| 1 |
/* stats.h (* Microsoft C++ 8.0 *) |
| 2 |
$Id: stats.h,v 1.3 1997/10/18 04:57:43 elf Exp $ |
| 3 |
|
| 4 |
written by Marc Singer |
| 5 |
3 October 1996 |
| 6 |
|
| 7 |
This file is part of the project XO. See the file README for |
| 8 |
more information. |
| 9 |
|
| 10 |
Copyright (C) 1997 Marc Singer |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or |
| 13 |
modify it under the terms of the GNU General Public License as |
| 14 |
published by the Free Software Foundation; either version 2 of the |
| 15 |
License, or (at your option) any later version. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but |
| 18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
in a file called COPYING along with this program; if not, write to |
| 24 |
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
| 25 |
02139, USA. |
| 26 |
|
| 27 |
----------- |
| 28 |
DESCRIPTION |
| 29 |
----------- |
| 30 |
|
| 31 |
Support for (simple) statistical analysis of program performance |
| 32 |
data. |
| 33 |
|
| 34 |
*/ |
| 35 |
|
| 36 |
#if !defined (__STATS_H__) |
| 37 |
# define __STATS_H__ |
| 38 |
|
| 39 |
/* ----- Includes */ |
| 40 |
|
| 41 |
#include <sys/times.h> |
| 42 |
#include <sys/resource.h> |
| 43 |
#if defined (HAVE_MEMORY_H) |
| 44 |
# include <memory.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
/* ----- Class Globals/Statics */ |
| 48 |
|
| 49 |
#define C_STAT_SAMPLES 200 // Samples saved for rolling statistics |
| 50 |
|
| 51 |
/* ----- Methods */ |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
class LStatistics { |
| 56 |
protected: |
| 57 |
unsigned long m_cSamples; // Number of samples collected |
| 58 |
long m_rgSamples[C_STAT_SAMPLES]; // Sample data |
| 59 |
|
| 60 |
public: |
| 61 |
|
| 62 |
LStatistics () { |
| 63 |
zero (); } |
| 64 |
~LStatistics () { } |
| 65 |
void zero () { |
| 66 |
memset (this, 0, sizeof (*this)); } |
| 67 |
|
| 68 |
void sample (long l); |
| 69 |
|
| 70 |
long samples (void) { |
| 71 |
return m_cSamples; } |
| 72 |
int count (void) { |
| 73 |
return (m_cSamples > C_STAT_SAMPLES) ? C_STAT_SAMPLES : (int) m_cSamples; } |
| 74 |
float mean (void); |
| 75 |
float stddev (void); |
| 76 |
void calc (float& rMean, float& rStddev, long& min, long& max); |
| 77 |
}; |
| 78 |
|
| 79 |
class LTime { |
| 80 |
protected: |
| 81 |
struct tms m_times; |
| 82 |
struct rusage m_usage; |
| 83 |
struct timeval m_timeval; |
| 84 |
|
| 85 |
public: |
| 86 |
LTime () { |
| 87 |
zero (); } |
| 88 |
~LTime () {} |
| 89 |
void zero () { |
| 90 |
memset (this, 0, sizeof (*this)); } |
| 91 |
|
| 92 |
void reset (void); |
| 93 |
long delta (void); |
| 94 |
|
| 95 |
}; |
| 96 |
|
| 97 |
#endif /* __STATS_H__ */ |
| 98 |
|