103 b[sub_bucket]++;
104 }
105
106 double HdrSeq::percentile(double level) const {
107 // target should be non-zero to find the first sample
108 int target = MAX2(1, (int) (level * num() / 100));
109 int cnt = 0;
110 for (int mag = 0; mag < MagBuckets; mag++) {
111 if (_hdr[mag] != NULL) {
112 for (int val = 0; val < ValBuckets; val++) {
113 cnt += _hdr[mag][val];
114 if (cnt >= target) {
115 return pow(10.0, MagMinimum + mag) * val / ValBuckets;
116 }
117 }
118 }
119 }
120 return maximum();
121 }
122
123 BinaryMagnitudeSeq::BinaryMagnitudeSeq() {
124 _mags = NEW_C_HEAP_ARRAY(size_t, BitsPerSize_t, mtInternal);
125 clear();
126 }
127
128 BinaryMagnitudeSeq::~BinaryMagnitudeSeq() {
129 FREE_C_HEAP_ARRAY(size_t, _mags);
130 }
131
132 void BinaryMagnitudeSeq::clear() {
133 for (int c = 0; c < BitsPerSize_t; c++) {
134 _mags[c] = 0;
135 }
136 _sum = 0;
137 }
138
139 void BinaryMagnitudeSeq::add(size_t val) {
140 Atomic::add(&_sum, val);
141
142 int mag = log2i_graceful(val) + 1;
|
103 b[sub_bucket]++;
104 }
105
106 double HdrSeq::percentile(double level) const {
107 // target should be non-zero to find the first sample
108 int target = MAX2(1, (int) (level * num() / 100));
109 int cnt = 0;
110 for (int mag = 0; mag < MagBuckets; mag++) {
111 if (_hdr[mag] != NULL) {
112 for (int val = 0; val < ValBuckets; val++) {
113 cnt += _hdr[mag][val];
114 if (cnt >= target) {
115 return pow(10.0, MagMinimum + mag) * val / ValBuckets;
116 }
117 }
118 }
119 }
120 return maximum();
121 }
122
123 // Merge this HdrSeq into hdr2: clear optional and on-by-default
124 // Note: this method isn't intrinsically MT-safe; callers must take care
125 // of any mutual exclusion as necessary.
126 void HdrSeq::merge(HdrSeq& hdr2, bool clear_this) {
127 for (int mag = 0; mag < MagBuckets; mag++) {
128 if (_hdr[mag] != NULL) {
129 int* that_bucket = hdr2._hdr[mag];
130 if (that_bucket == NULL) {
131 if (clear_this) {
132 // the target doesn't have any values, swap in ours.
133 // Could this cause native memory fragmentation?
134 hdr2._hdr[mag] = _hdr[mag];
135 _hdr[mag] = NULL;
136 } else {
137 // We can't clear this, so we create the entries & add in below
138 that_bucket = NEW_C_HEAP_ARRAY(int, ValBuckets, mtInternal);
139 for (int val = 0; val < ValBuckets; val++) {
140 that_bucket[val] = _hdr[mag][val];
141 }
142 hdr2._hdr[mag] = that_bucket;
143 }
144 } else {
145 // Add in our values into target
146 for (int val = 0; val < ValBuckets; val++) {
147 that_bucket[val] += _hdr[mag][val];
148 if (clear_this) {
149 _hdr[mag][val] = 0;
150 }
151 }
152 }
153 }
154 }
155 // Merge up the class hierarchy
156 NumberSeq::merge(hdr2, clear_this);
157 }
158
159 BinaryMagnitudeSeq::BinaryMagnitudeSeq() {
160 _mags = NEW_C_HEAP_ARRAY(size_t, BitsPerSize_t, mtInternal);
161 clear();
162 }
163
164 BinaryMagnitudeSeq::~BinaryMagnitudeSeq() {
165 FREE_C_HEAP_ARRAY(size_t, _mags);
166 }
167
168 void BinaryMagnitudeSeq::clear() {
169 for (int c = 0; c < BitsPerSize_t; c++) {
170 _mags[c] = 0;
171 }
172 _sum = 0;
173 }
174
175 void BinaryMagnitudeSeq::add(size_t val) {
176 Atomic::add(&_sum, val);
177
178 int mag = log2i_graceful(val) + 1;
|