test/hotspot/jtreg/gc/testlibrary/PerfCounters.java
author ehelin
Mon, 27 Nov 2017 10:51:31 +0100
changeset 48117 d64722b0b371
permissions -rw-r--r--
8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3 Reviewed-by: sjohanss, tschatzl Contributed-by: ysr1729@gmail.com, erik.helin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48117
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     1
/*
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     4
 *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     8
 *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    13
 * accompanied this code).
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    14
 *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    18
 *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    21
 * questions.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    22
 */
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    23
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    24
package gc.testlibrary;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    25
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    26
import sun.jvmstat.monitor.Monitor;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    27
import sun.jvmstat.monitor.MonitorException;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    28
import sun.jvmstat.monitor.MonitoredHost;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    29
import sun.jvmstat.monitor.MonitoredVm;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    30
import sun.jvmstat.monitor.VmIdentifier;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    31
import jdk.test.lib.process.ProcessTools;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    32
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    33
/**
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    34
 * PerfCounters can be used to get a performance counter from the currently
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    35
 * executing VM.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    36
 *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    37
 * Throws a runtime exception if an error occurs while communicating with the
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    38
 * currently executing VM.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    39
 */
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    40
public class PerfCounters {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    41
    private final static MonitoredVm vm;
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    42
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    43
    static {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    44
        try {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    45
            String pid = Long.toString(ProcessTools.getProcessId());
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    46
            VmIdentifier vmId = new VmIdentifier(pid);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    47
            MonitoredHost host = MonitoredHost.getMonitoredHost(vmId);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    48
            vm = host.getMonitoredVm(vmId);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    49
        } catch (Exception e) {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    50
            throw new RuntimeException("Could not connect to the VM");
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    51
        }
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    52
    }
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    53
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    54
    /**
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    55
     * Returns the performance counter with the given name.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    56
     *
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    57
     * @param name The name of the performance counter.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    58
     * @throws IllegalArgumentException If no counter with the given name exists.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    59
     * @throws MonitorException If an error occurs while communicating with the VM.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    60
     * @return The performance counter with the given name.
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    61
     */
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    62
    public static PerfCounter findByName(String name)
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    63
        throws MonitorException, IllegalArgumentException {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    64
        Monitor m = vm.findByName(name);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    65
        if (m == null) {
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    66
            throw new IllegalArgumentException("Did not find a performance counter with name " + name);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    67
        }
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    68
        return new PerfCounter(m, name);
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    69
    }
d64722b0b371 8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
diff changeset
    70
}