|
@@ -1,30 +0,0 @@
|
|
|
-package com.gree.mall.manager.config.aop;
|
|
|
-
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.servlet.*;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.IOException;
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-public class MemoryMonitoringFilter implements Filter {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
- throws IOException, ServletException {
|
|
|
- Runtime runtime = Runtime.getRuntime();
|
|
|
- long beforeMemory = runtime.totalMemory() - runtime.freeMemory();
|
|
|
-
|
|
|
- // 继续处理请求
|
|
|
- chain.doFilter(request, response);
|
|
|
-
|
|
|
- long afterMemory = runtime.totalMemory() - runtime.freeMemory();
|
|
|
- long memoryUsed = afterMemory - beforeMemory;
|
|
|
-
|
|
|
- if (request instanceof HttpServletRequest) {
|
|
|
- String requestURI = ((HttpServletRequest) request).getRequestURI();
|
|
|
- System.out.println("请求接口: " + requestURI + ", 内存使用情况: 使用前" + beforeMemory+"使用后"+afterMemory+"差值"+memoryUsed + " bytes");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|