Mercurial > hg > graal-jvmci-8
comparison src/share/vm/services/diagnosticCommand.cpp @ 4133:3b688d6ff3d0
7104647: Adding a diagnostic command framework
Reviewed-by: phh, dcubed
author | fparain |
---|---|
date | Wed, 14 Dec 2011 04:30:57 -0800 |
parents | |
children | 4f25538b54c9 |
comparison
equal
deleted
inserted
replaced
4131:e9b91fd07263 | 4133:3b688d6ff3d0 |
---|---|
1 /* | |
2 * Copyright (c) 2011, 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #include "precompiled.hpp" | |
26 #include "services/diagnosticArgument.hpp" | |
27 #include "services/diagnosticCommand.hpp" | |
28 #include "services/diagnosticFramework.hpp" | |
29 | |
30 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmd(output, heap), | |
31 _all("-all", "Show help for all commands", "BOOLEAN", false, "false"), | |
32 _cmd("command name", "The name of the command for which we want help", | |
33 "STRING", false) { | |
34 _dcmdparser.add_dcmd_option(&_all); | |
35 _dcmdparser.add_dcmd_argument(&_cmd); | |
36 }; | |
37 | |
38 void HelpDCmd::parse(CmdLine* line, char delim, TRAPS) { | |
39 _dcmdparser.parse(line, delim, CHECK); | |
40 } | |
41 | |
42 void HelpDCmd::print_help(outputStream* out) { | |
43 _dcmdparser.print_help(out, name()); | |
44 } | |
45 | |
46 void HelpDCmd::execute(TRAPS) { | |
47 if (_all.value()) { | |
48 GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(); | |
49 for (int i = 0; i < cmd_list->length(); i++) { | |
50 DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), | |
51 strlen(cmd_list->at(i))); | |
52 if (!factory->is_hidden()) { | |
53 output()->print_cr("%s%s", factory->name(), | |
54 factory->is_enabled() ? "" : " [disabled]"); | |
55 output()->print_cr("\t%s", factory->description()); | |
56 output()->cr(); | |
57 } | |
58 factory = factory->next(); | |
59 } | |
60 } else if (_cmd.has_value()) { | |
61 DCmd* cmd = NULL; | |
62 DCmdFactory* factory = DCmdFactory::factory(_cmd.value(), | |
63 strlen(_cmd.value())); | |
64 if (factory != NULL) { | |
65 output()->print_cr("%s%s", factory->name(), | |
66 factory->is_enabled() ? "" : " [disabled]"); | |
67 output()->print_cr(factory->description()); | |
68 output()->print_cr("\nImpact: %s", factory->impact()); | |
69 cmd = factory->create_resource_instance(output()); | |
70 if (cmd != NULL) { | |
71 DCmdMark mark(cmd); | |
72 cmd->print_help(output()); | |
73 } | |
74 } else { | |
75 output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value()); | |
76 } | |
77 } else { | |
78 output()->print_cr("The following commands are available:"); | |
79 GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(); | |
80 for (int i = 0; i < cmd_list->length(); i++) { | |
81 DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), | |
82 strlen(cmd_list->at(i))); | |
83 if (!factory->is_hidden()) { | |
84 output()->print_cr("%s%s", factory->name(), | |
85 factory->is_enabled() ? "" : " [disabled]"); | |
86 } | |
87 factory = factory->_next; | |
88 } | |
89 output()->print_cr("\nFor more information about a specific command use 'help <command>'."); | |
90 } | |
91 } | |
92 | |
93 void HelpDCmd::reset(TRAPS) { | |
94 _dcmdparser.reset(CHECK); | |
95 } | |
96 | |
97 void HelpDCmd::cleanup() { | |
98 _dcmdparser.cleanup(); | |
99 } | |
100 | |
101 int HelpDCmd::num_arguments() { | |
102 ResourceMark rm; | |
103 HelpDCmd* dcmd = new HelpDCmd(NULL, false); | |
104 if (dcmd != NULL) { | |
105 DCmdMark mark(dcmd); | |
106 return dcmd->_dcmdparser.num_arguments(); | |
107 } else { | |
108 return 0; | |
109 } | |
110 } | |
111 | |
112 GrowableArray<const char*>* HelpDCmd::argument_name_array() { | |
113 return _dcmdparser.argument_name_array(); | |
114 } | |
115 | |
116 GrowableArray<DCmdArgumentInfo*>* HelpDCmd::argument_info_array() { | |
117 return _dcmdparser.argument_info_array(); | |
118 } | |
119 | |
120 void VersionDCmd::execute(TRAPS) { | |
121 output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(), | |
122 Abstract_VM_Version::vm_release()); | |
123 JDK_Version jdk_version = JDK_Version::current(); | |
124 if (jdk_version.update_version() > 0) { | |
125 output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(), | |
126 jdk_version.minor_version(), jdk_version.update_version()); | |
127 } else { | |
128 output()->print_cr("JDK %d.%d", jdk_version.major_version(), | |
129 jdk_version.minor_version()); | |
130 } | |
131 } |