Skip to content

Commit

Permalink
fix: startupVO serialization exception
Browse files Browse the repository at this point in the history
  • Loading branch information
linyimin0812 committed Jun 4, 2024
1 parent a81e291 commit 3cdd2cb
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euxf -o pipefail

PRODUCT_NAME=spring-startup-analyzer
LAST_TAG=${1:-v3.1.2}
LAST_TAG=${1:-v3.1.3}
PROFILER_HOME=${HOME}/spring-startup-analyzer

check_permission() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<template.directory>${user.home}/spring-startup-analyzer/template</template.directory>
<sonar.organization>linyimin-bupt</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<revision>3.1.2</revision>
<revision>3.1.3</revision>
<sonar.coverage.jacoco.xmlReportPaths>
${project.basedir}/report-aggregate/target/site/
jacoco-aggregate/jacoco.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public static List<Statistics> getStatisticsList() {
}

public static String toJSONString() {
Map<String, String> map = new HashMap<>();


Map<String, String> map = new HashMap<>();

map.put("statisticsList", GSON.toJson(statisticsList, new TypeToken<List<Statistics>>(){}.getType()));
map.put("beanInitResultList", GSON.toJson(beanInitResultList));
Expand Down Expand Up @@ -81,7 +80,10 @@ private static List<MethodInvokeMetrics> calculateInvokeMetrics() {

}
} catch (Exception ex) {
List<MethodInvokeDetail> copies = methodInvokeDetailList.stream().map(invokeDetail -> new MethodInvokeDetail(invokeDetail.getMethodQualifier(), invokeDetail.getStartMillis(), invokeDetail.getDuration())).collect(Collectors.toList());
List<MethodInvokeDetail> copies = methodInvokeDetailList.stream()
.filter(Objects::nonNull)
.map(invokeDetail -> new MethodInvokeDetail(invokeDetail.getMethodQualifier(), invokeDetail.getStartMillis(), invokeDetail.getDuration()))
.collect(Collectors.toList());
logger.error(StartupVO.class, "calculateInvokeMetrics error. methodInvokeDetailList: {}", GSON.toJson(copies), ex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ public static boolean isStarted() {
}

public static boolean isStopped() {
return started.get();
return stopped.get();
}

/**
* only for internal test
*/
public static void clean() {

stopped.set(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private void handleOnEnd(Class<?> clazz, Object target, String methodName, Strin

private void handleEvent(InvokeEvent event) {

if (IocContainer.isStopped()) {
return;
}

for (EventListener listener : IocContainer.getComponents(EventListener.class)) {

if (!listener.listen().contains(event.type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ public boolean filter(String className) {
@Override
public boolean filter(String methodName, String[] methodTypes) {

if (!"run".equals(methodName) || methodTypes == null || methodTypes.length != 2) {
if (!"run".equals(methodName) || methodTypes == null) {
return false;
}

return ("java.lang.Class[]".equals(methodTypes[0]) || "java.lang.Object[]".equals(methodTypes[0])) && "java.lang.String[]".equals(methodTypes[1]);
if (methodTypes.length == 1) {
return "java.lang.String[]".equals(methodTypes[1]);
}

if (methodTypes.length == 2) {
return ("java.lang.Class[]".equals(methodTypes[0]) || "java.lang.Object[]".equals(methodTypes[0])) && "java.lang.String[]".equals(methodTypes[1]);
}

return false;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import java.nio.file.Paths
@Stepwise
class IocContainerSpec extends Specification {

def setupSpec() {
IocContainer.clean()
}

def "test copyFile"() {

given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EventDispatcherSpec extends Specification {
EventDispatcher eventDispatcher = new EventDispatcher()

def setupSpec() {
IocContainer.clean()
IocContainer.start()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.github.linyimin0812.profiler.extension.enhance.invoke;

import io.github.linyimin0812.profiler.api.EventListener;
import io.github.linyimin0812.profiler.api.event.AtEnterEvent;
import io.github.linyimin0812.profiler.api.event.AtExitEvent;
import io.github.linyimin0812.profiler.api.event.Event;
import io.github.linyimin0812.profiler.api.event.InvokeEvent;
import io.github.linyimin0812.profiler.api.event.*;
import io.github.linyimin0812.profiler.common.logger.LogFactory;
import io.github.linyimin0812.profiler.common.logger.Logger;
import io.github.linyimin0812.profiler.common.settings.ProfilerSettings;
Expand Down Expand Up @@ -61,7 +58,7 @@ public void onEvent(Event event) {
if (event instanceof AtEnterEvent) {
MethodInvokeDetail invokeDetail = new MethodInvokeDetail(buildMethodQualifier((AtEnterEvent) event), invokeEvent.args);
INVOKE_DETAIL_MAP.put(key, invokeDetail);
} else if (event instanceof AtExitEvent) {
} else if (event instanceof AtExitEvent || event instanceof AtExceptionExitEvent) {
if (INVOKE_DETAIL_MAP.containsKey(key)) {
MethodInvokeDetail invokeDetail = INVOKE_DETAIL_MAP.get(key);
invokeDetail.setDuration(System.currentTimeMillis() - invokeDetail.getStartMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onEvent(Event event) {
String beanName = (String) atEnterEvent.args[0];
createBeanInitResult(beanName);

} else if (event.type == Event.Type.AT_EXIT) {
} else if (event.type == Event.Type.AT_EXIT || event.type == Event.Type.AT_EXCEPTION_EXIT) {
// bean初始化结束, 出栈

AtExitEvent atExitEvent = (AtExitEvent) event;
Expand Down

0 comments on commit 3cdd2cb

Please sign in to comment.