Hearen / arthas

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
https://alibaba.github.io/arthas/
GNU General Public License v3.0
0 stars 0 forks source link

Refactor the WebConsole part using xterm? #21

Open Hearen opened 5 years ago

Hearen commented 5 years ago

Why?

Hearen commented 5 years ago

How?

Checked the mentioned (currently used ugly/stale termd which is packaged /Users/lhearen/.m2/repository/com/alibaba/middleware/termd-core/1.1.5/termd-core-1.1.5.jar), but it's indeed ugly.

two things at least first do

Hearen commented 5 years ago

how the Web Console works now to handle requests and respond?

  1. After you boot Arthas and attach it to the target Java process, **/arthas/agent/AgentBootstrap.java will be first started and using reflection in bind method to load **/arthas/core/server/ArthasBootstrap.java.
  2. still using reflection in agent bind method, we invoke server bind method to bind TelnetTermServer and HttpTermServer to specified IP and ports (telnetPort: 3658 httpPort: 8563).

F.Y.I

# start a demo listening at: 8000

$ javac Demo.java && java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 Demo

# configure Arthas to start a remote debug named: demo-remote (port: 8000)
# and start bin/as.sh

# select the demo

https://github.com/alibaba/arthas/issues/222#issuecomment-429014000 debugging Arthas to re-produce the mentioned.

Hearen commented 5 years ago

How Arthas agent attached to target VM?

  1. as.sh selecting the target java Pid and start Arthas core with this Pid;
  2. Arthas core **/arthas/core/Arthas.java list all available VMs and locate the target VM and load the Arthas agent.
  3. Arthas core will load the Arthas agent with all the parameters got in as.sh.

F.Y.I

JPDA_SUSPEND=y bin/as.sh debug

# configure remote debug named as: arthas-remote (port: 8888) to debug Arthas core. 

# start to debug now

https://github.com/alibaba/arthas/issues/222#issue-369185026

Hearen commented 5 years ago
  1. Once ArthasBootstrap in core booted and
  2. BuiltinCommandPack added to resolvers for later command location;
  3. added the TelnetTermServer and HttpTermServer, the ShellServerImpl will
  4. start to listen and
  5. in TelnetTermServer, it will bind a termHandler at specified IP and port with TermImpl
  6. TermImpl will load the key map and command history from local config files waiting to readlines from console;
  7. ShellServerImpl.handleTerm will bind TermServerTermHandler for each *TermServer (creating a new session with ShellImpl by passing in the term);
  8. ShellImpl start to read line in handleTerm, invoking term.readLine with ShellLineHandler;
  9. TermImpl bind ShellLineHandler to handle the new line;
  10. ShellLineHandler.handle will handle the input by ShellImpl.createJob(tokens);
  11. it will invoke GlobalJobControllerImpl.createJob(InternalCommandManager commandManager, List<CliToken> tokens, ShellImpl shell) which will first invoke JobControllerImpl.createJob and set the global options;
  12. JobControllerImpl.createJob first create a process ProcessImpl (locating the Command, passing in all args, binding the AnnotatedCommandImpl which is used to parse the annotated);
  13. and then new a JobImpl to handle the request;
  14. ShellLineHandler.handle will then run the job if created successfully;
  15. JobImpl.run will be invoked;
  16. ProcessImpl.run will then be invoked (AnnotatedCommandImpl.cli getting the CLI, command options will be parsed by CLI.parse - default with DefaultCLI.DefaultParser);
  17. CommandProcessTask(CommandProcessImpl) will be created and started by ArthasBootstrap.getInstance().execute(task);
Hearen commented 5 years ago

https://www.baeldung.com/java-instrumentation