Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeTunnel Tt 时间隧道 #4

Closed
WangJi92 opened this issue Mar 21, 2020 · 0 comments
Closed

TimeTunnel Tt 时间隧道 #4

WangJi92 opened this issue Mar 21, 2020 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@WangJi92
Copy link
Owner

tt 说明

tt 主要是用来记录请求的数据,方便二次触发,比如和测试找bug,触发了一次之后自己触发调试即可,不过这种场景用得还是比较少,现在获取tt 主要是为了获取spring context 然后进行一些操作。参考 arthas 这个获取spring context

打开 tt 命令

idea 打开右键获取tt命令
image

界面 说明

  • 一个是当前方法执行tt的命令
  • 一个是执行tt中使用常见的命令
    image
    停留一会回出现一些中文的提示信息
    image
com.github.wangji92.arthas.plugin.common.enums.TimeTunnelCommandEnum 主要是这个类

image

命令演示

接口信息

image

arthas 打开 执行命令(参考arthas 安装)

image

触发一下这个接口

image

tt time list 按Q 退出

image

执行一次重新触发一次

重常用命令列表选择复制命令粘贴到arthas的界面
image

tt -p -i 1000

周期性的触发

重新出发5次,每次时间间隔 2秒

tt -p --replay-times 5 --replay-interval 2000 -i 1000

image
image

特殊用法 获取spring contxt

image
前提是要触发一次 spring mvc的相关的接口
arthas 官方问题链接

tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod

其他的使用和上面的一致的,这里有了这个index 就可以获取spring context 了
image

这里的index 要修改为1001

tt -w 'target.getApplicationContext()' -i 1001

image
效果如下
image
也可以获取某个bean 处理方法

tt -w 'target.getApplicationContext().getBean("controllerTest").test()' -i 1001

image
image

other 示范

tt -w 'target.getApplicationContext().getBean(@org.springframework.web.servlet.view.BeanNameViewResolver@class).getOrder()' -i 1001

image

还有其他的获取spring context的方法?

1、上面的tt 获取

这种需要触发一次不是很方便

2、静态的stata 的 spring context

image
image
image

ognl -x 3 '#springContext=@com.wj.study.demo.generator.ApplicationContextProvider@context,#springContext.getBean("controllerTest").test()' -c 18b4aac2

arthas 插件命令直接支持
配置一下静态的位置即可。
image

3、watch 获取

这种需要触发一次不是很方便

watch org.springframework.web.servlet.DispatcherServlet doDispatch '@org.springframework.web.context.support.WebApplicationContextUtils@getWebApplicationContext(params[0].getServletContext()).getBean("controllerTest").test()' -n 5 -x 3

image

@WangJi92 WangJi92 added document documentation Improvements or additions to documentation and removed document labels Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant