Added method to get histogram buckets.
[dyninst.git] / pdutil / 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         int getBuckets(sampleValue *buckets, int numberOfBuckets, int first);
47         void addInterval(timeStamp start, timeStamp end, 
48             sampleValue value, Boolean smooth);
49         void addPoint(timeStamp start, sampleValue value) {
50             addInterval(start, start, value, False);
51         }
52         timeStamp currentTime() { 
53                 return((timeStamp)(lastGlobalBin*bucketSize)); 
54         }
55         static int numBins;             /* max bins to use */
56         static timeStamp bucketSize;    /* width of a bucket */
57     private:
58         void foldAllHist();
59         void convertToBins();
60         void bucketValue(timeStamp start, timeStamp end, 
61                 sampleValue value, Boolean smooth);
62
63         static timeStamp total_time;    /* numBins * bucketSize */
64         static int lastGlobalBin;       /* global point we have data from */
65         static Histogram *allHist;      /* linked list of all histograms */
66
67         Histogram *next;                /* linked list of all histograms */
68         int lastBin;                    /* current (for this hist) last bin */
69
70         histType storageType;   
71         Boolean smooth;         /* prevent values greater than binWidth */
72         metricStyle metricType; /* sampled function or event counter */
73         int intervalCount;      /* # of intervals in use */
74         int intervalLimit;      /* # of intervals in use */
75         union {
76             Bin *buckets;
77             Interval *intervals;
78         } dataPtr; 
79         dataCallBack dataFunc;
80         foldCallBack foldFunc;
81         void *cData;
82 };
83
84 #endif