5 #include "rtinst/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);
55 void enable() { status = histActive; }
56 void disable() { status = histInactive; }
57 sampleValue getValue();
58 sampleValue getValue(timeStamp start, timeStamp end);
59 void addInterval(timeStamp start, timeStamp end,
60 sampleValue value, Boolean smooth);
61 void addPoint(timeStamp start, sampleValue value) {
62 addInterval(start, start, value, False);
64 int subscribe(timeStamp maxRate,subscriberCallBack func,void *);
65 void unsubscribe(int id) {
66 subscribers.remove((HistogramSubscriber*)id);
68 timeStamp currentTime() {
69 return((timeStamp)(lastGlobalBin*bucketSize));
71 static int numBins; /* max bins to use */
75 void bucketValue(timeStamp start, timeStamp end,
76 sampleValue value, Boolean smooth);
78 static timeStamp bucketSize; /* width of a bucket */
79 static timeStamp total_time; /* numBins * bucketSize */
80 static int lastGlobalBin; /* global point we have data from */
81 static Histogram *allHist; /* linked list of all histograms */
83 Histogram *next; /* linked list of all histograms */
84 int lastBin; /* current (for this hist) last bin */
87 Boolean smooth; /* prevent values greater than binWidth */
88 metricStyle metricType; /* sampled function or event counter */
89 int intervalCount; /* # of intervals in use */
90 int intervalLimit; /* # of intervals in use */
95 List<HistogramSubscriber*> subscribers;