Java Code Examples for sun.management.counter.Counter#getValue()

The following examples show how to use sun.management.counter.Counter#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectorAddressLink.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 2
Source File: ConnectorAddressLink.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 3
Source File: ConnectorAddressLink.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 4
Source File: ConnectorAddressLink.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 5
Source File: ConnectorAddressLink.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 6
Source File: ConnectorAddressLink.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 7
Source File: ConnectorAddressLink.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 8
Source File: ConnectorAddressLink.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 9
Source File: ConnectorAddressLink.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 10
Source File: ConnectorAddressLink.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 11
Source File: PerfCounters.java    From java-svc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private MBeanInfo createMBeanInfo() {
	Collection<Counter> counters = counterMap.values();
	List<MBeanAttributeInfo> attributes = new ArrayList<>(counters.size());
	for (Counter c : counters) {
		if (!c.isVector()) {
			String typeName = "java.lang.String";
			synchronized (c) {
				Object value = c.getValue();
				if (value != null) {
					typeName = value.getClass().getName();
				}
			}
			attributes.add(new MBeanAttributeInfo(c.getName(), typeName,
					String.format("%s [%s,%s]", c.getName(), c.getUnits(), c.getVariability()), true, false,
					false));
		}
	}
	MBeanAttributeInfo[] attributesArray = attributes.toArray(new MBeanAttributeInfo[attributes.size()]);
	return new MBeanInfo(this.getClass().getName(),
			"An MBean exposing the available JVM Performance Counters as attributes.", attributesArray, null, null,
			null);
}
 
Example 12
Source File: ConnectorAddressLink.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 13
Source File: ConnectorAddressLink.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 14
Source File: ConnectorAddressLink.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Imports the connector address from the instrument buffer
 * of the specified Java virtual machine.
 *
 * @param vmid an identifier that uniquely identifies a local Java virtual
 * machine, or <code>0</code> to indicate the current Java virtual machine.
 *
 * @return the value of the connector address, or <code>null</code> if the
 * target VM has not exported a connector address.
 *
 * @throws IOException An I/O error occurred while trying to acquire the
 * instrumentation buffer.
 */
public static String importFrom(int vmid) throws IOException {
    Perf perf = Perf.getPerf();
    ByteBuffer bb;
    try {
        bb = perf.attach(vmid, "r");
    } catch (IllegalArgumentException iae) {
        throw new IOException(iae.getMessage());
    }
    List<Counter> counters =
            new PerfInstrumentation(bb).findByPattern(CONNECTOR_ADDRESS_COUNTER);
    Iterator<Counter> i = counters.iterator();
    if (i.hasNext()) {
        Counter c = i.next();
        return (String) c.getValue();
    } else {
        return null;
    }
}
 
Example 15
Source File: HostTask.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
private Long getValue(Map<String, Counter> counters, String key) {
    Counter counter = counters.get(key);
    if (counter != null && counter.getValue() != null) {
        return Long.valueOf(counter.getValue().toString());
    }
    return 0L;
}
 
Example 16
Source File: PerfCounters.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
		throws AttributeNotFoundException, MBeanException, ReflectionException {
	if (attribute == null) {
		throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name cannot be null."),
				"Cannot invoke getAttribute on " + MBEAN_OBJECT_NAME + " with null as attribute name.");
	}
	Counter c = counterMap.get(attribute);
	if (c == null) {
		throw new AttributeNotFoundException("Could not find the attribute " + attribute);
	}
	return c.getValue();
}
 
Example 17
Source File: SynchronizationStatistics.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@Override
protected void innerCollect(StatisticsSink sink) {
    for (Counter counter : hsRuntime.getInternalRuntimeCounters()) {
        String counterName = counter.getName();
        if (counters.contains(counterName)) {
            counterName = counterName.substring("sun.rt._sync_".length()).toLowerCase();
            Object value = counter.getValue();
            sink.add(counterName, value.toString());
        }
    }
}
 
Example 18
Source File: HostTask.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
private static String getStringValue(Map<String, Counter> counters, String key) {
    Counter counter = counters.get(key);
    if (counter != null && counter.getValue() != null) {
        return counter.getValue().toString();
    }
    return "";
}