annotate test/testlibrary/com/oracle/java/testlibrary/PerfCounters.java @ 16532:2dd966b157e8

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