1 /*
2 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
56 private boolean list;
57 private boolean options;
58 private boolean constants;
59 private boolean constantsOnly;
60 private boolean strings;
61 private boolean timestamp;
62 private boolean snap;
63 private boolean verbose;
64 private String specialOption;
65 private String names;
66
67 private OptionFormat optionFormat;
68
69 private int count = -1;
70 private int interval = -1;
71 private String vmIdString;
72
73 private VmIdentifier vmId;
74
75 public static void printUsage(PrintStream ps) {
76 ps.println("Usage: jstat -help|-options");
77 ps.println(" jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]");
78 ps.println();
79 ps.println("Definitions:");
80 ps.println(" <option> An option reported by the -options option");
81 ps.println(" <vmid> Virtual Machine Identifier. A vmid takes the following form:");
82 ps.println(" <lvmid>[@<hostname>[:<port>]]");
83 ps.println(" Where <lvmid> is the local vm identifier for the target");
84 ps.println(" Java virtual machine, typically a process id; <hostname> is");
85 ps.println(" the name of the host running the target Java virtual machine;");
86 ps.println(" and <port> is the port number for the rmiregistry on the");
87 ps.println(" target host. See the jvmstat documentation for a more complete");
88 ps.println(" description of the Virtual Machine Identifier.");
89 ps.println(" <lines> Number of samples between header lines.");
90 ps.println(" <interval> Sampling interval. The following forms are allowed:");
91 ps.println(" <n>[\"ms\"|\"s\"]");
92 ps.println(" Where <n> is an integer and the suffix specifies the units as ");
93 ps.println(" milliseconds(\"ms\") or seconds(\"s\"). The default units are \"ms\".");
94 ps.println(" <count> Number of samples to take before terminating.");
95 ps.println(" -J<flag> Pass <flag> directly to the runtime system.");
96
97 // undocumented options:
98 // -list [<vmid>] - list counter names
99 // -snap <vmid> - snapshot counter values as name=value pairs
100 // -name <pattern> - output counters matching given pattern
101 // -a - sort in ascending order (default)
102 // -d - sort in descending order
103 // -v - verbose output (-snap)
104 // -constants - output constants with -name output
105 // -strings - output strings with -name output
106 }
107
108 private static int toMillis(String s) throws IllegalArgumentException {
109
110 String[] unitStrings = { "ms", "s" }; // ordered from most specific to
111 // least specific
112 String unitString = null;
113 String valueString = s;
114
115 for (int i = 0; i < unitStrings.length; i++) {
116 int index = s.indexOf(unitStrings[i]);
117 if (index > 0) {
118 unitString = s.substring(index);
119 valueString = s.substring(0, index);
120 break;
121 }
122 }
123
124 try {
125 int value = Integer.parseInt(valueString);
130 return value * 1000;
131 } else {
132 throw new IllegalArgumentException(
133 "Unknow time unit: " + unitString);
134 }
135 } catch (NumberFormatException e) {
136 throw new IllegalArgumentException(
137 "Could not convert interval: " + s);
138 }
139 }
140
141 public Arguments(String[] args) throws IllegalArgumentException {
142 int argc = 0;
143
144 if (args.length == 0) {
145 help = true;
146 return;
147 }
148
149 if ((args[0].compareTo("-?") == 0)
150 || (args[0].compareTo("-help") == 0)) {
151 help = true;
152 return;
153 } else if (args[0].compareTo("-options") == 0) {
154 options = true;
155 return;
156 } else if (args[0].compareTo("-list") == 0) {
157 list = true;
158 if (args.length > 2) {
159 throw new IllegalArgumentException("invalid argument count");
160 }
161 // list can take one arg - a vmid - fall through for arg processing
162 argc++;
163 }
164
165 for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
166 String arg = args[argc];
167
168 if (arg.compareTo("-a") == 0) {
169 comparator = new AscendingMonitorComparator();
|
1 /*
2 * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
56 private boolean list;
57 private boolean options;
58 private boolean constants;
59 private boolean constantsOnly;
60 private boolean strings;
61 private boolean timestamp;
62 private boolean snap;
63 private boolean verbose;
64 private String specialOption;
65 private String names;
66
67 private OptionFormat optionFormat;
68
69 private int count = -1;
70 private int interval = -1;
71 private String vmIdString;
72
73 private VmIdentifier vmId;
74
75 public static void printUsage(PrintStream ps) {
76 ps.println("Usage: jstat --help|-options");
77 ps.println(" jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]");
78 ps.println();
79 ps.println("Definitions:");
80 ps.println(" <option> An option reported by the -options option");
81 ps.println(" <vmid> Virtual Machine Identifier. A vmid takes the following form:");
82 ps.println(" <lvmid>[@<hostname>[:<port>]]");
83 ps.println(" Where <lvmid> is the local vm identifier for the target");
84 ps.println(" Java virtual machine, typically a process id; <hostname> is");
85 ps.println(" the name of the host running the target Java virtual machine;");
86 ps.println(" and <port> is the port number for the rmiregistry on the");
87 ps.println(" target host. See the jvmstat documentation for a more complete");
88 ps.println(" description of the Virtual Machine Identifier.");
89 ps.println(" <lines> Number of samples between header lines.");
90 ps.println(" <interval> Sampling interval. The following forms are allowed:");
91 ps.println(" <n>[\"ms\"|\"s\"]");
92 ps.println(" Where <n> is an integer and the suffix specifies the units as ");
93 ps.println(" milliseconds(\"ms\") or seconds(\"s\"). The default units are \"ms\".");
94 ps.println(" <count> Number of samples to take before terminating.");
95 ps.println(" -J<flag> Pass <flag> directly to the runtime system.");
96 ps.println(" -? -h --help Prints this help message.");
97 ps.println(" -help Prints this help message.");
98
99 // undocumented options:
100 // -list [<vmid>] - list counter names
101 // -snap <vmid> - snapshot counter values as name=value pairs
102 // -name <pattern> - output counters matching given pattern
103 // -a - sort in ascending order (default)
104 // -d - sort in descending order
105 // -v - verbose output (-snap)
106 // -constants - output constants with -name output
107 // -strings - output strings with -name output
108 // -help - same as -? ...
109 }
110
111 private static int toMillis(String s) throws IllegalArgumentException {
112
113 String[] unitStrings = { "ms", "s" }; // ordered from most specific to
114 // least specific
115 String unitString = null;
116 String valueString = s;
117
118 for (int i = 0; i < unitStrings.length; i++) {
119 int index = s.indexOf(unitStrings[i]);
120 if (index > 0) {
121 unitString = s.substring(index);
122 valueString = s.substring(0, index);
123 break;
124 }
125 }
126
127 try {
128 int value = Integer.parseInt(valueString);
133 return value * 1000;
134 } else {
135 throw new IllegalArgumentException(
136 "Unknow time unit: " + unitString);
137 }
138 } catch (NumberFormatException e) {
139 throw new IllegalArgumentException(
140 "Could not convert interval: " + s);
141 }
142 }
143
144 public Arguments(String[] args) throws IllegalArgumentException {
145 int argc = 0;
146
147 if (args.length == 0) {
148 help = true;
149 return;
150 }
151
152 if ((args[0].compareTo("-?") == 0)
153 || (args[0].compareTo("-h") == 0)
154 || (args[0].compareTo("--help") == 0)
155 // -help: legacy.
156 || (args[0].compareTo("-help") == 0)) {
157 help = true;
158 return;
159 } else if (args[0].compareTo("-options") == 0) {
160 options = true;
161 return;
162 } else if (args[0].compareTo("-list") == 0) {
163 list = true;
164 if (args.length > 2) {
165 throw new IllegalArgumentException("invalid argument count");
166 }
167 // list can take one arg - a vmid - fall through for arg processing
168 argc++;
169 }
170
171 for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
172 String arg = args[argc];
173
174 if (arg.compareTo("-a") == 0) {
175 comparator = new AscendingMonitorComparator();
|