Rearranged order of includes for igen-generated code, so that it compiles
[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 (*subscriberCallBack)(callType, timeStamp, void* userData);
25 class Histogram;
26
27 /*
28  * upcall mechanism for routines that need to find out about changes to
29  *   a histogram.
30  *
31  */
32 class HistogramSubscriber {
33         friend Histogram;
34     public:
35         HistogramSubscriber(timeStamp maxRate, subscriberCallBack func, void *userData);
36         deliver(int bin);
37     private:
38         void *userData;
39         timeStamp interval;
40         timeStamp lastCall;
41         subscriberCallBack callBack; 
42 };
43
44 typedef enum { histActive, histInactive } histStatus;
45 typedef enum { histSum, histAverage } histCompact;
46 typedef enum { histSplit, histSet } histAddMode;
47 typedef enum { EventCounter, SampledFunction } metricStyle;
48
49 class Histogram {
50         friend class histDisplay;
51         void newDataFunc(callType type, timeStamp time, void* userData);
52     public:
53         Histogram(metricStyle);
54         Histogram(Bin *buckets, metricStyle);
55 #ifdef notdef
56         void enable() { status = histActive; }
57         void disable() { status = histInactive; }
58 #endif
59         sampleValue getValue();
60         sampleValue getValue(timeStamp start, timeStamp end);
61         void addInterval(timeStamp start, timeStamp end, 
62             sampleValue value, Boolean smooth);
63         void addPoint(timeStamp start, sampleValue value) {
64             addInterval(start, start, value, False);
65         }
66         int subscribe(timeStamp maxRate,subscriberCallBack func,void *);
67         void unsubscribe(int id) { 
68                 subscribers.remove((HistogramSubscriber*)id); 
69         }
70         timeStamp currentTime() { 
71                 return((timeStamp)(lastGlobalBin*bucketSize)); 
72         }
73         static int numBins;             /* max bins to use */
74     private:
75         void foldAllHist();
76         void convertToBins();
77         void bucketValue(timeStamp start, timeStamp end, 
78                 sampleValue value, Boolean smooth);
79
80         static timeStamp bucketSize;    /* width of a bucket */
81         static timeStamp total_time;    /* numBins * bucketSize */
82         static int lastGlobalBin;       /* global point we have data from */
83         static Histogram *allHist;      /* linked list of all histograms */
84
85         Histogram *next;                /* linked list of all histograms */
86         int lastBin;                    /* current (for this hist) last bin */
87
88         histType storageType;   
89         Boolean smooth;         /* prevent values greater than binWidth */
90         metricStyle metricType; /* sampled function or event counter */
91         int intervalCount;      /* # of intervals in use */
92         int intervalLimit;      /* # of intervals in use */
93         union {
94             Bin *buckets;
95             Interval *intervals;
96         } dataPtr; 
97         List<HistogramSubscriber*> subscribers;
98 #ifdef notdef
99         histStatus status;
100 #endif
101 };
102
103 #endif