This is the first day of my participation in Gwen Challenge

This article is based on Arthas 3.5.1 and introduces the use and implementation of the basic help,cat, and echo commands.

A. Help command

For command help, see the commands supported in current arthas versions or see instructions for specific commands.

The parameter name Parameters of the abbreviations Parameters that mandatory The sample
cmd Name of the command optional help cat

Files at com.taobao.arthas.core.com mand. Basic1000. HelpCommand. Java.

Check whether the command name is specified. All commands are returned if no arguments are passed, and the description and name of the specified command are returned if arguments are passed with an actual return.

Call the allCommands(Session Session) method, which gets allCommands. The BuiltinCommandPack and BuiltinCommandResolver classes implement the CommandResolver interface. The BuiltinCommandPack and BuiltinCommandResolver classes implement the Commands method. Both are done by actively adding commands to a list and then returning the list.

We can do automatic scanning here. If you want to make it automatic scanning command mode, you can through the way of scanning annotation for the specified path of the package, mainly for com.taobao.arthas.core.com mand scanning the packet. . The method of using off-the-shelf ArthasReflectUtils getClasses access to the specified class, relative to the original way, of course, this way performance losses, somewhat in the custom ordering more trouble. en.. The old one is fine. Forget it.

2. The cat command

Print the contents of the file, similar to the cat command in Linux.

The parameter name Parameters of the abbreviations Parameters that mandatory The sample
files Multiple file names can be separated by Spaces mandatory cat /tmp/a.txt
–encoding Specifies the encoding optional cat –encodeing=UTF-8 /tmp/a.txt
–sizeLimit -M The default value is 128kb, and the maximum value can be 8Mb. Currently, the maximum value is 128kb in non-terminal mode optional cat -M 1024 /tmp/a.txt

Files at com.taobao.arthas.core.com mand. Basic1000. CatCommand. Java

Iterate through and access the files in the files parameter, determine whether the file path exists, whether the file path is a folder, recycle to determine whether the file size exceeds the limit, and finally convert the content of the file into the specified encoding string output. The two loops here can be combined.

3. The echo command

Print parameters, similar to the Echo command in Linux.

The parameter name Parameters of the abbreviations Parameters that mandatory The sample
message What to output optional echo ‘hello’

Files at com.taobao.arthas.core.com mand. Basic1000. EchoCommand. Java

The message argument is returned directly, which is not quite the same as the Linux echo command.