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