Skip to content

Commit e8d88b0

Browse files
authored
fix: use PROFILER_STOP_COMMAND in Shutdown hooks (#537)
1 parent dfb8911 commit e8d88b0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Diff for: experimental/aws-lambda-java-profiler/extension/src/main/java/com/amazonaws/services/lambda/extension/PreMain.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void premain(String agentArgs, Instrumentation inst) {
2828
if(!createFileIfNotExist("/tmp/aws-lambda-java-profiler")) {
2929
Logger.debug("starting the profiler for coldstart");
3030
startProfiler();
31-
registerShutdownHook(AsyncProfiler.getInstance());
31+
registerShutdownHook();
3232
try {
3333
Integer port = Integer.parseInt(INTERNAL_COMMUNICATION_PORT);
3434
Logger.debug("using profile communication port = " + port);
@@ -101,9 +101,9 @@ public static void startProfiler() {
101101
}
102102
}
103103

104-
public static void registerShutdownHook(AsyncProfiler profiler) {
104+
public static void registerShutdownHook() {
105105
Logger.debug("registering shutdown hook");
106-
Thread shutdownHook = new Thread(new ShutdownHook(profiler));
106+
Thread shutdownHook = new Thread(new ShutdownHook(PROFILER_STOP_COMMAND));
107107
Runtime.getRuntime().addShutdownHook(shutdownHook);
108108
}
109109

Diff for: experimental/aws-lambda-java-profiler/extension/src/main/java/com/amazonaws/services/lambda/extension/ShutdownHook.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
public class ShutdownHook implements Runnable {
88

9-
private AsyncProfiler profiler;
9+
private String stopCommand;
1010

11-
public ShutdownHook(AsyncProfiler profiler) {
12-
this.profiler = profiler;
11+
public ShutdownHook(String stopCommand) {
12+
this.stopCommand = stopCommand;
1313
}
1414

1515
@Override
@@ -18,7 +18,7 @@ public void run() {
1818
try {
1919
final String fileName = "/tmp/profiling-data-shutdown.html";
2020
Logger.debug("stopping the profiler");
21-
AsyncProfiler.getInstance().execute(String.format("stop,file=%s,include=*AWSLambda.main,include=start_thread", fileName));
21+
AsyncProfiler.getInstance().execute(String.format(this.stopCommand, fileName));
2222
} catch (Exception e) {
2323
Logger.error("could not stop the profiler");
2424
}

0 commit comments

Comments
 (0)