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