re-organized some of the header files so that definitions that are
[dyninst.git] / pdutil / h / hist.h
1 #ifndef HIST
2 #define HIST
3
4 #include "util/h/list.h"
5 #include "util/h/sys.h"
6
7 typedef enum { HistInterval, HistBucket } histType;
8 typedef enum { HistNewValue, HistNewTimeBase } callType;
9 typedef sampleValue Bin;
10
11 typedef void (*foldCallBack)(timeStamp, void* userData);
12
13 typedef void (*dataCallBack)(sampleValue *buckets,
14                              int numberOfBuckets,
15                              int first,
16                              void *userData);
17
18 class Histogram;
19
20 typedef enum { histActive, histInactive } histStatus;
21 typedef enum { histSum, histAverage } histCompact;
22 typedef enum { histSplit, histSet } histAddMode;
23 typedef enum { EventCounter, SampledFunction } metricStyle;
24
25 class Histogram {
26         void newDataFunc(callType type, timeStamp time, void* userData);
27     public:
28         ~Histogram();
29         Histogram(metricStyle, dataCallBack, foldCallBack, void* );
30         Histogram(Bin *buckets, metricStyle, dataCallBack, foldCallBack, void*);
31         sampleValue getValue();
32         sampleValue getValue(timeStamp start, timeStamp end);
33         int getBuckets(sampleValue *buckets, int numberOfBuckets, int first);
34         void addInterval(timeStamp start, timeStamp end, 
35             sampleValue value, bool smooth);
36         void addPoint(timeStamp start, sampleValue value) {
37             addInterval(start, start, value, false);
38         }
39         timeStamp currentTime() { 
40                 return((timeStamp)(lastGlobalBin*bucketSize)); 
41         }
42         static int numBins;             /* max bins to use */
43         static timeStamp bucketSize;    /* width of a bucket */
44         static int lastGlobalBin;       /* global point we have data from */
45     private:
46         void foldAllHist();
47         void convertToBins();
48         void bucketValue(timeStamp start, timeStamp end, 
49                 sampleValue value, bool smooth);
50
51         static timeStamp total_time;    /* numBins * bucketSize */
52         static Histogram *allHist;      /* linked list of all histograms */
53
54         Histogram *next;                /* linked list of all histograms */
55         int lastBin;                    /* current (for this hist) last bin */
56
57         histType storageType;   
58         bool smooth;            /* prevent values greater than binWidth */
59         metricStyle metricType; /* sampled function or event counter */
60         int intervalCount;      /* # of intervals in use */
61         int intervalLimit;      /* # of intervals in use */
62         union {
63             Bin *buckets;
64             Interval *intervals;
65         } dataPtr; 
66         dataCallBack dataFunc;
67         foldCallBack foldFunc;
68         void *cData;
69 };
70
71 #endif