trace spring
package xx.com.aspect; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.Vector; @Aspect
@Configuration
public class performace { @Autowired
HttpServletRequest request; static final ThreadLocal<TraceInfo> localRequest=new ThreadLocal<>();
static final ThreadLocal<Boolean> localIsChild=new ThreadLocal<>(); public static TraceInfo getLocalRequest() {
return localRequest.get();
}
public static void setParentRequest(TraceInfo traceInfo) {
localRequest.set(traceInfo);
localIsChild.set(true);
} // @Around("execution(* xx.com..*(..))")
// @Around("!within(is(FinalType)) && execution(* *..*(..))")
public Object aspectAround(ProceedingJoinPoint point) throws Throwable { String methodName = point.getSignature().getName();
String type=point.getSignature().getDeclaringType().getName()+":"+methodName;
TraceInfo traceInfo=new TraceInfo(type,new Date());
traceInfo.setChilds(new Vector<>());
if(localIsChild.get()!=null&&localIsChild.get()){
traceInfo.setChildThread(true);
}
boolean isMain=false;
if(localRequest.get()==null) {
isMain=true;
localRequest.set(traceInfo);
}
Object ret=point.proceed();
traceInfo.setEndDate(new Date()); if(isMain) {
try {
request.getAttribute("a");
} catch (Exception e) {
localRequest.remove();
System.out.println("*** 非请求执行:" + traceInfo.getType() + " : " + String.valueOf(traceInfo.getEndDate().getTime() - traceInfo.getStartDate().getTime()));
return ret;
}
} if(!isMain){
localRequest.get().getChilds().add(traceInfo);
} for (Annotation an : point.getTarget().getClass().getAnnotations()) {
if (an instanceof RestController) {
//end controller
trace(localRequest.get(), 0);
localRequest.remove();
break;
}
} // traces=new Vector<>();
// request.setAttribute("traces", traces);
return ret; } private void trace(TraceInfo traceInfo,int deep){ char[] space=new char[deep];
for(int i=0;i<deep;i++){
if(i==deep-1){
if(traceInfo.isChildThread()){
space[i] = '→';
}else {
space[i] = '┞';
}
break;
}
space[i]=' ';
}
System.out.println(
new String(space)+
traceInfo.getType()+
" : "+
String.valueOf(traceInfo.getEndDate().getTime()-traceInfo.getStartDate().getTime()));
if(traceInfo.getChilds()==null){
return;
}
for(TraceInfo child:traceInfo.getChilds()){
trace(child,deep+1);
} } public static class TraceInfo{ private Date startDate;
private Date endDate;
private String type;
private Vector<TraceInfo> childs;
private boolean childThread=false; public TraceInfo(String type,Date time){
this.startDate=time;
this.type=type;
} public Vector<TraceInfo> getChilds() {
return childs;
} public void setChilds(Vector<TraceInfo> childs) {
this.childs = childs;
} public Date getEndDate() {
return endDate;
} public void setEndDate(Date endDate) {
this.endDate = endDate;
} public Date getStartDate() {
return startDate;
} public void setStartDate(Date startDate) {
this.startDate = startDate;
} public String getType() {
return type;
} public void setType(String type) {
this.type = type;
} public boolean isChildThread() {
return childThread;
} public void setChildThread(boolean childThread) {
this.childThread = childThread;
}
} }
trace spring的更多相关文章
- spring boot 国际化MessageSource
转自:https://blog.csdn.net/flowingflying/article/details/76358970 spring中ResourceBundleMessageSource的配 ...
- 1.Spring Cloud初相识--------简单项目搭建
开发工具:STS 代码下载链接:GitHub管理项目 前言: Springcloud 算是当前比较火的技术,一套微服务架构的技术. 我个人对微服务的理解为: 服务可以代表service,微服务就是小的 ...
- Spring boot 官网学习笔记 - logging
commons-logging和slf4j是java中的日志门面,即它们提供了一套通用的接口,具体的实现可以由开发者自由选择.log4j和logback则是具体的日志实现方案. 比较常用的搭配是com ...
- 20191112 Spring Boot官方文档学习(4.4)
4.4.日志 Spring Boot使用Commons Logging进行所有内部日志记录,但是使底层日志实现打开状态.为Java Util Logging,Log4J2和Logback提供了默认配置 ...
- Spring cloud gateway自定义filter以及负载均衡
自定义全局filter package com.example.demo; import java.nio.charset.StandardCharsets; import org.apache.co ...
- Spring Boot从入门到精通(九)整合Spring Data JPA应用框架
JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...
- Spring Boot 日志各种使用姿势,是时候捋清楚了!
@ 目录 1. Java 日志概览 1.1 总体概览 1.2 日志级别 1.3 综合对比 1.4 最佳实践 2. Spring Boot 日志实现 2.1 Spring Boot 日志配置 2.2 L ...
- SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例
SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例 这是一个简单的SpringBoot整合实例 这里是项目的结构目录 首先是pom.xml ...
- SpringBoot官方文档学习(三)配置文件、日志、国际化和JSON
一.Profiles Spring配置文件提供了一种方法来隔离应用程序配置的各个部分,并使其仅在某些环境中可用.任何@Component.@Configuration或@ConfigurationPr ...
随机推荐
- The Dominator of Strings HDU - 6208(ac自动机板题)
题意: 就是求是否有一个串 是其它所有串的母串 解析: 把所有的串都加入到trie数中 然后用最长的串去匹配就好了 emm..开始理解错题意了...看成了只要存在一个串是另一个的母串就好.. 然后输 ...
- 【Cf #502 F】The Neutral Zone
本题把$log$化简之后求得就是每个质数$f$前的系数,求系数并不难,难点在于求出所有的质数. 由于空间限制相当苛刻,$3e8$的$bitset$的内存超限,我们考虑所有的除了$2$和$3$以外的质数 ...
- 用Gradle命令行编译Android工程
在Android sdk 目录下的samples/android-21/ 文件夹下,任找一个工程,如果在命令行直接编译 可能会报这种错误:gradle buile.gradle FAILURE: Bu ...
- Unhandled rejection RangeError: Maximum call stack size exceededill install loadIdealTree
npm安装时候报这个错误,解决方法如下: 删除项目中的 package-lock.json 文件 和 node_modules 文件夹,然后再尝试 npm install 详细参考
- 洛谷P4382 劈配
不知道这个Zayid是谁... 题意: 有n个人,m个导师.每个导师能接纳bi个人,每个人对于这m个导师都有一个志愿档次. 优先满足靠前的人,问到最后每个人匹配的导师是他的第几志愿. 每个人又有一个限 ...
- Centos6.7在VMware7.0上的hgfs文件共享
站在各大巨人的肩膀上.总结如下: 1,设置虚拟机共享 虚拟机->setting->options->Shared Folders->Always Enable mount -t ...
- codeforces.com/contest/251/problem/C
C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别
1. clock_gettime( ) 提供了纳秒的精确度 int clock_gettime(clockid_t clk_id, struct timespect *tp); clockid_t c ...
- 搞ACM的你伤不起[转载] 原作者:RoBa
劳资六年前开始搞ACM啊!!!!!!!!!! 从此踏上了尼玛不归路啊!!!!!!!!!!!! 谁特么跟劳资讲算法是程序设计的核心啊!!!!!! 尼玛除了面试题就没见过用算法的地方啊!!!!!! 谁再跟 ...
- noi题库(noi.openjudge.cn) 3.9数据结构之C++STL T1——T2
T1 1806:词典 描述 你旅游到了一个国外的城市.那里的人们说的外国语言你不能理解.不过幸运的是,你有一本词典可以帮助你. 输入首先输入一个词典,词典中包含不超过100000个词条,每个词条占据一 ...