|
@@ -1,576 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
3
|
|
- *
|
4
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
|
- * of this software and associated documentation files (the "Software"), to deal
|
6
|
|
- * in the Software without restriction, including without limitation the rights
|
7
|
|
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
|
- * copies of the Software, and to permit persons to whom the Software is
|
9
|
|
- * furnished to do so, subject to the following conditions:
|
10
|
|
- *
|
11
|
|
- * The above copyright notice and this permission notice shall be included in
|
12
|
|
- * all copies or substantial portions of the Software.
|
13
|
|
- *
|
14
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
|
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
|
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
|
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
|
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
|
- * SOFTWARE.
|
21
|
|
- */
|
22
|
|
-
|
23
|
|
-package com.dmdirc.commandparser.commands.global;
|
24
|
|
-
|
25
|
|
-import com.dmdirc.FrameContainer;
|
26
|
|
-import com.dmdirc.Server;
|
27
|
|
-import com.dmdirc.WritableFrameContainer;
|
28
|
|
-import com.dmdirc.commandparser.CommandArguments;
|
29
|
|
-import com.dmdirc.commandparser.CommandInfo;
|
30
|
|
-import com.dmdirc.commandparser.CommandType;
|
31
|
|
-import com.dmdirc.commandparser.commands.Command;
|
32
|
|
-import com.dmdirc.commandparser.commands.IntelligentCommand;
|
33
|
|
-import com.dmdirc.commandparser.commands.context.CommandContext;
|
34
|
|
-import com.dmdirc.config.ConfigManager;
|
35
|
|
-import com.dmdirc.config.Identity;
|
36
|
|
-import com.dmdirc.config.IdentityManager;
|
37
|
|
-import com.dmdirc.logger.ErrorLevel;
|
38
|
|
-import com.dmdirc.logger.Logger;
|
39
|
|
-import com.dmdirc.plugins.PluginManager;
|
40
|
|
-import com.dmdirc.plugins.Service;
|
41
|
|
-import com.dmdirc.plugins.ServiceProvider;
|
42
|
|
-import com.dmdirc.ui.input.AdditionalTabTargets;
|
43
|
|
-import com.dmdirc.ui.input.TabCompleter;
|
44
|
|
-import com.dmdirc.ui.interfaces.Window;
|
45
|
|
-import com.dmdirc.ui.messages.Styliser;
|
46
|
|
-import com.dmdirc.updater.UpdateChecker;
|
47
|
|
-
|
48
|
|
-import java.io.Serializable;
|
49
|
|
-import java.util.Comparator;
|
50
|
|
-import java.util.Map;
|
51
|
|
-import java.util.SortedSet;
|
52
|
|
-import java.util.TreeSet;
|
53
|
|
-import java.util.Map.Entry;
|
54
|
|
-
|
55
|
|
-/**
|
56
|
|
- * Provides various handy ways to test or debug the client.
|
57
|
|
- *
|
58
|
|
- * @author Chris
|
59
|
|
- */
|
60
|
|
-public class Debug extends Command implements IntelligentCommand, CommandInfo {
|
61
|
|
-
|
62
|
|
- /**
|
63
|
|
- * Creates a new instance of Debug.
|
64
|
|
- */
|
65
|
|
- public Debug() {
|
66
|
|
- super();
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- /** {@inheritDoc} */
|
70
|
|
- @Override
|
71
|
|
- public void execute(final FrameContainer<?> origin,
|
72
|
|
- final CommandArguments args, final CommandContext context) {
|
73
|
|
- if (args.getArguments().length == 0) {
|
74
|
|
- showUsage(origin, args.isSilent(), "debug", "<debug command> [options]");
|
75
|
|
- } else if ("error".equals(args.getArguments()[0])) {
|
76
|
|
- doError(args.getArguments());
|
77
|
|
- } else if ("showraw".equals(args.getArguments()[0])) {
|
78
|
|
- doShowRaw(origin, args.isSilent());
|
79
|
|
- } else if ("configstats".equals(args.getArguments()[0])) {
|
80
|
|
- doConfigStats(origin, args.isSilent(), args.getArguments());
|
81
|
|
- } else if ("configinfo".equals(args.getArguments()[0])) {
|
82
|
|
- doConfigInfo(origin, args.isSilent());
|
83
|
|
- } else if ("globalconfiginfo".equals(args.getArguments()[0])) {
|
84
|
|
- doGlobalConfigInfo(origin, args.isSilent());
|
85
|
|
- } else if ("colourspam".equals(args.getArguments()[0])) {
|
86
|
|
- doColourSpam(origin, args.isSilent());
|
87
|
|
- } else if ("meminfo".equals(args.getArguments()[0])) {
|
88
|
|
- doMemInfo(origin, args.isSilent());
|
89
|
|
- } else if ("rungc".equals(args.getArguments()[0])) {
|
90
|
|
- doGarbage(origin, args.isSilent());
|
91
|
|
- } else if ("threads".equals(args.getArguments()[0])) {
|
92
|
|
- doThreads(origin, args.isSilent());
|
93
|
|
- } else if ("forceupdate".equals(args.getArguments()[0])) {
|
94
|
|
- doForceUpdate(origin, args.isSilent());
|
95
|
|
- } else if ("serverinfo".equals(args.getArguments()[0])) {
|
96
|
|
- doServerInfo(origin, args.isSilent());
|
97
|
|
- } else if ("serverstate".equals(args.getArguments()[0])) {
|
98
|
|
- doServerState(origin, args.isSilent());
|
99
|
|
- } else if ("benchmark".equals(args.getArguments()[0])) {
|
100
|
|
- doBenchmark(origin);
|
101
|
|
- } else if ("services".equals(args.getArguments()[0])) {
|
102
|
|
- doServices(origin, args.isSilent(), args.getArguments());
|
103
|
|
- } else if ("firstrun".equals(args.getArguments()[0])) {
|
104
|
|
- context.getSource().getController().showFirstRunWizard();
|
105
|
|
- } else if ("migration".equals(args.getArguments()[0])) {
|
106
|
|
- context.getSource().getController().showMigrationWizard();
|
107
|
|
- } else if ("notify".equals(args.getArguments()[0])) {
|
108
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Current notification colour is: "
|
109
|
|
- + origin.getNotification());
|
110
|
|
- } else if ("time".equals(args.getArguments()[0])) {
|
111
|
|
- doTime(origin, context.getSource(), args);
|
112
|
|
- } else {
|
113
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown debug action.");
|
114
|
|
- }
|
115
|
|
- }
|
116
|
|
-
|
117
|
|
- /**
|
118
|
|
- * Generates a fake error.
|
119
|
|
- *
|
120
|
|
- * @param args The arguments that were passed to the command
|
121
|
|
- */
|
122
|
|
- private static void doError(final String ... args) {
|
123
|
|
- ErrorLevel el = ErrorLevel.HIGH;
|
124
|
|
- if (args.length > 2) {
|
125
|
|
- final String level = args[2];
|
126
|
|
-
|
127
|
|
- if (level.equals("low")) {
|
128
|
|
- el = ErrorLevel.LOW;
|
129
|
|
- } else if (level.equals("medium")) {
|
130
|
|
- el = ErrorLevel.MEDIUM;
|
131
|
|
- } else if (level.equals("fatal")) {
|
132
|
|
- el = ErrorLevel.FATAL;
|
133
|
|
- } else if (level.equals("unknown")) {
|
134
|
|
- el = ErrorLevel.UNKNOWN;
|
135
|
|
- }
|
136
|
|
- }
|
137
|
|
-
|
138
|
|
- if (args.length > 1 && args[1].equals("user")) {
|
139
|
|
- Logger.userError(el, "Debug error message");
|
140
|
|
- } else {
|
141
|
|
- Logger.appError(el, "Debug error message", new Exception());
|
142
|
|
- }
|
143
|
|
- }
|
144
|
|
-
|
145
|
|
- /**
|
146
|
|
- * Attempts to show the server's raw window.
|
147
|
|
- *
|
148
|
|
- * @param origin The window this command was executed in
|
149
|
|
- * @param isSilent Whether this command has been silenced or not
|
150
|
|
- */
|
151
|
|
- private void doShowRaw(final FrameContainer<?> origin, final boolean isSilent) {
|
152
|
|
- if (origin == null || origin.getServer() == null) {
|
153
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, "Cannot show raw window here.");
|
154
|
|
- } else {
|
155
|
|
- origin.getServer().addRaw();
|
156
|
|
- }
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- /**
|
160
|
|
- * Shows stats related to the config system.
|
161
|
|
- *
|
162
|
|
- * @param origin The window this command was executed in
|
163
|
|
- * @param isSilent Whether this command has been silenced or not
|
164
|
|
- * @param args Arguments array for the command
|
165
|
|
- */
|
166
|
|
- private void doConfigStats(final FrameContainer<?> origin, final boolean isSilent,
|
167
|
|
- final String[] args) {
|
168
|
|
- int arg = -1;
|
169
|
|
- if (args.length == 2) {
|
170
|
|
- if (args[1].startsWith("+")) {
|
171
|
|
- try {
|
172
|
|
- arg = Integer.parseInt(args[1].substring(1));
|
173
|
|
- } catch (NumberFormatException e) {
|
174
|
|
- arg = Integer.MAX_VALUE;
|
175
|
|
- }
|
176
|
|
- doConfigStatsTop(origin, isSilent, arg);
|
177
|
|
- } else if (args[1].matches("^[0-9]+$")) {
|
178
|
|
- try {
|
179
|
|
- arg = Integer.parseInt(args[1]);
|
180
|
|
- } catch (NumberFormatException e) {
|
181
|
|
- arg = -1;
|
182
|
|
- }
|
183
|
|
- doConfigStatsCutOff(origin, isSilent, arg);
|
184
|
|
- } else {
|
185
|
|
- doConfigStatsOption(origin, isSilent, args[1]);
|
186
|
|
- }
|
187
|
|
- } else {
|
188
|
|
- doConfigStatsCutOff(origin, isSilent, arg);
|
189
|
|
- }
|
190
|
|
- }
|
191
|
|
-
|
192
|
|
- /**
|
193
|
|
- * Shows stats related to the config system, showing any options matching
|
194
|
|
- * the regex
|
195
|
|
- *
|
196
|
|
- * @param origin The window this command was executed in
|
197
|
|
- * @param isSilent Whether this command has been silenced or not
|
198
|
|
- * @param regex Regex to match options against
|
199
|
|
- */
|
200
|
|
- private void doConfigStatsOption(final FrameContainer<?> origin,
|
201
|
|
- final boolean isSilent, final String regex) {
|
202
|
|
- final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
|
203
|
|
- boolean found = false;
|
204
|
|
- for (Map.Entry<String, Integer> entry : sortedStats) {
|
205
|
|
- if (entry.getKey().matches(regex)) {
|
206
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, entry.getKey() + " - " +
|
207
|
|
- entry.getValue());
|
208
|
|
- found = true;
|
209
|
|
- }
|
210
|
|
- }
|
211
|
|
- if (!found) {
|
212
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, "Unable to locate option.");
|
213
|
|
- }
|
214
|
|
- }
|
215
|
|
-
|
216
|
|
- /**
|
217
|
|
- * Shows stats related to the config system, listing the top X number of
|
218
|
|
- * options.
|
219
|
|
- *
|
220
|
|
- * @param origin The window this command was executed in
|
221
|
|
- * @param isSilent Whether this command has been silenced or not
|
222
|
|
- * @param top Top number of entries to show
|
223
|
|
- */
|
224
|
|
- private void doConfigStatsTop(final FrameContainer<?> origin,
|
225
|
|
- final boolean isSilent, final int top) {
|
226
|
|
- final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
|
227
|
|
- int i = 0;
|
228
|
|
- for (Map.Entry<String, Integer> entry : sortedStats) {
|
229
|
|
- if (i == top) {
|
230
|
|
- break;
|
231
|
|
- }
|
232
|
|
- i++;
|
233
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, entry.getKey() + " - " +
|
234
|
|
- entry.getValue());
|
235
|
|
- }
|
236
|
|
- }
|
237
|
|
-
|
238
|
|
- /**
|
239
|
|
- * Shows stats related to the config system, lists all values with number
|
240
|
|
- * of usages over the specified value
|
241
|
|
- *
|
242
|
|
- * @param origin The window this command was executed in
|
243
|
|
- * @param isSilent Whether this command has been silenced or not
|
244
|
|
- * @param cutoff Cut off value for stats
|
245
|
|
- */
|
246
|
|
- private void doConfigStatsCutOff(final FrameContainer<?> origin,
|
247
|
|
- final boolean isSilent, final int cutoff) {
|
248
|
|
- final SortedSet<Entry<String, Integer>> sortedStats = getSortedStats();
|
249
|
|
- for (Map.Entry<String, Integer> entry : sortedStats) {
|
250
|
|
- if (entry.getValue() <= cutoff) {
|
251
|
|
- break;
|
252
|
|
- }
|
253
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, entry.getKey() + " - " +
|
254
|
|
- entry.getValue());
|
255
|
|
- }
|
256
|
|
- }
|
257
|
|
-
|
258
|
|
- /**
|
259
|
|
- * Gets a sorted Set of config options and the number of times they have
|
260
|
|
- * been called.
|
261
|
|
- *
|
262
|
|
- * @return Sorted set of config options and usages
|
263
|
|
- */
|
264
|
|
- private static SortedSet<Entry<String, Integer>> getSortedStats() {
|
265
|
|
- final SortedSet<Entry<String, Integer>> sortedStats =
|
266
|
|
- new TreeSet<Entry<String, Integer>>(new ValueComparator());
|
267
|
|
- sortedStats.addAll(ConfigManager.getStats().entrySet());
|
268
|
|
- return sortedStats;
|
269
|
|
- }
|
270
|
|
-
|
271
|
|
- /**
|
272
|
|
- * Shows memory usage information.
|
273
|
|
- *
|
274
|
|
- * @param origin The window this command was executed in
|
275
|
|
- * @param isSilent Whether this command has been silenced or not
|
276
|
|
- */
|
277
|
|
- private void doMemInfo(final FrameContainer<?> origin, final boolean isSilent) {
|
278
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Total Memory: "
|
279
|
|
- + Runtime.getRuntime().totalMemory());
|
280
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Free Memory: "
|
281
|
|
- + Runtime.getRuntime().freeMemory());
|
282
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Used Memory: "
|
283
|
|
- + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
|
284
|
|
- }
|
285
|
|
-
|
286
|
|
- /**
|
287
|
|
- * Outputs 100 lines containing various colours.
|
288
|
|
- *
|
289
|
|
- * @param origin The window this command was executed in
|
290
|
|
- * @param isSilent Whether this command has been silenced or not
|
291
|
|
- */
|
292
|
|
- private void doColourSpam(final FrameContainer<?> origin, final boolean isSilent) {
|
293
|
|
- for (int i = 0; i < 100; i++) {
|
294
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, ((char) 3) + "5Colour! "
|
295
|
|
- + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
|
296
|
|
- + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
|
297
|
|
- + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! "
|
298
|
|
- + ((char) 3) + "6Colour! " + ((char) 3) + "7Colour! ");
|
299
|
|
- }
|
300
|
|
- }
|
301
|
|
-
|
302
|
|
- /**
|
303
|
|
- * Manually runs the garbage collector.
|
304
|
|
- *
|
305
|
|
- * @param origin The window this command was executed in
|
306
|
|
- * @param isSilent Whether this command has been silenced or not
|
307
|
|
- */
|
308
|
|
- private void doGarbage(final FrameContainer<?> origin, final boolean isSilent) {
|
309
|
|
- System.gc();
|
310
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Invoked garbage collector.");
|
311
|
|
- }
|
312
|
|
-
|
313
|
|
- /**
|
314
|
|
- * Shows information about the config manager.
|
315
|
|
- *
|
316
|
|
- * @param origin The window this command was executed in
|
317
|
|
- * @param isSilent Whether this command has been silenced or not
|
318
|
|
- */
|
319
|
|
- private void doConfigInfo(final FrameContainer<?> origin, final boolean isSilent) {
|
320
|
|
- for (Identity source : origin.getConfigManager().getSources()) {
|
321
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, source.getTarget() + " - "
|
322
|
|
- + source + "(" + source.getTarget().getOrder() + ")");
|
323
|
|
- }
|
324
|
|
- }
|
325
|
|
-
|
326
|
|
- /**
|
327
|
|
- * Shows information about the global config manager.
|
328
|
|
- *
|
329
|
|
- * @param origin The window this command was executed in
|
330
|
|
- * @param isSilent Whether this command has been silenced or not
|
331
|
|
- */
|
332
|
|
- private void doGlobalConfigInfo(final FrameContainer<?> origin, final boolean isSilent) {
|
333
|
|
- for (Identity source : IdentityManager.getGlobalConfig().getSources()) {
|
334
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, source.getTarget() + " - "
|
335
|
|
- + source + "(" + source.getTarget().getOrder() + ")");
|
336
|
|
- }
|
337
|
|
- }
|
338
|
|
-
|
339
|
|
- /**
|
340
|
|
- * Forces the update checker to check for updates.
|
341
|
|
- *
|
342
|
|
- * @param origin The window this command was executed in
|
343
|
|
- * @param isSilent Whether this command has been silenced or not
|
344
|
|
- */
|
345
|
|
- private void doForceUpdate(final FrameContainer<?> origin, final boolean isSilent) {
|
346
|
|
- if (IdentityManager.getGlobalConfig().getOptionBool("updater", "enable")) {
|
347
|
|
- new Thread(new UpdateChecker(), "Forced update checker").start();
|
348
|
|
- } else {
|
349
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, "Update checking is currenty disabled."
|
350
|
|
- + " You can enable it by typing:");
|
351
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, Styliser.CODE_FIXED
|
352
|
|
- + " /set updater enable true");
|
353
|
|
- }
|
354
|
|
- }
|
355
|
|
-
|
356
|
|
- /**
|
357
|
|
- * Shows information about active threads.
|
358
|
|
- *
|
359
|
|
- * @param origin The window this command was executed in
|
360
|
|
- * @param isSilent Whether this command has been silenced or not
|
361
|
|
- */
|
362
|
|
- private void doThreads(final FrameContainer<?> origin, final boolean isSilent) {
|
363
|
|
- for (Entry<Thread, StackTraceElement[]> thread: Thread.getAllStackTraces().entrySet()) {
|
364
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_BOLD
|
365
|
|
- + thread.getKey().getName());
|
366
|
|
-
|
367
|
|
- for (StackTraceElement element : thread.getValue()) {
|
368
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
|
369
|
|
- + " " + element.toString());
|
370
|
|
- }
|
371
|
|
- }
|
372
|
|
- }
|
373
|
|
-
|
374
|
|
- /**
|
375
|
|
- * Shows information about the current server's state.
|
376
|
|
- *
|
377
|
|
- * @param origin The window this command was executed in
|
378
|
|
- * @param isSilent Whether this command has been silenced or not
|
379
|
|
- */
|
380
|
|
- private void doServerState(final FrameContainer<?> origin, final boolean isSilent) {
|
381
|
|
- if (origin.getServer() == null) {
|
382
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, "This window isn't connected to a server");
|
383
|
|
- } else {
|
384
|
|
- final Server server = origin.getServer();
|
385
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, server.getStatus().getTransitionHistory());
|
386
|
|
- }
|
387
|
|
- }
|
388
|
|
-
|
389
|
|
- /**
|
390
|
|
- * Shows information about the current server.
|
391
|
|
- *
|
392
|
|
- * @param origin The window this command was executed in
|
393
|
|
- * @param isSilent Whether this command has been silenced or not
|
394
|
|
- */
|
395
|
|
- private void doServerInfo(final FrameContainer<?> origin, final boolean isSilent) {
|
396
|
|
- if (origin.getServer() == null) {
|
397
|
|
- sendLine(origin, isSilent, FORMAT_ERROR, "This window isn't connected to a server");
|
398
|
|
- } else {
|
399
|
|
- final Server server = origin.getServer();
|
400
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Server name: " + server.getName());
|
401
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Actual name: "
|
402
|
|
- + server.getParser().getServerName());
|
403
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Network: " + server.getNetwork());
|
404
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "IRCd: "
|
405
|
|
- + server.getParser().getServerSoftware() + " - "
|
406
|
|
- + server.getParser().getServerSoftwareType());
|
407
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Modes: "
|
408
|
|
- + server.getParser().getBooleanChannelModes() + " "
|
409
|
|
- + server.getParser().getListChannelModes() + " "
|
410
|
|
- + server.getParser().getParameterChannelModes() + " "
|
411
|
|
- + server.getParser().getDoubleParameterChannelModes());
|
412
|
|
- }
|
413
|
|
- }
|
414
|
|
-
|
415
|
|
- /**
|
416
|
|
- * Benchmarks the textpane.
|
417
|
|
- *
|
418
|
|
- * @param origin The window this command was executed in
|
419
|
|
- */
|
420
|
|
- private static void doBenchmark(final FrameContainer<?> origin) {
|
421
|
|
- long[] results = new long[10];
|
422
|
|
-
|
423
|
|
- for (int i = 0; i < results.length; i++) {
|
424
|
|
- final long start = System.nanoTime();
|
425
|
|
-
|
426
|
|
- for (int j = 0; j < 5000; j++) {
|
427
|
|
- origin.addLine(FORMAT_OUTPUT, "This is a benchmark. Lorem ipsum doler...");
|
428
|
|
- }
|
429
|
|
-
|
430
|
|
- final long end = System.nanoTime();
|
431
|
|
-
|
432
|
|
- results[i] = end - start;
|
433
|
|
- }
|
434
|
|
-
|
435
|
|
- for (int i = 0; i < results.length; i++) {
|
436
|
|
- origin.addLine(FORMAT_OUTPUT, "Iteration " + i + ": " + results[i]
|
437
|
|
- + " nanoseconds.");
|
438
|
|
- }
|
439
|
|
- }
|
440
|
|
-
|
441
|
|
- /**
|
442
|
|
- * Shows information about all the current services available to plugins.
|
443
|
|
- *
|
444
|
|
- * @param origin The window this command was executed in
|
445
|
|
- * @param isSilent Whether this command has been silenced or not
|
446
|
|
- * @param args The arguments that were passed to the command
|
447
|
|
- */
|
448
|
|
- private void doServices(final FrameContainer<?> origin, final boolean isSilent,
|
449
|
|
- final String[] args) {
|
450
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, "Available Services:");
|
451
|
|
- for (Service service : PluginManager.getPluginManager().getAllServices()) {
|
452
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, " " + service.toString());
|
453
|
|
- if (args.length > 1 && args[1].equals("full")) {
|
454
|
|
- for (ServiceProvider provider : service.getProviders()) {
|
455
|
|
- sendLine(origin, isSilent, FORMAT_OUTPUT, " "
|
456
|
|
- + provider.getProviderName() + " [Active: "
|
457
|
|
- + provider.isActive() + "]");
|
458
|
|
- }
|
459
|
|
- }
|
460
|
|
- }
|
461
|
|
- }
|
462
|
|
-
|
463
|
|
- /**
|
464
|
|
- * Facilitates timing of a command.
|
465
|
|
- *
|
466
|
|
- * @param origin The origin of the command
|
467
|
|
- * @param window The window to be passed on to the timed command, if any
|
468
|
|
- * @param args The arguments that were passed to the command
|
469
|
|
- */
|
470
|
|
- private void doTime(final FrameContainer<?> origin, final Window window,
|
471
|
|
- final CommandArguments args) {
|
472
|
|
- if (origin instanceof WritableFrameContainer<?>) {
|
473
|
|
- final WritableFrameContainer<?> container = (WritableFrameContainer<?>) origin;
|
474
|
|
- final long start = System.currentTimeMillis();
|
475
|
|
- container.getCommandParser().parseCommand(origin, window, args.getArgumentsAsString(1));
|
476
|
|
- final long end = System.currentTimeMillis();
|
477
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Command executed in "
|
478
|
|
- + (end - start) + " milliseconds.");
|
479
|
|
- }
|
480
|
|
- }
|
481
|
|
-
|
482
|
|
- /** {@inheritDoc} */
|
483
|
|
- @Override
|
484
|
|
- public String getName() {
|
485
|
|
- return "debug";
|
486
|
|
- }
|
487
|
|
-
|
488
|
|
- /** {@inheritDoc} */
|
489
|
|
- @Override
|
490
|
|
- public boolean showInHelp() {
|
491
|
|
- return false;
|
492
|
|
- }
|
493
|
|
-
|
494
|
|
- /** {@inheritDoc} */
|
495
|
|
- @Override
|
496
|
|
- public CommandType getType() {
|
497
|
|
- return CommandType.TYPE_GLOBAL;
|
498
|
|
- }
|
499
|
|
-
|
500
|
|
- /** {@inheritDoc} */
|
501
|
|
- @Override
|
502
|
|
- public String getHelp() {
|
503
|
|
- return null;
|
504
|
|
- }
|
505
|
|
-
|
506
|
|
- /** {@inheritDoc} */
|
507
|
|
- @Override
|
508
|
|
- public AdditionalTabTargets getSuggestions(final int arg,
|
509
|
|
- final IntelligentCommandContext context) {
|
510
|
|
- final AdditionalTabTargets res = new AdditionalTabTargets();
|
511
|
|
-
|
512
|
|
- res.excludeAll();
|
513
|
|
-
|
514
|
|
- if (arg == 0) {
|
515
|
|
- res.add("error");
|
516
|
|
- res.add("showraw");
|
517
|
|
- res.add("colourspam");
|
518
|
|
- res.add("configstats");
|
519
|
|
- res.add("meminfo");
|
520
|
|
- res.add("rungc");
|
521
|
|
- res.add("configinfo");
|
522
|
|
- res.add("globalconfiginfo");
|
523
|
|
- res.add("forceupdate");
|
524
|
|
- res.add("serverinfo");
|
525
|
|
- res.add("serverstate");
|
526
|
|
- res.add("threads");
|
527
|
|
- res.add("benchmark");
|
528
|
|
- res.add("firstrun");
|
529
|
|
- res.add("migration");
|
530
|
|
- res.add("notify");
|
531
|
|
- res.add("services");
|
532
|
|
- res.add("time");
|
533
|
|
- } else if (arg == 1 && "error".equals(context.getPreviousArgs().get(0))) {
|
534
|
|
- res.add("user");
|
535
|
|
- res.add("app");
|
536
|
|
- } else if (arg == 1 && "services".equals(context.getPreviousArgs().get(0))) {
|
537
|
|
- res.add("full");
|
538
|
|
- } else if (arg == 2 && "error".equals(context.getPreviousArgs().get(0))) {
|
539
|
|
- res.add("low");
|
540
|
|
- res.add("medium");
|
541
|
|
- res.add("high");
|
542
|
|
- res.add("fatal");
|
543
|
|
- res.add("unknown");
|
544
|
|
- } else if (arg > 0 && "time".equals(context.getPreviousArgs().get(0))) {
|
545
|
|
- return TabCompleter.getIntelligentResults(arg, context, 1);
|
546
|
|
- }
|
547
|
|
-
|
548
|
|
- return res;
|
549
|
|
- }
|
550
|
|
-
|
551
|
|
- /** Reverse value comparator for a map entry. */
|
552
|
|
- private static class ValueComparator implements
|
553
|
|
- Comparator<Entry<String, Integer>>, Serializable {
|
554
|
|
-
|
555
|
|
- /**
|
556
|
|
- * A version number for this class. It should be changed whenever the
|
557
|
|
- * class structure is changed (or anything else that would prevent
|
558
|
|
- * serialized objects being unserialized with the new class).
|
559
|
|
- */
|
560
|
|
- private static final long serialVersionUID = 1;
|
561
|
|
-
|
562
|
|
- /** {@inheritDoc} */
|
563
|
|
- @Override
|
564
|
|
- public int compare(final Entry<String, Integer> o1,
|
565
|
|
- final Entry<String, Integer> o2) {
|
566
|
|
- int returnValue = o1.getValue().compareTo(o2.getValue()) * -1;
|
567
|
|
-
|
568
|
|
- if (returnValue == 0) {
|
569
|
|
- returnValue = o1.getKey().compareToIgnoreCase(o2.getKey());
|
570
|
|
- }
|
571
|
|
-
|
572
|
|
- return returnValue;
|
573
|
|
- }
|
574
|
|
- }
|
575
|
|
-
|
576
|
|
-}
|