本文整理汇总了Java中java.lang.management.BufferPoolMXBean类的典型用法代码示例。如果您正苦于以下问题:Java BufferPoolMXBean类的具体用法?Java BufferPoolMXBean怎么用?Java BufferPoolMXBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BufferPoolMXBean类属于java.lang.management包,在下文中一共展示了BufferPoolMXBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sense
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public void sense(final MetricRecorder.Context metricContext)
{
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean mxBean : pools) {
//TODO: something else?
String name = mxBean.getName();
Metric countMetric = Metric.define("BufferPoolCount_"+name);
Metric usedMetric = Metric.define("BufferPoolUsed_"+name);
Metric maxMetric = Metric.define("BufferPoolMax_"+name);
metricContext.record(countMetric, mxBean.getCount(), Unit.NONE);
metricContext.record(usedMetric, mxBean.getMemoryUsed() / M, Unit.MEGABYTE);
metricContext.record(maxMetric, mxBean.getTotalCapacity() / M, Unit.MEGABYTE);
}
}
示例2: testByteBufferMXBeanMethods
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
public void testByteBufferMXBeanMethods() {
List<BufferPoolMXBean> byteBufferPools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (int counter = 0; counter < 10; counter++) {
for (BufferPoolMXBean bean: byteBufferPools) {
// Name should not be blank or null
assertNotNull ("MXBean name is null", bean.getName());
assertFalse ("MXBean name is blank", bean.getName().equalsIgnoreCase(""));
// Total capacity should not be negative
assertTrue (bean.getName() + "'s total capacity was not greater than zero", bean.getTotalCapacity() >= 0);
// Likewise memoryUsed
assertTrue (bean.getName() + "'s memory used was not greater than zero", bean.getMemoryUsed() >= 0);
assertTrue (bean.getName() + "'s object name is null or blank",
bean.getObjectName() != null && bean.getObjectName().toString() != "");
}
}
}
示例3: next
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public Object next() {
if (!beforeFirst) {
throw new IllegalStateException();
}
beforeFirst = false;
final MemoryInfo memoryInfo = new MemoryInfo();
final DrillbitEndpoint endpoint = context.getIdentity();
memoryInfo.hostname = endpoint.getAddress();
memoryInfo.user_port = endpoint.getUserPort();
final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryInfo.heap_current = heapMemoryUsage.getUsed();
memoryInfo.heap_max = heapMemoryUsage.getMax();
BufferPoolMXBean directBean = getDirectBean();
memoryInfo.jvm_direct_current = directBean.getMemoryUsed();
memoryInfo.direct_current = context.getDrillbitContext().getAllocator().getAllocatedMemory();
memoryInfo.direct_max = TopLevelAllocator.MAXIMUM_DIRECT_MEMORY;
return memoryInfo;
}
示例4: check
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
static void check(List<BufferPoolMXBean> pools,
int minBufferCount,
long minTotalCapacity)
{
int bufferCount = 0;
long totalCap = 0;
long totalMem = 0;
for (BufferPoolMXBean pool: pools) {
bufferCount += pool.getCount();
totalCap += pool.getTotalCapacity();
totalMem += pool.getMemoryUsed();
}
if (bufferCount < minBufferCount)
throw new RuntimeException("Count less than expected");
if (totalMem < minTotalCapacity)
throw new RuntimeException("Memory usage less than expected");
if (totalCap < minTotalCapacity)
throw new RuntimeException("Total capacity less than expected");
}
示例5: submitTasks
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
static void submitTasks(ExecutorService executor, int count) {
for (int i=0; i < count && !failed; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
List<PlatformManagedObject> mbeans = new ArrayList<>();
mbeans.add(ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class));
mbeans.addAll(ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class));
for (PlatformManagedObject pmo : mbeans) {
// Name should not be null
if (pmo.getObjectName() == null) {
failed = true;
throw new RuntimeException("TEST FAILED: getObjectName() returns null");
}
}
}
});
}
}
示例6: next
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public Object next() {
if (!beforeFirst) {
throw new IllegalStateException();
}
beforeFirst = false;
final MemoryInfo memoryInfo = new MemoryInfo();
final NodeEndpoint endpoint = dbContext.getEndpoint();
memoryInfo.hostname = endpoint.getAddress();
memoryInfo.fabric_port = endpoint.getFabricPort();
final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryInfo.heap_current = heapMemoryUsage.getUsed();
memoryInfo.heap_max = heapMemoryUsage.getMax();
BufferPoolMXBean directBean = getDirectBean();
memoryInfo.jvm_direct_current = directBean.getMemoryUsed();
memoryInfo.direct_current = dbContext.getAllocator().getAllocatedMemory();
memoryInfo.direct_max = SabotConfig.getMaxDirectMemory();
return memoryInfo;
}
示例7: main
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
public static void main(String[] args) {
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean pool:pools) {
System.out.println(String.format(
"%s %d/%d",
pool.getName(),
pool.getMemoryUsed(),
pool.getTotalCapacity()));
}
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
for (String arg:RuntimemxBean.getInputArguments()) {
System.out.println(arg);
}
HotSpotDiagnosticMXBean hsdiag = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
for (VMOption i:hsdiag.getDiagnosticOptions()) {
System.out.println(i.getName() + ":" + i.getValue());
}
System.out.println(hsdiag.getVMOption("MaxDirectMemorySize"));
System.out.println(sun.misc.VM.maxDirectMemory());
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(getDirectMemoryUsed());
}
示例8: next
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public Object next() {
if (!beforeFirst) {
throw new IllegalStateException();
}
beforeFirst = false;
final MemoryInfo memoryInfo = new MemoryInfo();
final DrillbitEndpoint endpoint = context.getIdentity();
memoryInfo.hostname = endpoint.getAddress();
memoryInfo.user_port = endpoint.getUserPort();
final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryInfo.heap_current = heapMemoryUsage.getUsed();
memoryInfo.heap_max = heapMemoryUsage.getMax();
BufferPoolMXBean directBean = getDirectBean();
memoryInfo.jvm_direct_current = directBean.getMemoryUsed();
memoryInfo.direct_current = context.getDrillbitContext().getAllocator().getAllocatedMemory();
memoryInfo.direct_max = DrillConfig.getMaxDirectMemory();
return memoryInfo;
}
示例9: run
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public void run() {
try {
long memoryUsed = 0;
for (BufferPoolMXBean bufferPool : bufferPools) {
if (bufferPool.getName().equals("direct")) {
memoryUsed = bufferPool.getMemoryUsed();
}
}
Counter counter = new Counter(ValueType.VALUE);
counter.set(memoryUsed);
check(counter, config.getDescription(), "Allocate more direct memory. ");
} catch (Exception x) {
// TODO what?
}
}
示例10: getMetrics
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
public Map<String, Metric> getMetrics() {
Map<String, Metric> metrics = super.getMetrics();
MemoryMXBean memMxBean = ManagementFactory.getMemoryMXBean();
registerGauge(metrics, MEMORY_OBJ_PENDING_FINALIZATION_COUNT_METRIC_NAME, memMxBean.getObjectPendingFinalizationCount());
MemoryUsage heapMemUsage = memMxBean.getHeapMemoryUsage(), nonHeapMemUsage = memMxBean.getNonHeapMemoryUsage();
registerMemoryUsageMetrics(metrics, MEMORY_HEAP_METRIC_NAME_PREFIX, heapMemUsage);
registerMemoryUsageMetrics(metrics, MEMORY_NON_HEAP_METRIC_NAME_PREFIX, nonHeapMemUsage);
registerMemoryUsageMetrics(metrics, MEMORY_TOTAL_METRIC_NAME_PREFIX, (heapMemUsage.getCommitted() + nonHeapMemUsage.getCommitted()),
(heapMemUsage.getInit() + nonHeapMemUsage.getInit()), -1, (heapMemUsage.getUsed() + nonHeapMemUsage.getUsed()),
(heapMemUsage.getMax() + nonHeapMemUsage.getMax()));
ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isValid)
.forEach(memPoolMxBean -> registerMemoryPoolMetrics(metrics, memPoolMxBean));
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class).stream().forEach(bufferPoolMxBean -> registerBufferPoolMetrics(metrics, bufferPoolMxBean));
return metrics;
}
示例11: updateBufferPoolMetrics
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
private void updateBufferPoolMetrics() {
for (BufferPoolMXBean bufferPoolMXBean : bufferPoolMXBeanList) {
String normalizedKeyName = bufferPoolMXBean.getName().replaceAll("[^\\w]", "-");
final ByteAmount memoryUsed = ByteAmount.fromBytes(bufferPoolMXBean.getMemoryUsed());
final ByteAmount totalCapacity = ByteAmount.fromBytes(bufferPoolMXBean.getTotalCapacity());
final ByteAmount count = ByteAmount.fromBytes(bufferPoolMXBean.getCount());
// The estimated memory the JVM is using for this buffer pool
jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-memory-used")
.setValue(memoryUsed.asMegabytes());
// The estimated total capacity of the buffers in this pool
jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-total-capacity")
.setValue(totalCapacity.asMegabytes());
// THe estimated number of buffers in this pool
jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-count")
.setValue(count.asMegabytes());
}
}
示例12: printTestName
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Before
public void printTestName() {
/* protect a travis stalled build */
BufferPoolMXBean direct = BufferPool.getDirectBufferPool();
BufferPoolMXBean mapped = BufferPool.getMappedBufferPool();
System.out.println(String.format("Used heap: %s/%s, direct:%s/%s, mapped:%s/%s, Active Threads: %d, Run: %s.%s",
FileUtil.humanReadableByteCount(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(), false),
FileUtil.humanReadableByteCount(Runtime.getRuntime().maxMemory(), false),
FileUtil.humanReadableByteCount(direct.getMemoryUsed(), false),
FileUtil.humanReadableByteCount(direct.getTotalCapacity(), false),
FileUtil.humanReadableByteCount(mapped.getMemoryUsed(), false),
FileUtil.humanReadableByteCount(mapped.getTotalCapacity(), false),
Thread.activeCount(),
getClass().getSimpleName(),
name.getMethodName()));
}
示例13: heartbeat
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
@Override
protected void heartbeat() {
// Let them know we are alive
// Print some stats about the ByteBuffers
List<BufferPoolMXBean> byteBufferPools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
String direct = "direct";
String mapped = "mapped";
for (BufferPoolMXBean bean: byteBufferPools) {
if (bean.getName().equalsIgnoreCase(direct)) {
direct += " - " + bean.getMemoryUsed() + "/" + bean.getTotalCapacity();
}
if (bean.getName().equalsIgnoreCase(mapped)) {
mapped += " - " + bean.getMemoryUsed() + "/" + bean.getTotalCapacity();
}
}
logMessage(direct + " , " + mapped);
logMessage("Currently connected clients: " + getConnectedClients().size());
logMessage("Total bytes received : " + bytesReceived);
logMessage("Total clients connected : " + clientsConnected);
logMessage("Total clients disconnected : " + clientsDisconnected);
synchronized (connectionsPerSecond) {
if (!connectionsPerSecond.isEmpty()) {
logMessage("CPS Max: " + Collections.max(connectionsPerSecond.values()) );
}
}
synchronized (connectionsPerMinute) {
if (!connectionsPerMinute.isEmpty()) {
logMessage("CPM Max: " + Collections.max(connectionsPerMinute.values()) );
}
}
logMessage();
}
示例14: getDirectBean
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
private BufferPoolMXBean getDirectBean() {
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean b : pools) {
if (b.getName().equals("direct")) {
return b;
}
}
throw new IllegalStateException("Unable to find direct buffer bean. JVM must be too old.");
}
示例15: SystemManager
import java.lang.management.BufferPoolMXBean; //导入依赖的package包/类
public SystemManager(){
memoryBean = ManagementFactory.getMemoryMXBean();
BufferPoolMXBean localBean = null;
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for(BufferPoolMXBean b : pools){
if(b.getName().equals("direct")){
localBean = b;
}
}
directBean = localBean;
}