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();
|
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
98 // undocumented options:
99 // -list [<vmid>] - list counter names
100 // -snap <vmid> - snapshot counter values as name=value pairs
101 // -name <pattern> - output counters matching given pattern
102 // -a - sort in ascending order (default)
103 // -d - sort in descending order
104 // -v - verbose output (-snap)
105 // -constants - output constants with -name output
106 // -strings - output strings with -name output
107 // -help - same as -? ...
108 }
109
110 private static int toMillis(String s) throws IllegalArgumentException {
111
112 String[] unitStrings = { "ms", "s" }; // ordered from most specific to
113 // least specific
114 String unitString = null;
115 String valueString = s;
116
117 for (int i = 0; i < unitStrings.length; i++) {
118 int index = s.indexOf(unitStrings[i]);
119 if (index > 0) {
120 unitString = s.substring(index);
121 valueString = s.substring(0, index);
122 break;
123 }
124 }
125
126 try {
127 int value = Integer.parseInt(valueString);
132 return value * 1000;
133 } else {
134 throw new IllegalArgumentException(
135 "Unknow time unit: " + unitString);
136 }
137 } catch (NumberFormatException e) {
138 throw new IllegalArgumentException(
139 "Could not convert interval: " + s);
140 }
141 }
142
143 public Arguments(String[] args) throws IllegalArgumentException {
144 int argc = 0;
145
146 if (args.length == 0) {
147 help = true;
148 return;
149 }
150
151 if ((args[0].compareTo("-?") == 0)
152 || (args[0].compareTo("-h") == 0)
153 || (args[0].compareTo("--help") == 0)
154 // -help: legacy. Undocumented.
155 || (args[0].compareTo("-help") == 0)) {
156 help = true;
157 return;
158 } else if (args[0].compareTo("-options") == 0) {
159 options = true;
160 return;
161 } else if (args[0].compareTo("-list") == 0) {
162 list = true;
163 if (args.length > 2) {
164 throw new IllegalArgumentException("invalid argument count");
165 }
166 // list can take one arg - a vmid - fall through for arg processing
167 argc++;
168 }
169
170 for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
171 String arg = args[argc];
172
173 if (arg.compareTo("-a") == 0) {
174 comparator = new AscendingMonitorComparator();
|