1 /*
2 * Copyright 2017 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 * http://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.netty.buffer;
17
18 import io.netty.util.internal.StringUtil;
19
20 import java.util.List;
21
22 /**
23 * Exposed metric for {@link PooledByteBufAllocator}.
24 */
25 @SuppressWarnings("deprecation")
26 public final class PooledByteBufAllocatorMetric implements ByteBufAllocatorMetric {
27
28 private final PooledByteBufAllocator allocator;
29
30 PooledByteBufAllocatorMetric(PooledByteBufAllocator allocator) {
31 this.allocator = allocator;
32 }
33
34 /**
35 * Return the number of heap arenas.
36 */
37 public int numHeapArenas() {
38 return allocator.numHeapArenas();
39 }
40
41 /**
42 * Return the number of direct arenas.
43 */
44 public int numDirectArenas() {
45 return allocator.numDirectArenas();
46 }
47
48 /**
49 * Return a {@link List} of all heap {@link PoolArenaMetric}s that are provided by this pool.
50 */
51 public List<PoolArenaMetric> heapArenas() {
52 return allocator.heapArenas();
53 }
54
55 /**
56 * Return a {@link List} of all direct {@link PoolArenaMetric}s that are provided by this pool.
57 */
58 public List<PoolArenaMetric> directArenas() {
59 return allocator.directArenas();
60 }
61
62 /**
63 * Return the number of thread local caches used by this {@link PooledByteBufAllocator}.
64 */
65 public int numThreadLocalCaches() {
66 return allocator.numThreadLocalCaches();
67 }
68
69 /**
70 * Return the size of the tiny cache.
71 *
72 * @deprecated Tiny caches have been merged into small caches.
73 */
74 @Deprecated
75 public int tinyCacheSize() {
76 return allocator.tinyCacheSize();
77 }
78
79 /**
80 * Return the size of the small cache.
81 */
82 public int smallCacheSize() {
83 return allocator.smallCacheSize();
84 }
85
86 /**
87 * Return the size of the normal cache.
88 */
89 public int normalCacheSize() {
90 return allocator.normalCacheSize();
91 }
92
93 /**
94 * Return the chunk size for an arena.
95 */
96 public int chunkSize() {
97 return allocator.chunkSize();
98 }
99
100 @Override
101 public long usedHeapMemory() {
102 return allocator.usedHeapMemory();
103 }
104
105 @Override
106 public long usedDirectMemory() {
107 return allocator.usedDirectMemory();
108 }
109
110 @Override
111 public String toString() {
112 StringBuilder sb = new StringBuilder(256);
113 sb.append(StringUtil.simpleClassName(this))
114 .append("(usedHeapMemory: ").append(usedHeapMemory())
115 .append("; usedDirectMemory: ").append(usedDirectMemory())
116 .append("; numHeapArenas: ").append(numHeapArenas())
117 .append("; numDirectArenas: ").append(numDirectArenas())
118 .append("; smallCacheSize: ").append(smallCacheSize())
119 .append("; normalCacheSize: ").append(normalCacheSize())
120 .append("; numThreadLocalCaches: ").append(numThreadLocalCaches())
121 .append("; chunkSize: ").append(chunkSize()).append(')');
122 return sb.toString();
123 }
124 }
125