‘linchangsheng’ 1 month ago
parent
commit
d59eca3cdc

+ 0 - 27
mall-server-api/src/main/java/com/gree/mall/manager/config/aop/MemoryMonitorAspect.java

@@ -1,27 +0,0 @@
-package com.gree.mall.manager.config.aop;
-
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.stereotype.Component;
-
-@Aspect
-@Component
-public class MemoryMonitorAspect {
-
-    @Around("execution(* com.gree.mall.manager.controller..*(..))") // 替换为您的控制器包路径
-    public Object monitorMemoryUsage(ProceedingJoinPoint joinPoint) throws Throwable {
-        Runtime runtime = Runtime.getRuntime();
-        long beforeMemory = runtime.totalMemory() - runtime.freeMemory();
-
-        // 执行方法
-        Object result = joinPoint.proceed();
-
-        long afterMemory = runtime.totalMemory() - runtime.freeMemory();
-        long memoryUsed = afterMemory - beforeMemory;
-
-        System.out.println("方法: " + joinPoint.getSignature() + ", 使用内存: " + memoryUsed + " bytes");
-
-        return result;
-    }
-}

+ 0 - 30
mall-server-api/src/main/java/com/gree/mall/manager/config/aop/MemoryMonitoringFilter.java

@@ -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");
-        }
-    }
-}