1 /* 2 * Copyright 2021 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty5.buffer.api.pool; 17 18 /** 19 * Expose metrics for an SizeClasses. 20 */ 21 public interface SizeClassesMetric { 22 23 /** 24 * Computes size from lookup table according to sizeIdx. 25 * 26 * @return size 27 */ 28 int sizeIdx2size(int sizeIdx); 29 30 /** 31 * Computes size according to sizeIdx. 32 * 33 * @return size 34 */ 35 int sizeIdx2sizeCompute(int sizeIdx); 36 37 /** 38 * Computes size from lookup table according to pageIdx. 39 * 40 * @return size which is multiples of pageSize. 41 */ 42 long pageIdx2size(int pageIdx); 43 44 /** 45 * Computes size according to pageIdx. 46 * 47 * @return size which is multiples of pageSize 48 */ 49 long pageIdx2sizeCompute(int pageIdx); 50 51 /** 52 * Normalizes request size up to the nearest size class. 53 * 54 * @param size request size 55 * 56 * @return sizeIdx of the size class 57 */ 58 int size2SizeIdx(int size); 59 60 /** 61 * Normalizes request size up to the nearest pageSize class. 62 * 63 * @param pages multiples of pageSizes 64 * 65 * @return pageIdx of the pageSize class 66 */ 67 int pages2pageIdx(int pages); 68 69 /** 70 * Normalizes request size down to the nearest pageSize class. 71 * 72 * @param pages multiples of pageSizes 73 * 74 * @return pageIdx of the pageSize class 75 */ 76 int pages2pageIdxFloor(int pages); 77 78 /** 79 * Normalizes usable size that would result from allocating an object with the 80 * specified size and alignment. 81 * 82 * @param size request size 83 * 84 * @return normalized size 85 */ 86 int normalizeSize(int size); 87 }