1 /*
2 * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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] != nullptr) {
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;
|
1 /*
2 * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
104 b[sub_bucket]++;
105 }
106
107 double HdrSeq::percentile(double level) const {
108 // target should be non-zero to find the first sample
109 int target = MAX2(1, (int) (level * num() / 100));
110 int cnt = 0;
111 for (int mag = 0; mag < MagBuckets; mag++) {
112 if (_hdr[mag] != nullptr) {
113 for (int val = 0; val < ValBuckets; val++) {
114 cnt += _hdr[mag][val];
115 if (cnt >= target) {
116 return pow(10.0, MagMinimum + mag) * val / ValBuckets;
117 }
118 }
119 }
120 }
121 return maximum();
122 }
123
124 void HdrSeq::add(const HdrSeq& other) {
125 if (other.num() == 0) {
126 // Other sequence is empty, return
127 return;
128 }
129
130 for (int mag = 0; mag < MagBuckets; mag++) {
131 int* other_bucket = other._hdr[mag];
132 if (other_bucket == nullptr) {
133 // Nothing to do
134 continue;
135 }
136 int* bucket = _hdr[mag];
137 if (bucket != nullptr) {
138 // Add into our bucket
139 for (int val = 0; val < ValBuckets; val++) {
140 bucket[val] += other_bucket[val];
141 }
142 } else {
143 // Create our bucket and copy the contents over
144 bucket = NEW_C_HEAP_ARRAY(int, ValBuckets, mtInternal);
145 for (int val = 0; val < ValBuckets; val++) {
146 bucket[val] = other_bucket[val];
147 }
148 _hdr[mag] = bucket;
149 }
150 }
151
152 // This is a hacky way to only update the fields we want.
153 // This inlines NumberSeq code without going into AbsSeq and
154 // dealing with decayed average/variance, which we do not
155 // know how to compute yet.
156 _last = other._last;
157 _maximum = MAX2(_maximum, other._maximum);
158 _sum += other._sum;
159 _sum_of_squares += other._sum_of_squares;
160 _num += other._num;
161
162 // Until JDK-8298902 is fixed, we taint the decaying statistics
163 _davg = NAN;
164 _dvariance = NAN;
165 }
166
167 void HdrSeq::clear() {
168 // Clear the storage
169 for (int mag = 0; mag < MagBuckets; mag++) {
170 int* bucket = _hdr[mag];
171 if (bucket != nullptr) {
172 for (int c = 0; c < ValBuckets; c++) {
173 bucket[c] = 0;
174 }
175 }
176 }
177
178 // Clear other fields too
179 _last = 0;
180 _maximum = 0;
181 _sum = 0;
182 _sum_of_squares = 0;
183 _num = 0;
184 _davg = 0;
185 _dvariance = 0;
186 }
187
188 BinaryMagnitudeSeq::BinaryMagnitudeSeq() {
189 _mags = NEW_C_HEAP_ARRAY(size_t, BitsPerSize_t, mtInternal);
190 clear();
191 }
192
193 BinaryMagnitudeSeq::~BinaryMagnitudeSeq() {
194 FREE_C_HEAP_ARRAY(size_t, _mags);
195 }
196
197 void BinaryMagnitudeSeq::clear() {
198 for (int c = 0; c < BitsPerSize_t; c++) {
199 _mags[c] = 0;
200 }
201 _sum = 0;
202 }
203
204 void BinaryMagnitudeSeq::add(size_t val) {
205 Atomic::add(&_sum, val);
206
207 int mag = log2i_graceful(val) + 1;
|