Skip to content

Commit

Permalink
Add new argument, capture_stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
beothorn committed Mar 31, 2024
1 parent bdee484 commit f3c8242
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Capture all function calls including argument and return values.
No servers or open connections, just plug the agent and get the results.
See function calls, parameters and return values all at once.
[Latest release v18.0.0](https://github.com/beothorn/javaflame/releases/download/v18.0.0/javaAgent.jar)
[Latest release v19.0.0](https://github.com/beothorn/javaflame/releases/download/v19.0.0/javaAgent.jar)

Want to see it in action? [Check out this rendering of some sort algorithms flamegraphs](https://beothorn.github.io/javaflame).

Expand Down Expand Up @@ -74,6 +74,7 @@ Anything without exclusions will generate lots of data. Either it will not rende
| core_classes | Will include Java core classes. More useful in conjunction with filters to check, for example, network calls. | `java -javaagent:javaAgent.jar=core_classes -jar yourApp.jar` |
| no_snapshots | Dump the stack only when JVM goes down. Beware, this will use a lot of memory! You probably don't want that. | `java -javaagent:javaAgent.jar=no_snapshots -jar yourApp.jar` |
| qualified_functions | Print the qualified function name, ownerClass.functionName | `java -javaagent:javaAgent.jar=qualified_functions -jar yourApp.jar` |
| capture_stacktrace | Capture stacktraces for calls. Very expensive, use it when analizyng a single method.| `java -javaagent:javaAgent.jar=capture_stacktrace -jar yourApp.jar` |
| filter:expression | Will instrument only classes for which the qualified name matches the expression, see more below. You probably want to set this to you app package to avoid huge snapshots. | `java "-javaagent:javaAgent.jar=filter:com.github.myApp||store" -jar yourApp.jar` |
| startRecordingTriggerFunction:method | Will start recording the stack only when the function with this name is called. This checks only the method name. | `java -javaagent:javaAgent.jar=startRecordingTriggerFunction:afterSetup -jar yourApp.jar` |
| stopRecordingTriggerFunction:method | Will stop recording the stack when the function with this name is called. This checks only the method name. | `java -javaagent:javaAgent.jar=stopRecordingTriggerFunction:afterJobIsDone -jar yourApp.jar` |
Expand Down
3 changes: 2 additions & 1 deletion buildAndRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ java -javaagent:./javaAgent/build/libs/javaAgent.jar=log:DEBUG,out:/tmp,filter:c
#java "-javaagent:./javaAgent/build/libs/javaAgent.jar=log:INFO,out:/tmp,filter:nameStartsWith(Test)" -jar ./javaExampleApp/build/libs/javaExampleApp.jar
#java "-javaagent:./javaAgent/build/libs/javaAgent.jar=log:INFO,out:/tmp,filter:nameEndsWith(A)" -jar ./javaExampleApp/build/libs/javaExampleApp.jar
#java "-javaagent:./javaAgent/build/libs/javaAgent.jar=log:INFO,out:/tmp,filter:nameMatche(A)" -jar ./javaExampleApp/build/libs/javaExampleApp.jar
#java "-javaagent:./javaAgent/build/libs/javaAgent.jar=log:INFO,out:/tmp,filter:nameMatches(.*TestFilters[AB].*)" -jar ./javaExampleApp/build/libs/javaExampleApp.jar
#java "-javaagent:./javaAgent/build/libs/javaAgent.jar=log:INFO,out:/tmp,filter:nameMatches(.*TestFilters[AB].*)" -jar ./javaExampleApp/build/libs/javaExampleApp.jar
#java -javaagent:./javaAgent/build/libs/javaAgent.jar=log:DEBUG,out:/tmp,filter:com.github.beothorn.sorts,capture_stacktrace -jar ./javaExampleApp/build/libs/javaExampleApp.jar
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public enum Flag{
NO_CAPTURING_VALUES("no_capturing_values"),
CORE_CLASSES("core_classes"),
NO_SNAPSHOTS("no_snapshots"),
QUALIFIED_FUNCTIONS("qualified_functions");
QUALIFIED_FUNCTIONS("qualified_functions"),
CAPTURE_STACKTRACE("capture_stacktrace"),;

public final String flagAsString;

Expand Down Expand Up @@ -117,6 +118,7 @@ public static void premain(
currentLevel = argumentLogLevel(argument);
log(INFO, "Agent loaded");
boolean shouldCaptureValues = !argumentHasNoCaptureValuesMode(argument);
FunctionCallRecorder.setShouldCaptureStacktrace(argumentHasShouldCaptureStackTraces(argument));
Optional<String> maybeFilePath = outputFileOnArgument(argument);

Optional<File> file = maybeFilePath
Expand Down Expand Up @@ -349,6 +351,10 @@ public static boolean argumentHasNoCaptureValuesMode(String argument){
return NO_CAPTURING_VALUES.isOnArguments(argument);
}

public static boolean argumentHasShouldCaptureStackTraces(String argument){
return CAPTURE_STACKTRACE.isOnArguments(argument);
}

public static boolean argumentHasIncludeCoreClasses(String argument){
return CORE_CLASSES.isOnArguments(argument);
}
Expand Down

0 comments on commit f3c8242

Please sign in to comment.