4 #include "util/h/list.h"
5 #include "rtinst/h/trace.h"
12 typedef double timeStamp;
20 typedef enum { HistInterval, HistBucket } histType;
21 typedef enum { HistNewValue, HistNewTimeBase } callType;
22 typedef sampleValue Bin;
24 typedef void (*subscriberCallBack)(callType, timeStamp, void* userData);
28 * upcall mechanism for routines that need to find out about changes to
32 class HistogramSubscriber {
35 HistogramSubscriber(timeStamp maxRate, subscriberCallBack func, void *userData);
41 subscriberCallBack callBack;
44 typedef enum { histActive, histInactive } histStatus;
45 typedef enum { histSum, histAverage } histCompact;
46 typedef enum { histSplit, histSet } histAddMode;
47 typedef enum { EventCounter, SampledFunction } metricStyle;
50 friend class histDisplay;
51 void newDataFunc(callType type, timeStamp time, void* userData);
53 Histogram(metricStyle);
54 Histogram(Bin *buckets, metricStyle);
56 void enable() { status = histActive; }
57 void disable() { status = histInactive; }
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);
66 int subscribe(timeStamp maxRate,subscriberCallBack func,void *);
67 void unsubscribe(int id) {
68 subscribers.remove((HistogramSubscriber*)id);
70 timeStamp currentTime() {
71 return((timeStamp)(lastGlobalBin*bucketSize));
73 static int numBins; /* max bins to use */
77 void bucketValue(timeStamp start, timeStamp end,
78 sampleValue value, Boolean smooth);
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 */
85 Histogram *next; /* linked list of all histograms */
86 int lastBin; /* current (for this hist) last bin */
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 */
97 List<HistogramSubscriber*> subscribers;