View Javadoc
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  import io.netty5.util.internal.StringUtil;
19  
20  import java.util.List;
21  
22  /**
23   * Exposed metric for {@link PooledBufferAllocator}.
24   */
25  final class PooledBufferAllocatorMetric implements BufferAllocatorMetric {
26  
27      private final PooledBufferAllocator allocator;
28  
29      PooledBufferAllocatorMetric(PooledBufferAllocator allocator) {
30          this.allocator = allocator;
31      }
32  
33      @Override
34      public int numArenas() {
35          return allocator.numArenas();
36      }
37  
38      @Override
39      public List<PoolArenaMetric> arenaMetrics() {
40          return allocator.arenaMetrics();
41      }
42  
43      @Override
44      public int numThreadLocalCaches() {
45          return allocator.numThreadLocalCaches();
46      }
47  
48      @Override
49      public int smallCacheSize() {
50          return allocator.smallCacheSize();
51      }
52  
53      @Override
54      public int normalCacheSize() {
55          return allocator.normalCacheSize();
56      }
57  
58      @Override
59      public int chunkSize() {
60          return allocator.chunkSize();
61      }
62  
63      @Override
64      public long usedMemory() {
65          return allocator.usedMemory();
66      }
67  
68      @Override
69      public long pinnedMemory() {
70          return allocator.pinnedMemory();
71      }
72  
73      @Override
74      public String toString() {
75          StringBuilder sb = new StringBuilder(256);
76          sb.append(StringUtil.simpleClassName(this))
77                  .append("(usedMemory: ").append(usedMemory())
78                  .append("; pinnedMemory: ").append(pinnedMemory())
79                  .append("; numArenas: ").append(numArenas())
80                  .append("; smallCacheSize: ").append(smallCacheSize())
81                  .append("; normalCacheSize: ").append(normalCacheSize())
82                  .append("; numThreadLocalCaches: ").append(numThreadLocalCaches())
83                  .append("; chunkSize: ").append(chunkSize()).append(')');
84          return sb.toString();
85      }
86  }