Added fold callback and changed from multiple data callbacks to one per
[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 #ifndef False
8 #define False   0
9 #define True    1
10 #endif
11
12 typedef double timeStamp;
13
14 typedef struct {
15     timeStamp start;
16     timeStamp end;
17     sampleValue value;
18 } Interval;
19
20 typedef enum { HistInterval, HistBucket } histType;
21 typedef enum { HistNewValue, HistNewTimeBase } callType;
22 typedef sampleValue Bin;
23
24 typedef void (*foldCallBack)(timeStamp, void* userData);
25
26 typedef void (*dataCallBack)(timeStamp st,
27                              timeStamp en,
28                              timeStamp value,
29                              void *userData);
30
31 class Histogram;
32
33 typedef enum { histActive, histInactive } histStatus;
34 typedef enum { histSum, histAverage } histCompact;
35 typedef enum { histSplit, histSet } histAddMode;
36 typedef enum { EventCounter, SampledFunction } metricStyle;
37
38 class Histogram {
39         friend class histDisplay;
40         void newDataFunc(callType type, timeStamp time, void* userData);
41     public:
42         Histogram(metricStyle, dataCallBack, foldCallBack, void* );
43         Histogram(Bin *buckets, metricStyle, dataCallBack, foldCallBack, void*);
44         sampleValue getValue();
45         sampleValue getValue(timeStamp start, timeStamp end);
46         void addInterval(timeStamp start, timeStamp end, 
47             sampleValue value, Boolean smooth);
48         void addPoint(timeStamp start, sampleValue value) {
49             addInterval(start, start, value, False);
50         }
51         timeStamp currentTime() { 
52                 return((timeStamp)(lastGlobalBin*bucketSize)); 
53         }
54         static int numBins;             /* max bins to use */
55     private:
56         void foldAllHist();
57         void convertToBins();
58         void bucketValue(timeStamp start, timeStamp end, 
59                 sampleValue value, Boolean smooth);
60
61         static timeStamp bucketSize;    /* width of a bucket */
62         static timeStamp total_time;    /* numBins * bucketSize */
63         static int lastGlobalBin;       /* global point we have data from */
64         static Histogram *allHist;      /* linked list of all histograms */
65
66         Histogram *next;                /* linked list of all histograms */
67         int lastBin;                    /* current (for this hist) last bin */
68
69         histType storageType;   
70         Boolean smooth;         /* prevent values greater than binWidth */
71         metricStyle metricType; /* sampled function or event counter */
72         int intervalCount;      /* # of intervals in use */
73         int intervalLimit;      /* # of intervals in use */
74         union {
75             Bin *buckets;
76             Interval *intervals;
77         } dataPtr; 
78         dataCallBack dataFunc;
79         foldCallBack foldFunc;
80         void *cData;
81 };
82
83 #endif